Skip to content

Commit

Permalink
feat: add typehint on adapter (#694)
Browse files Browse the repository at this point in the history
* feat: add typehint on adapter

* Type interface for adapters

* Type AsyncAwsS3

* Type AwsS3

* Type AzureBlobStorage

* Type DoctrineDbal

* fix constructor AsyncAwsS3

* Type Flysystem

* Type PhpseclibSftp

* Type Zip

* Type GridFS and fix declaration checksum

* fix muchafm review

* refacto: add types on adapter

* fix: review

* fix: review

* Refacto: Add type on Stream classes

* fix pedro review

* refactor: add typeint to FilesystemMap, StreamWrapper and StreamMode

* Refacto: Add type on Util classes

* fix muchafm review

* fix: pedro review

* fix pedro's review

* refacto: spec types

* fix: review

* refactor: fix Ftp and StreamWrapper errors

* refactor: fix lvl5 errors for AwsS3 and AzureBlobStorage adapters

* ci: upgrade phpstan to 1.10.39

* test: fix filesystem typehint in phpunit tests

* fix: fix phpspec tests

* refactor: apply cs fixing

* test: fix phpspec tests

* Update src/Gaufrette/Adapter/AwsS3.php

Co-authored-by: Grégoire Drapeau <[email protected]>

* Update src/Gaufrette/Adapter/PhpseclibSftp.php

Co-authored-by: Grégoire Drapeau <[email protected]>

* Update src/Gaufrette/Adapter/AzureBlobStorage.php

Co-authored-by: Kévin <[email protected]>

* Update src/Gaufrette/Adapter.php

* Update src/Gaufrette/Adapter/AzureBlobStorage.php

Co-authored-by: Kévin <[email protected]>

* Update src/Gaufrette/Adapter/Ftp.php

Co-authored-by: Kévin <[email protected]>

* Update src/Gaufrette/Adapter/AzureBlobStorage.php

Co-authored-by: Kévin <[email protected]>

* Update src/Gaufrette/Adapter/DoctrineDbal.php

* refactor: set type for mimetype aware adapters

* docs: add explanation for bitwire value in StreamWrapper

* fix: introduction of readonly promoted properties

* Update src/Gaufrette/Adapter/AwsS3.php

Co-authored-by: Grégoire Drapeau <[email protected]>

* Update src/Gaufrette/Stream/InMemoryBuffer.php

Co-authored-by: Kévin <[email protected]>

* Update src/Gaufrette/Stream/Local.php

Co-authored-by: Kévin <[email protected]>

* Update src/Gaufrette/Stream/Local.php

Co-authored-by: Kévin <[email protected]>

* Update src/Gaufrette/Adapter/AsyncAwsS3.php

* Update src/Gaufrette/Stream/InMemoryBuffer.php

Co-authored-by: Kévin <[email protected]>

---------

Co-authored-by: Sophie Roussel <[email protected]>
Co-authored-by: PedroTroller <[email protected]>
Co-authored-by: Grégoire Drapeau <[email protected]>
  • Loading branch information
4 people committed Feb 26, 2024
1 parent 40e904a commit 6227d85
Show file tree
Hide file tree
Showing 58 changed files with 619 additions and 1,419 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/static.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- name: Download dependencies
run: |
make require-all
composer require --dev --no-update phpstan/phpstan:1.8.8
composer require --dev --no-update phpstan/phpstan:1.10.39
composer update --no-interaction --prefer-dist
- name: PHPStan
Expand Down
3 changes: 0 additions & 3 deletions spec/Gaufrette/Adapter/AsyncAwsS3Spec.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@

class AsyncAwsS3Spec extends ObjectBehavior
{
/**
* @param \AsyncAws\SimpleS3\SimpleS3Client $service
*/
function let(SimpleS3Client $service)
{
$this->beConstructedWith($service, 'bucketName');
Expand Down
3 changes: 0 additions & 3 deletions spec/Gaufrette/Adapter/AwsS3Spec.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@

class AwsS3Spec extends ObjectBehavior
{
/**
* @param \Aws\S3\S3Client $service
*/
function let(S3Client $service)
{
$this->beConstructedWith($service, 'bucketName');
Expand Down
5 changes: 1 addition & 4 deletions spec/Gaufrette/Adapter/AzureBlobStorage/BlobProxyFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@

class BlobProxyFactory extends ObjectBehavior
{
/**
* @param string $connectionString
*/
function let($connectionString)
function let(string $connectionString)
{
$this->beConstructedWith($connectionString);
}
Expand Down
147 changes: 27 additions & 120 deletions spec/Gaufrette/Adapter/AzureBlobStorageSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@

namespace spec\Gaufrette\Adapter;

use Gaufrette\Adapter\AzureBlobStorage\BlobProxyFactoryInterface;
use PhpSpec\ObjectBehavior;

use WindowsAzure\Blob\Internal\IBlob;
use WindowsAzure\Blob\Models\Blob;
use WindowsAzure\Blob\Models\GetBlobResult;
use WindowsAzure\Blob\Models\ListBlobsResult;
use WindowsAzure\Common\ServiceException;

class AzureBlobStorageSpec extends ObjectBehavior
{
/**
* @param \Gaufrette\Adapter\AzureBlobStorage\BlobProxyFactoryInterface $blobProxyFactory
*/
function let($blobProxyFactory)
function let(BlobProxyFactoryInterface $blobProxyFactory)
{
$this->beConstructedWith($blobProxyFactory, 'containerName');
}
Expand All @@ -24,12 +24,7 @@ function it_should_be_initializable()
$this->shouldHaveType('Gaufrette\Adapter\MetadataSupporter');
}

/**
* @param \Gaufrette\Adapter\AzureBlobStorage\BlobProxyFactoryInterface $blobProxyFactory
* @param \WindowsAzure\Blob\Internal\IBlob $blobProxy
* @param \WindowsAzure\Blob\Models\GetBlobResult $getBlobResult
*/
function it_should_read_file($blobProxyFactory, $blobProxy, $getBlobResult)
function it_should_read_file(BlobProxyFactoryInterface $blobProxyFactory, IBlob $blobProxy, GetBlobResult $getBlobResult)
{
$getBlobResult
->getContentStream()
Expand All @@ -50,11 +45,7 @@ function it_should_read_file($blobProxyFactory, $blobProxy, $getBlobResult)
$this->read('filename')->shouldReturn('some content');
}

/**
* @param \Gaufrette\Adapter\AzureBlobStorage\BlobProxyFactoryInterface $blobProxyFactory
* @param \WindowsAzure\Blob\Internal\IBlob $blobProxy
*/
function it_should_return_false_when_cannot_read($blobProxyFactory, $blobProxy)
function it_should_return_false_when_cannot_read(BlobProxyFactoryInterface $blobProxyFactory, IBlob $blobProxy)
{
$blobProxy
->getBlob('containerName', 'filename')
Expand All @@ -69,11 +60,7 @@ function it_should_return_false_when_cannot_read($blobProxyFactory, $blobProxy)
$this->read('filename')->shouldReturn(false);
}

/**
* @param \Gaufrette\Adapter\AzureBlobStorage\BlobProxyFactoryInterface $blobProxyFactory
* @param \WindowsAzure\Blob\Internal\IBlob $blobProxy
*/
function it_should_not_mask_exception_when_read($blobProxyFactory, $blobProxy)
function it_should_not_mask_exception_when_read(BlobProxyFactoryInterface $blobProxyFactory, IBlob $blobProxy)
{
$blobProxy
->getBlob('containerName', 'filename')
Expand All @@ -88,11 +75,7 @@ function it_should_not_mask_exception_when_read($blobProxyFactory, $blobProxy)
$this->shouldThrow(new \RuntimeException('read'))->duringRead('filename');
}

/**
* @param \Gaufrette\Adapter\AzureBlobStorage\BlobProxyFactoryInterface $blobProxyFactory
* @param \WindowsAzure\Blob\Internal\IBlob $blobProxy
*/
function it_should_rename_file($blobProxyFactory, $blobProxy)
function it_should_rename_file(BlobProxyFactoryInterface $blobProxyFactory, IBlob $blobProxy)
{
$blobProxy
->copyBlob('containerName', 'filename2', 'containerName', 'filename1')
Expand All @@ -110,11 +93,7 @@ function it_should_rename_file($blobProxyFactory, $blobProxy)
$this->rename('filename1', 'filename2')->shouldReturn(true);
}

/**
* @param \Gaufrette\Adapter\AzureBlobStorage\BlobProxyFactoryInterface $blobProxyFactory
* @param \WindowsAzure\Blob\Internal\IBlob $blobProxy
*/
function it_should_return_false_when_cannot_rename($blobProxyFactory, $blobProxy)
function it_should_return_false_when_cannot_rename(BlobProxyFactoryInterface $blobProxyFactory, IBlob $blobProxy)
{
$blobProxy
->copyBlob('containerName', 'filename2', 'containerName', 'filename1')
Expand All @@ -129,11 +108,7 @@ function it_should_return_false_when_cannot_rename($blobProxyFactory, $blobProxy
$this->rename('filename1', 'filename2')->shouldReturn(false);
}

/**
* @param \Gaufrette\Adapter\AzureBlobStorage\BlobProxyFactoryInterface $blobProxyFactory
* @param \WindowsAzure\Blob\Internal\IBlob $blobProxy
*/
function it_should_not_mask_exception_when_rename($blobProxyFactory, $blobProxy)
function it_should_not_mask_exception_when_rename(BlobProxyFactoryInterface $blobProxyFactory, IBlob $blobProxy)
{
$blobProxy
->copyBlob('containerName', 'filename2', 'containerName', 'filename1')
Expand All @@ -148,11 +123,7 @@ function it_should_not_mask_exception_when_rename($blobProxyFactory, $blobProxy)
$this->shouldThrow(new \RuntimeException('rename'))->duringRename('filename1', 'filename2');
}

/**
* @param \Gaufrette\Adapter\AzureBlobStorage\BlobProxyFactoryInterface $blobProxyFactory
* @param \WindowsAzure\Blob\Internal\IBlob $blobProxy
*/
function it_should_write_file($blobProxyFactory, $blobProxy)
function it_should_write_file(BlobProxyFactoryInterface $blobProxyFactory, IBlob $blobProxy)
{
$blobProxy
->createBlockBlob(
Expand All @@ -171,11 +142,7 @@ function it_should_write_file($blobProxyFactory, $blobProxy)
$this->write('filename', 'some content')->shouldReturn(12);
}

/**
* @param \Gaufrette\Adapter\AzureBlobStorage\BlobProxyFactoryInterface $blobProxyFactory
* @param \WindowsAzure\Blob\Internal\IBlob $blobProxy
*/
function it_should_return_false_when_cannot_write($blobProxyFactory, $blobProxy)
function it_should_return_false_when_cannot_write(BlobProxyFactoryInterface $blobProxyFactory, IBlob $blobProxy)
{
$blobProxy
->createBlockBlob(
Expand All @@ -194,11 +161,7 @@ function it_should_return_false_when_cannot_write($blobProxyFactory, $blobProxy)
$this->write('filename', 'some content')->shouldReturn(false);
}

/**
* @param \Gaufrette\Adapter\AzureBlobStorage\BlobProxyFactoryInterface $blobProxyFactory
* @param \WindowsAzure\Blob\Internal\IBlob $blobProxy
*/
function it_should_not_mask_exception_when_write($blobProxyFactory, $blobProxy)
function it_should_not_mask_exception_when_write(BlobProxyFactoryInterface $blobProxyFactory, IBlob $blobProxy)
{
$blobProxy
->createBlockBlob(
Expand All @@ -217,12 +180,7 @@ function it_should_not_mask_exception_when_write($blobProxyFactory, $blobProxy)
$this->shouldThrow(new \RuntimeException('write'))->duringWrite('filename', 'some content');
}

/**
* @param \Gaufrette\Adapter\AzureBlobStorage\BlobProxyFactoryInterface $blobProxyFactory
* @param \WindowsAzure\Blob\Internal\IBlob $blobProxy
* @param \WindowsAzure\Blob\Models\GetBlobResult $getBlobResult
*/
function it_should_check_if_file_exists($blobProxyFactory, $blobProxy, $getBlobResult)
function it_should_check_if_file_exists(BlobProxyFactoryInterface $blobProxyFactory, IBlob $blobProxy, GetBlobResult $getBlobResult)
{
$blobProxyFactory
->create()
Expand All @@ -244,11 +202,7 @@ function it_should_check_if_file_exists($blobProxyFactory, $blobProxy, $getBlobR
$this->exists('filename2')->shouldReturn(true);
}

/**
* @param \Gaufrette\Adapter\AzureBlobStorage\BlobProxyFactoryInterface $blobProxyFactory
* @param \WindowsAzure\Blob\Internal\IBlob $blobProxy
*/
function it_should_not_mask_exception_when_check_if_file_exists($blobProxyFactory, $blobProxy)
function it_should_not_mask_exception_when_check_if_file_exists(BlobProxyFactoryInterface $blobProxyFactory, IBlob $blobProxy)
{
$blobProxyFactory
->create()
Expand All @@ -263,13 +217,7 @@ function it_should_not_mask_exception_when_check_if_file_exists($blobProxyFactor
$this->shouldThrow(new \RuntimeException('exists'))->duringExists('filename');
}

/**
* @param \Gaufrette\Adapter\AzureBlobStorage\BlobProxyFactoryInterface $blobProxyFactory
* @param \WindowsAzure\Blob\Internal\IBlob $blobProxy
* @param \WindowsAzure\Blob\Models\GetBlobPropertiesResult $getBlobPropertiesResult
* @param \WindowsAzure\Blob\Models\BlobProperties $blobProperties
*/
function it_should_get_file_mtime($blobProxyFactory, $blobProxy, $getBlobPropertiesResult, $blobProperties)
function it_should_get_file_mtime(BlobProxyFactoryInterface $blobProxyFactory, IBlob $blobProxy, GetBlobPropertiesResult $getBlobPropertiesResult, BlobProperties $blobProperties)
{
$blobProxyFactory
->create()
Expand All @@ -294,11 +242,7 @@ function it_should_get_file_mtime($blobProxyFactory, $blobProxy, $getBlobPropert
$this->mtime('filename')->shouldReturn(strtotime('1987-12-28 20:00:00'));
}

/**
* @param \Gaufrette\Adapter\AzureBlobStorage\BlobProxyFactoryInterface $blobProxyFactory
* @param \WindowsAzure\Blob\Internal\IBlob $blobProxy
*/
function it_should_return_false_when_cannot_mtime($blobProxyFactory, $blobProxy)
function it_should_return_false_when_cannot_mtime(BlobProxyFactoryInterface $blobProxyFactory, IBlob $blobProxy)
{
$blobProxyFactory
->create()
Expand All @@ -313,11 +257,7 @@ function it_should_return_false_when_cannot_mtime($blobProxyFactory, $blobProxy)
$this->mtime('filename')->shouldReturn(false);
}

/**
* @param \Gaufrette\Adapter\AzureBlobStorage\BlobProxyFactoryInterface $blobProxyFactory
* @param \WindowsAzure\Blob\Internal\IBlob $blobProxy
*/
function it_should_not_mask_exception_when_get_mtime($blobProxyFactory, $blobProxy)
function it_should_not_mask_exception_when_get_mtime(BlobProxyFactoryInterface $blobProxyFactory, IBlob $blobProxy)
{
$blobProxyFactory
->create()
Expand All @@ -332,11 +272,7 @@ function it_should_not_mask_exception_when_get_mtime($blobProxyFactory, $blobPro
$this->shouldThrow(new \RuntimeException('mtime'))->duringMtime('filename');
}

/**
* @param \Gaufrette\Adapter\AzureBlobStorage\BlobProxyFactoryInterface $blobProxyFactory
* @param \WindowsAzure\Blob\Internal\IBlob $blobProxy
*/
function it_should_delete_file($blobProxyFactory, $blobProxy)
function it_should_delete_file(BlobProxyFactoryInterface $blobProxyFactory, IBlob $blobProxy)
{
$blobProxyFactory
->create()
Expand All @@ -350,11 +286,7 @@ function it_should_delete_file($blobProxyFactory, $blobProxy)
$this->delete('filename')->shouldReturn(true);
}

/**
* @param \Gaufrette\Adapter\AzureBlobStorage\BlobProxyFactoryInterface $blobProxyFactory
* @param \WindowsAzure\Blob\Internal\IBlob $blobProxy
*/
function it_should_return_false_when_cannot_delete_file($blobProxyFactory, $blobProxy)
function it_should_return_false_when_cannot_delete_file(BlobProxyFactoryInterface $blobProxyFactory, IBlob $blobProxy)
{
$blobProxyFactory
->create()
Expand All @@ -369,11 +301,7 @@ function it_should_return_false_when_cannot_delete_file($blobProxyFactory, $blob
$this->delete('filename')->shouldReturn(false);
}

/**
* @param \Gaufrette\Adapter\AzureBlobStorage\BlobProxyFactoryInterface $blobProxyFactory
* @param \WindowsAzure\Blob\Internal\IBlob $blobProxy
*/
function it_should_not_mask_exception_when_delete($blobProxyFactory, $blobProxy)
function it_should_not_mask_exception_when_delete(BlobProxyFactoryInterface $blobProxyFactory, IBlob $blobProxy)
{
$blobProxyFactory
->create()
Expand All @@ -388,12 +316,7 @@ function it_should_not_mask_exception_when_delete($blobProxyFactory, $blobProxy)
$this->shouldThrow(new \RuntimeException('delete'))->duringDelete('filename');
}

/**
* @param \Gaufrette\Adapter\AzureBlobStorage\BlobProxyFactoryInterface $blobProxyFactory
* @param \WindowsAzure\Blob\Internal\IBlob $blobProxy
* @param \WindowsAzure\Blob\Models\ListBlobsResult $listBlobResult
*/
function it_should_get_keys($blobProxyFactory, $blobProxy, $listBlobResult)
function it_should_get_keys(BlobProxyFactoryInterface $blobProxyFactory, IBlob $blobProxy, ListBlobsResult $listBlobResult)
{
$fileNames = ['aaa', 'aaa/filename', 'filename1', 'filename2'];
$blobs = [];
Expand Down Expand Up @@ -421,11 +344,7 @@ function it_should_get_keys($blobProxyFactory, $blobProxy, $listBlobResult)
$this->keys()->shouldReturn(['aaa', 'aaa/filename', 'filename1', 'filename2']);
}

/**
* @param \Gaufrette\Adapter\AzureBlobStorage\BlobProxyFactoryInterface $blobProxyFactory
* @param \WindowsAzure\Blob\Internal\IBlob $blobProxy
*/
function it_should_not_mask_exception_when_get_keys($blobProxyFactory, $blobProxy)
function it_should_not_mask_exception_when_get_keys(BlobProxyFactoryInterface $blobProxyFactory, IBlob $blobProxy)
{
$blobProxyFactory
->create()
Expand All @@ -440,11 +359,7 @@ function it_should_not_mask_exception_when_get_keys($blobProxyFactory, $blobProx
$this->shouldThrow(new \RuntimeException('keys'))->duringKeys();
}

/**
* @param \Gaufrette\Adapter\AzureBlobStorage\BlobProxyFactoryInterface $blobProxyFactory
* @param \WindowsAzure\Blob\Internal\IBlob $blobProxy
*/
function it_should_handle_dirs($blobProxyFactory, $blobProxy)
function it_should_handle_dirs(BlobProxyFactoryInterface $blobProxyFactory, IBlob $blobProxy)
{
$blobProxyFactory
->create()
Expand All @@ -466,11 +381,7 @@ function it_should_handle_dirs($blobProxyFactory, $blobProxy)
$this->isDirectory('dirname')->shouldReturn(true);
}

/**
* @param \Gaufrette\Adapter\AzureBlobStorage\BlobProxyFactoryInterface $blobProxyFactory
* @param \WindowsAzure\Blob\Internal\IBlob $blobProxy
*/
function it_should_create_container($blobProxyFactory, $blobProxy)
function it_should_create_container(BlobProxyFactoryInterface $blobProxyFactory, IBlob $blobProxy)
{
$blobProxyFactory
->create()
Expand All @@ -484,11 +395,7 @@ function it_should_create_container($blobProxyFactory, $blobProxy)
$this->createContainer('containerName');
}

/**
* @param \Gaufrette\Adapter\AzureBlobStorage\BlobProxyFactoryInterface $blobProxyFactory
* @param \WindowsAzure\Blob\Internal\IBlob $blobProxy
*/
function it_should_fail_when_cannot_create_container($blobProxyFactory, $blobProxy)
function it_should_fail_when_cannot_create_container(BlobProxyFactoryInterface $blobProxyFactory, IBlob $blobProxy)
{
$blobProxyFactory
->create()
Expand Down
Loading

0 comments on commit 6227d85

Please sign in to comment.