From 20b0b047193f985fbf82123c82008e11c1c54e53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin?= Date: Fri, 21 Apr 2023 15:13:07 +0200 Subject: [PATCH 01/48] feat: add typehint on adapter --- src/Gaufrette/Adapter.php | 42 +++++++++------------------------------ 1 file changed, 9 insertions(+), 33 deletions(-) diff --git a/src/Gaufrette/Adapter.php b/src/Gaufrette/Adapter.php index c6c4a95ba..5b9c2d417 100644 --- a/src/Gaufrette/Adapter.php +++ b/src/Gaufrette/Adapter.php @@ -13,72 +13,48 @@ interface Adapter /** * Reads the content of the file. * - * @param string $key - * * @return string|bool if cannot read content */ - public function read($key); + public function read(string $key): string|bool; /** * Writes the given content into the file. * - * @param string $key - * @param string $content - * * @return int|bool The number of bytes that were written into the file */ - public function write($key, $content); + public function write(string $key, string $content): int|bool; /** * Indicates whether the file exists. - * - * @param string $key - * - * @return bool */ - public function exists($key); + public function exists(string $key): bool; /** * Returns an array of all keys (files and directories). * - * @return array + * @return array */ - public function keys(); + public function keys(): array; /** * Returns the last modified time. * - * @param string $key - * * @return int|bool An UNIX like timestamp or false */ - public function mtime($key); + public function mtime(string $key): int|bool; /** * Deletes the file. - * - * @param string $key - * - * @return bool */ - public function delete($key); + public function delete(string$key): bool; /** * Renames a file. - * - * @param string $sourceKey - * @param string $targetKey - * - * @return bool */ - public function rename($sourceKey, $targetKey); + public function rename(string $sourceKey, string $targetKey): bool; /** * Check if key is directory. - * - * @param string $key - * - * @return bool */ - public function isDirectory($key); + public function isDirectory(string $key): bool; } From ab3604b215f9afe902cbd5ee7f4fd4b3618d06ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin?= Date: Fri, 21 Apr 2023 15:38:02 +0200 Subject: [PATCH 02/48] Type interface for adapters --- src/Gaufrette/Adapter.php | 4 ++-- src/Gaufrette/Adapter/ListKeysAware.php | 6 +----- src/Gaufrette/Adapter/MetadataSupporter.php | 13 ++----------- src/Gaufrette/Adapter/MimeTypeProvider.php | 6 +----- src/Gaufrette/Adapter/SizeCalculator.php | 6 +----- 5 files changed, 7 insertions(+), 28 deletions(-) diff --git a/src/Gaufrette/Adapter.php b/src/Gaufrette/Adapter.php index 5b9c2d417..b4a412df4 100644 --- a/src/Gaufrette/Adapter.php +++ b/src/Gaufrette/Adapter.php @@ -22,7 +22,7 @@ public function read(string $key): string|bool; * * @return int|bool The number of bytes that were written into the file */ - public function write(string $key, string $content): int|bool; + public function write(string $key, mixed $content): int|bool; /** * Indicates whether the file exists. @@ -46,7 +46,7 @@ public function mtime(string $key): int|bool; /** * Deletes the file. */ - public function delete(string$key): bool; + public function delete(string $key): bool; /** * Renames a file. diff --git a/src/Gaufrette/Adapter/ListKeysAware.php b/src/Gaufrette/Adapter/ListKeysAware.php index bea2a3d8d..7b6d559d0 100644 --- a/src/Gaufrette/Adapter/ListKeysAware.php +++ b/src/Gaufrette/Adapter/ListKeysAware.php @@ -12,10 +12,6 @@ interface ListKeysAware /** * Lists keys beginning with pattern given * (no wildcard / regex matching). - * - * @param string $prefix - * - * @return array */ - public function listKeys($prefix = ''); + public function listKeys(string $prefix = ''): array; } diff --git a/src/Gaufrette/Adapter/MetadataSupporter.php b/src/Gaufrette/Adapter/MetadataSupporter.php index 16a4daeb4..19f319b5c 100644 --- a/src/Gaufrette/Adapter/MetadataSupporter.php +++ b/src/Gaufrette/Adapter/MetadataSupporter.php @@ -9,16 +9,7 @@ */ interface MetadataSupporter { - /** - * @param string $key - * @param array $content - */ - public function setMetadata($key, $content); + public function setMetadata(string $key, array $content); - /** - * @param string $key - * - * @return array - */ - public function getMetadata($key); + public function getMetadata(string $key): array; } diff --git a/src/Gaufrette/Adapter/MimeTypeProvider.php b/src/Gaufrette/Adapter/MimeTypeProvider.php index 16b1fc88a..53617beaf 100644 --- a/src/Gaufrette/Adapter/MimeTypeProvider.php +++ b/src/Gaufrette/Adapter/MimeTypeProvider.php @@ -11,10 +11,6 @@ interface MimeTypeProvider { /** * Returns the mime type of the specified key. - * - * @param string $key - * - * @return string */ - public function mimeType($key); + public function mimeType(string $key): string; } diff --git a/src/Gaufrette/Adapter/SizeCalculator.php b/src/Gaufrette/Adapter/SizeCalculator.php index 512537a5b..fa1e08100 100644 --- a/src/Gaufrette/Adapter/SizeCalculator.php +++ b/src/Gaufrette/Adapter/SizeCalculator.php @@ -11,10 +11,6 @@ interface SizeCalculator { /** * Returns the size of the specified key. - * - * @param string $key - * - * @return int */ - public function size($key); + public function size(string $key): int; } From ed226324e518cc6737705f111148eca03f1f8ded Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin?= Date: Fri, 21 Apr 2023 15:38:20 +0200 Subject: [PATCH 03/48] Type AsyncAwsS3 --- src/Gaufrette/Adapter/AsyncAwsS3.php | 83 ++++++++++------------------ 1 file changed, 30 insertions(+), 53 deletions(-) diff --git a/src/Gaufrette/Adapter/AsyncAwsS3.php b/src/Gaufrette/Adapter/AsyncAwsS3.php index 0ee94bb6d..c0979a2f7 100644 --- a/src/Gaufrette/Adapter/AsyncAwsS3.php +++ b/src/Gaufrette/Adapter/AsyncAwsS3.php @@ -10,37 +10,26 @@ /** * Amazon S3 adapter using the AsyncAws. * - * @author Michael Dowling + * @author Michael Dowling * @author Tobias Nyholm */ class AsyncAwsS3 implements Adapter, MetadataSupporter, ListKeysAware, SizeCalculator, MimeTypeProvider { - /** @var SimpleS3Client */ - protected $service; - /** @var string */ - protected $bucket; - /** @var array */ - protected $options; - /** @var bool */ - protected $bucketExists; - /** @var array */ - protected $metadata = []; - /** @var bool */ - protected $detectContentType; - - /** - * @param SimpleS3Client $service - * @param string $bucket - * @param array $options - * @param bool $detectContentType - */ - public function __construct(SimpleS3Client $service, $bucket, array $options = [], $detectContentType = false) - { + protected SimpleS3Client $service; + protected array $options; + protected bool $bucketExists; + protected array $metadata = []; + + public function __construct( + SimpleS3Client $service, + private readonly string $bucket, + array $options = [], + private readonly bool $detectContentType = false + ) { if (!class_exists(SimpleS3Client::class)) { throw new \LogicException('You need to install package "async-aws/simple-s3" to use this adapter'); } $this->service = $service; - $this->bucket = $bucket; $this->options = array_replace( [ 'create' => false, @@ -49,14 +38,12 @@ public function __construct(SimpleS3Client $service, $bucket, array $options = [ ], $options ); - - $this->detectContentType = $detectContentType; } /** * {@inheritdoc} */ - public function setMetadata($key, $content) + public function setMetadata(string $key, array $content) { // BC with AmazonS3 adapter if (isset($content['contentType'])) { @@ -70,7 +57,7 @@ public function setMetadata($key, $content) /** * {@inheritdoc} */ - public function getMetadata($key) + public function getMetadata(string $key): array { return $this->metadata[$key] ?? []; } @@ -78,7 +65,7 @@ public function getMetadata($key) /** * {@inheritdoc} */ - public function read($key) + public function read(string $key): string|bool { $this->ensureBucketExists(); $options = $this->getOptions($key); @@ -102,7 +89,7 @@ public function read($key) /** * {@inheritdoc} */ - public function rename($sourceKey, $targetKey) + public function rename(string $sourceKey, string $targetKey): bool { $this->ensureBucketExists(); $options = $this->getOptions( @@ -121,9 +108,8 @@ public function rename($sourceKey, $targetKey) /** * {@inheritdoc} - * @param string|resource $content */ - public function write($key, $content) + public function write(string $key, mixed $content): int|bool { $this->ensureBucketExists(); $options = $this->getOptions($key); @@ -153,7 +139,7 @@ public function write($key, $content) /** * {@inheritdoc} */ - public function exists($key) + public function exists(string $key): bool { return $this->service->has($this->bucket, $this->computePath($key)); } @@ -161,7 +147,7 @@ public function exists($key) /** * {@inheritdoc} */ - public function mtime($key) + public function mtime(string $key): int|bool { try { $result = $this->service->headObject($this->getOptions($key)); @@ -175,14 +161,14 @@ public function mtime($key) /** * {@inheritdoc} */ - public function size($key) + public function size(string $key): int { $result = $this->service->headObject($this->getOptions($key)); return (int) $result->getContentLength(); } - public function mimeType($key) + public function mimeType(string $key): string { $result = $this->service->headObject($this->getOptions($key)); @@ -192,7 +178,7 @@ public function mimeType($key) /** * {@inheritdoc} */ - public function keys() + public function keys(): array { return $this->listKeys(); } @@ -200,7 +186,7 @@ public function keys() /** * {@inheritdoc} */ - public function listKeys($prefix = '') + public function listKeys(string $prefix = ''): array { $this->ensureBucketExists(); @@ -223,7 +209,7 @@ public function listKeys($prefix = '') /** * {@inheritdoc} */ - public function delete($key) + public function delete(string $key): bool { try { $this->service->deleteObject($this->getOptions($key)); @@ -237,7 +223,7 @@ public function delete($key) /** * {@inheritdoc} */ - public function isDirectory($key) + public function isDirectory(string $key): bool { $result = $this->service->listObjectsV2([ 'Bucket' => $this->bucket, @@ -261,7 +247,7 @@ public function isDirectory($key) * @throws \RuntimeException if the bucket does not exists or could not be * created */ - protected function ensureBucketExists() + protected function ensureBucketExists(): bool { if ($this->bucketExists) { return true; @@ -288,7 +274,7 @@ protected function ensureBucketExists() return true; } - protected function getOptions($key, array $options = []) + protected function getOptions(string $key, array $options = []): array { $options['ACL'] = $this->options['acl']; $options['Bucket'] = $this->bucket; @@ -303,7 +289,7 @@ protected function getOptions($key, array $options = []) return $options; } - protected function computePath($key) + protected function computePath(string $key): string { if (empty($this->options['directory'])) { return $key; @@ -314,22 +300,13 @@ protected function computePath($key) /** * Computes the key from the specified path. - * - * @param string $path - * - * return string */ - protected function computeKey($path) + protected function computeKey(string $path): string { return ltrim(substr($path, strlen($this->options['directory'])), '/'); } - /** - * @param string|resource $content - * - * @return string - */ - private function guessContentType($content) + private function guessContentType(mixed $content): false|string { $fileInfo = new \finfo(FILEINFO_MIME_TYPE); From a7db6fd49f55878adcc05d18128ec21a37f3661d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin?= Date: Fri, 21 Apr 2023 15:42:33 +0200 Subject: [PATCH 04/48] Type AwsS3 --- src/Gaufrette/Adapter/AsyncAwsS3.php | 2 +- src/Gaufrette/Adapter/AwsS3.php | 102 ++++++++------------ src/Gaufrette/Adapter/MetadataSupporter.php | 2 +- 3 files changed, 42 insertions(+), 64 deletions(-) diff --git a/src/Gaufrette/Adapter/AsyncAwsS3.php b/src/Gaufrette/Adapter/AsyncAwsS3.php index c0979a2f7..b8cec1324 100644 --- a/src/Gaufrette/Adapter/AsyncAwsS3.php +++ b/src/Gaufrette/Adapter/AsyncAwsS3.php @@ -43,7 +43,7 @@ public function __construct( /** * {@inheritdoc} */ - public function setMetadata(string $key, array $content) + public function setMetadata(string $key, array $content): void { // BC with AmazonS3 adapter if (isset($content['contentType'])) { diff --git a/src/Gaufrette/Adapter/AwsS3.php b/src/Gaufrette/Adapter/AwsS3.php index 2d335a1c6..6ff0bbf6f 100644 --- a/src/Gaufrette/Adapter/AwsS3.php +++ b/src/Gaufrette/Adapter/AwsS3.php @@ -9,36 +9,25 @@ /** * Amazon S3 adapter using the AWS SDK for PHP v2.x. * - * @author Michael Dowling + * @author Michael Dowling */ class AwsS3 implements Adapter, MetadataSupporter, ListKeysAware, SizeCalculator, MimeTypeProvider { - /** @var S3Client */ - protected $service; - /** @var string */ - protected $bucket; - /** @var array */ - protected $options; - /** @var bool */ - protected $bucketExists; - /** @var array */ - protected $metadata = []; - /** @var bool */ - protected $detectContentType; - - /** - * @param S3Client $service - * @param string $bucket - * @param array $options - * @param bool $detectContentType - */ - public function __construct(S3Client $service, $bucket, array $options = [], $detectContentType = false) - { + protected S3Client $service; + protected array $options; + protected bool $bucketExists; + protected array $metadata = []; + + public function __construct( + S3Client $service, + private readonly string $bucket, + array $options = [], + private readonly bool $detectContentType = false + ) { if (!class_exists(S3Client::class)) { throw new \LogicException('You need to install package "aws/aws-sdk-php" to use this adapter'); } $this->service = $service; - $this->bucket = $bucket; $this->options = array_replace( [ 'create' => false, @@ -47,14 +36,12 @@ public function __construct(S3Client $service, $bucket, array $options = [], $de ], $options ); - - $this->detectContentType = $detectContentType; } /** * {@inheritdoc} */ - public function setMetadata($key, $metadata) + public function setMetadata(string $key, array $content): void { // BC with AmazonS3 adapter if (isset($metadata['contentType'])) { @@ -68,7 +55,7 @@ public function setMetadata($key, $metadata) /** * {@inheritdoc} */ - public function getMetadata($key) + public function getMetadata(string $key): array { return $this->metadata[$key] ?? []; } @@ -76,7 +63,7 @@ public function getMetadata($key) /** * {@inheritdoc} */ - public function read($key) + public function read(string $key): string|bool { $this->ensureBucketExists(); $options = $this->getOptions($key); @@ -100,7 +87,7 @@ public function read($key) /** * {@inheritdoc} */ - public function rename($sourceKey, $targetKey) + public function rename(string $sourceKey, string $targetKey): bool { $this->ensureBucketExists(); $options = $this->getOptions( @@ -120,7 +107,7 @@ public function rename($sourceKey, $targetKey) /** * {@inheritdoc} */ - public function write($key, $content) + public function write(string $key, mixed $content): int|bool { $this->ensureBucketExists(); $options = $this->getOptions($key, ['Body' => $content]); @@ -149,7 +136,7 @@ public function write($key, $content) /** * {@inheritdoc} */ - public function exists($key) + public function exists(string $key): bool { return $this->service->doesObjectExist($this->bucket, $this->computePath($key)); } @@ -157,7 +144,7 @@ public function exists($key) /** * {@inheritdoc} */ - public function mtime($key) + public function mtime(string $key): int|bool { try { $result = $this->service->headObject($this->getOptions($key)); @@ -171,7 +158,7 @@ public function mtime($key) /** * {@inheritdoc} */ - public function size($key) + public function size(string $key): int { try { $result = $this->service->headObject($this->getOptions($key)); @@ -182,10 +169,21 @@ public function size($key) } } + public function mimeType(string $key): string + { + try { + $result = $this->service->headObject($this->getOptions($key)); + + return ($result['ContentType']); + } catch (\Exception $e) { + return false; + } + } + /** * {@inheritdoc} */ - public function keys() + public function keys(): array { return $this->listKeys(); } @@ -193,7 +191,7 @@ public function keys() /** * {@inheritdoc} */ - public function listKeys($prefix = '') + public function listKeys(string $prefix = ''): array { $this->ensureBucketExists(); @@ -216,7 +214,7 @@ public function listKeys($prefix = '') /** * {@inheritdoc} */ - public function delete($key) + public function delete(string $key): bool { try { $this->service->deleteObject($this->getOptions($key)); @@ -230,7 +228,7 @@ public function delete($key) /** * {@inheritdoc} */ - public function isDirectory($key) + public function isDirectory(string $key): bool { $result = $this->service->listObjects([ 'Bucket' => $this->bucket, @@ -255,7 +253,7 @@ public function isDirectory($key) * @throws \RuntimeException if the bucket does not exists or could not be * created */ - protected function ensureBucketExists() + protected function ensureBucketExists(): bool { if ($this->bucketExists) { return true; @@ -281,7 +279,7 @@ protected function ensureBucketExists() return true; } - protected function getOptions($key, array $options = []) + protected function getOptions(string $key, array $options = []): array { $options['ACL'] = $this->options['acl']; $options['Bucket'] = $this->bucket; @@ -296,7 +294,7 @@ protected function getOptions($key, array $options = []) return $options; } - protected function computePath($key) + protected function computePath(string $key): string { if (empty($this->options['directory'])) { return $key; @@ -307,22 +305,13 @@ protected function computePath($key) /** * Computes the key from the specified path. - * - * @param string $path - * - * return string */ - protected function computeKey($path) + protected function computeKey(string $path): string { return ltrim(substr($path, strlen($this->options['directory'])), '/'); } - /** - * @param string $content - * - * @return string - */ - private function guessContentType($content) + private function guessContentType(mixed $content): false|string { $fileInfo = new \finfo(FILEINFO_MIME_TYPE); @@ -332,15 +321,4 @@ private function guessContentType($content) return $fileInfo->buffer($content); } - - public function mimeType($key) - { - try { - $result = $this->service->headObject($this->getOptions($key)); - - return ($result['ContentType']); - } catch (\Exception $e) { - return false; - } - } } diff --git a/src/Gaufrette/Adapter/MetadataSupporter.php b/src/Gaufrette/Adapter/MetadataSupporter.php index 19f319b5c..c40f5f64f 100644 --- a/src/Gaufrette/Adapter/MetadataSupporter.php +++ b/src/Gaufrette/Adapter/MetadataSupporter.php @@ -9,7 +9,7 @@ */ interface MetadataSupporter { - public function setMetadata(string $key, array $content); + public function setMetadata(string $key, array $content): void; public function getMetadata(string $key): array; } From 7ef46f71451c1084b36a4059527dcbe9af70c244 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin?= Date: Fri, 21 Apr 2023 15:56:53 +0200 Subject: [PATCH 05/48] Type AzureBlobStorage --- src/Gaufrette/Adapter/AzureBlobStorage.php | 142 +++++-------------- src/Gaufrette/Adapter/ChecksumCalculator.php | 6 +- 2 files changed, 34 insertions(+), 114 deletions(-) diff --git a/src/Gaufrette/Adapter/AzureBlobStorage.php b/src/Gaufrette/Adapter/AzureBlobStorage.php index c153f9c01..d9d81c329 100644 --- a/src/Gaufrette/Adapter/AzureBlobStorage.php +++ b/src/Gaufrette/Adapter/AzureBlobStorage.php @@ -28,49 +28,18 @@ class AzureBlobStorage implements Adapter, MetadataSupporter, SizeCalculator, Ch const ERROR_CONTAINER_ALREADY_EXISTS = 'ContainerAlreadyExists'; const ERROR_CONTAINER_NOT_FOUND = 'ContainerNotFound'; - /** - * @var AzureBlobStorage\BlobProxyFactoryInterface - */ - protected $blobProxyFactory; + protected \MicrosoftAzure\Storage\Blob\Internal\IBlob $blobProxy; - /** - * @var string - */ - protected $containerName; + protected bool $multiContainerMode = false; - /** - * @var bool - */ - protected $detectContentType; + protected CreateContainerOptions $createContainerOptions; - /** - * @var \MicrosoftAzure\Storage\Blob\Internal\IBlob - */ - protected $blobProxy; - - /** - * @var bool - */ - protected $multiContainerMode = false; - - /** - * @var CreateContainerOptions - */ - protected $createContainerOptions; - - /** - * @param AzureBlobStorage\BlobProxyFactoryInterface $blobProxyFactory - * @param string|null $containerName - * @param bool $create - * @param bool $detectContentType - * - * @throws \RuntimeException - */ - public function __construct(BlobProxyFactoryInterface $blobProxyFactory, $containerName = null, $create = false, $detectContentType = true) - { - $this->blobProxyFactory = $blobProxyFactory; - $this->containerName = $containerName; - $this->detectContentType = $detectContentType; + public function __construct( + private readonly BlobProxyFactoryInterface $blobProxyFactory, + private readonly ?string $containerName = null, + bool $create = false, + private readonly bool $detectContentType = true + ) { if (null === $containerName) { $this->multiContainerMode = true; } elseif ($create) { @@ -78,17 +47,11 @@ public function __construct(BlobProxyFactoryInterface $blobProxyFactory, $contai } } - /** - * @return CreateContainerOptions - */ - public function getCreateContainerOptions() + public function getCreateContainerOptions(): CreateContainerOptions { return $this->createContainerOptions; } - /** - * @param CreateContainerOptions $options - */ public function setCreateContainerOptions(CreateContainerOptions $options) { $this->createContainerOptions = $options; @@ -97,12 +60,9 @@ public function setCreateContainerOptions(CreateContainerOptions $options) /** * Creates a new container. * - * @param string $containerName - * @param \MicrosoftAzure\Storage\Blob\Models\CreateContainerOptions $options - * * @throws \RuntimeException if cannot create the container */ - public function createContainer($containerName, CreateContainerOptions $options = null) + public function createContainer(string $containerName, CreateContainerOptions $options = null) { $this->init(); @@ -129,12 +89,9 @@ public function createContainer($containerName, CreateContainerOptions $options /** * Deletes a container. * - * @param string $containerName - * @param BlobServiceOptions $options - * * @throws \RuntimeException if cannot delete the container */ - public function deleteContainer($containerName, BlobServiceOptions $options = null) + public function deleteContainer(string $containerName, BlobServiceOptions $options = null) { $this->init(); @@ -156,10 +113,8 @@ public function deleteContainer($containerName, BlobServiceOptions $options = nu /** * {@inheritdoc} - * @throws \RuntimeException - * @throws \InvalidArgumentException */ - public function read($key) + public function read(string $key): string|bool { $this->init(); list($containerName, $key) = $this->tokenizeKey($key); @@ -177,10 +132,8 @@ public function read($key) /** * {@inheritdoc} - * @throws \RuntimeException - * @throws \InvalidArgumentException */ - public function write($key, $content) + public function write(string $key, mixed $content): int|bool { $this->init(); list($containerName, $key) = $this->tokenizeKey($key); @@ -220,10 +173,8 @@ public function write($key, $content) /** * {@inheritdoc} - * @throws \RuntimeException - * @throws \InvalidArgumentException */ - public function exists($key) + public function exists(string $key): bool { $this->init(); list($containerName, $key) = $this->tokenizeKey($key); @@ -260,9 +211,8 @@ public function exists($key) /** * {@inheritdoc} - * @throws \RuntimeException */ - public function keys() + public function keys(): array { $this->init(); @@ -296,10 +246,8 @@ function (Container $container) { /** * {@inheritdoc} - * @throws \RuntimeException - * @throws \InvalidArgumentException */ - public function mtime($key) + public function mtime(string $key): int|bool { $this->init(); list($containerName, $key) = $this->tokenizeKey($key); @@ -318,7 +266,7 @@ public function mtime($key) /** * {@inheritdoc} */ - public function size($key) + public function size(string $key): int { $this->init(); list($containerName, $key) = $this->tokenizeKey($key); @@ -337,7 +285,7 @@ public function size($key) /** * {@inheritdoc} */ - public function mimeType($key) + public function mimeType(string $key): string { $this->init(); list($containerName, $key) = $this->tokenizeKey($key); @@ -356,7 +304,7 @@ public function mimeType($key) /** * {@inheritdoc} */ - public function checksum($key) + public function checksum(string $key): string { $this->init(); list($containerName, $key) = $this->tokenizeKey($key); @@ -375,10 +323,8 @@ public function checksum($key) /** * {@inheritdoc} - * @throws \RuntimeException - * @throws \InvalidArgumentException */ - public function delete($key) + public function delete(string $key): bool { $this->init(); list($containerName, $key) = $this->tokenizeKey($key); @@ -396,10 +342,8 @@ public function delete($key) /** * {@inheritdoc} - * @throws \RuntimeException - * @throws \InvalidArgumentException */ - public function rename($sourceKey, $targetKey) + public function rename(string $sourceKey, string $targetKey): bool { $this->init(); @@ -424,7 +368,7 @@ public function rename($sourceKey, $targetKey) /** * {@inheritdoc} */ - public function isDirectory($key) + public function isDirectory(string $key): bool { // Windows Azure Blob Storage does not support directories return false; @@ -432,10 +376,8 @@ public function isDirectory($key) /** * {@inheritdoc} - * @throws \RuntimeException - * @throws \InvalidArgumentException */ - public function setMetadata($key, $content) + public function setMetadata(string $key, array $content): void { $this->init(); list($containerName, $key) = $this->tokenizeKey($key); @@ -457,10 +399,8 @@ public function setMetadata($key, $content) /** * {@inheritdoc} - * @throws \RuntimeException - * @throws \InvalidArgumentException */ - public function getMetadata($key) + public function getMetadata(string $key): array { $this->init(); list($containerName, $key) = $this->tokenizeKey($key); @@ -485,7 +425,7 @@ public function getMetadata($key) /** * Lazy initialization, automatically called when some method is called after construction. */ - protected function init() + protected function init(): void { if ($this->blobProxy === null) { $this->blobProxy = $this->blobProxyFactory->create(); @@ -495,13 +435,9 @@ protected function init() /** * Throws a runtime exception if a give ServiceException derived from a "container not found" error. * - * @param ServiceException $exception - * @param string $action - * @param string $containerName - * * @throws \RuntimeException */ - protected function failIfContainerNotFound(ServiceException $exception, $action, $containerName) + protected function failIfContainerNotFound(ServiceException $exception, string $action, string $containerName): void { $errorCode = $this->getErrorCodeFromServiceException($exception); @@ -516,12 +452,8 @@ protected function failIfContainerNotFound(ServiceException $exception, $action, /** * Extracts the error code from a service exception. - * - * @param ServiceException $exception - * - * @return string */ - protected function getErrorCodeFromServiceException(ServiceException $exception) + protected function getErrorCodeFromServiceException(ServiceException $exception): string { $xml = @simplexml_load_string($exception->getResponse()->getBody()); @@ -534,10 +466,8 @@ protected function getErrorCodeFromServiceException(ServiceException $exception) /** * @param string|resource $content - * - * @return string */ - private function guessContentType($content) + private function guessContentType($content): string { $fileInfo = new \finfo(FILEINFO_MIME_TYPE); @@ -549,12 +479,9 @@ private function guessContentType($content) } /** - * @param string $key - * - * @return array - * @throws \InvalidArgumentException + * @return array */ - private function tokenizeKey($key) + private function tokenizeKey(string $key): array { $containerName = $this->containerName; if (false === $this->multiContainerMode) { @@ -574,12 +501,9 @@ private function tokenizeKey($key) } /** - * @param string $containerName - * @param null $prefix - * - * @return array + * @return array */ - private function fetchBlobs($containerName, $prefix = null) + private function fetchBlobs(string $containerName, ?string $prefix = null): array { $blobList = $this->blobProxy->listBlobs($containerName); diff --git a/src/Gaufrette/Adapter/ChecksumCalculator.php b/src/Gaufrette/Adapter/ChecksumCalculator.php index 46ca2b7db..cef02e127 100644 --- a/src/Gaufrette/Adapter/ChecksumCalculator.php +++ b/src/Gaufrette/Adapter/ChecksumCalculator.php @@ -11,10 +11,6 @@ interface ChecksumCalculator { /** * Returns the checksum of the specified key. - * - * @param string $key - * - * @return string */ - public function checksum($key); + public function checksum(string $key): string; } From f4065b148de836f6b2fc36ebc5841cd06e2cee36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin?= Date: Fri, 21 Apr 2023 16:02:09 +0200 Subject: [PATCH 06/48] Type DoctrineDbal --- src/Gaufrette/Adapter/DoctrineDbal.php | 42 ++++++++++++++------------ 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/src/Gaufrette/Adapter/DoctrineDbal.php b/src/Gaufrette/Adapter/DoctrineDbal.php index 77066d2fb..dcb24a2d4 100644 --- a/src/Gaufrette/Adapter/DoctrineDbal.php +++ b/src/Gaufrette/Adapter/DoctrineDbal.php @@ -16,9 +16,7 @@ */ class DoctrineDbal implements Adapter, ChecksumCalculator, ListKeysAware { - protected $connection; - protected $table; - protected $columns = [ + protected array $columns = [ 'key' => 'key', 'content' => 'content', 'mtime' => 'mtime', @@ -30,21 +28,22 @@ class DoctrineDbal implements Adapter, ChecksumCalculator, ListKeysAware * @param string $table The files table * @param array $columns The column names */ - public function __construct(Connection $connection, $table, array $columns = []) - { + public function __construct( + private readonly Connection $connection, + private readonly string $table, + array $columns = [] + ) { if (!class_exists(Connection::class)) { throw new \LogicException('You need to install package "doctrine/dbal" to use this adapter'); } - $this->connection = $connection; - $this->table = $table; $this->columns = array_replace($this->columns, $columns); } /** * {@inheritdoc} */ - public function keys() + public function keys(): array { $keys = []; $stmt = $this->connection->executeQuery(sprintf( @@ -65,7 +64,7 @@ public function keys() /** * {@inheritdoc} */ - public function rename($sourceKey, $targetKey) + public function rename(string $sourceKey, string $targetKey): bool { return (boolean) $this->connection->update( $this->table, @@ -77,7 +76,7 @@ public function rename($sourceKey, $targetKey) /** * {@inheritdoc} */ - public function mtime($key) + public function mtime(string $key): int|bool { return $this->getColumnValue($key, 'mtime'); } @@ -85,7 +84,7 @@ public function mtime($key) /** * {@inheritdoc} */ - public function checksum($key) + public function checksum(string $key): string { return $this->getColumnValue($key, 'checksum'); } @@ -93,7 +92,7 @@ public function checksum($key) /** * {@inheritdoc} */ - public function exists($key) + public function exists(string $key): bool { $method = 'fetchOne'; // dbal 3.x if (!method_exists(Connection::class, $method)) { @@ -114,7 +113,7 @@ public function exists($key) /** * {@inheritdoc} */ - public function read($key) + public function read(string $key): string|bool { return $this->getColumnValue($key, 'content'); } @@ -122,7 +121,7 @@ public function read($key) /** * {@inheritdoc} */ - public function delete($key) + public function delete(string $key): bool { return (boolean) $this->connection->delete( $this->table, @@ -133,7 +132,7 @@ public function delete($key) /** * {@inheritdoc} */ - public function write($key, $content) + public function write(string $key, mixed $content): int|bool { $values = [ $this->getQuotedColumn('content') => $content, @@ -158,12 +157,15 @@ public function write($key, $content) /** * {@inheritdoc} */ - public function isDirectory($key) + public function isDirectory(string $key): bool { return false; } - private function getColumnValue($key, $column) + /** + * @return mixed|false + */ + private function getColumnValue(string $key, string $column) { $method = 'fetchOne'; // dbal 3.x if (!method_exists(Connection::class, $method)) { @@ -186,7 +188,7 @@ private function getColumnValue($key, $column) /** * {@inheritdoc} */ - public function listKeys($prefix = '') + public function listKeys(string $prefix = ''): array { $prefix = trim($prefix); @@ -216,12 +218,12 @@ function ($value) { ]; } - private function getQuotedTable() + private function getQuotedTable(): string { return $this->connection->quoteIdentifier($this->table); } - private function getQuotedColumn($column) + private function getQuotedColumn(string $column) { return $this->connection->quoteIdentifier($this->columns[$column]); } From 17fb146c4fac059bf8dc546834659c87ad0945fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin?= Date: Fri, 21 Apr 2023 16:02:22 +0200 Subject: [PATCH 07/48] fix constructor AsyncAwsS3 --- src/Gaufrette/Adapter/AsyncAwsS3.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/Gaufrette/Adapter/AsyncAwsS3.php b/src/Gaufrette/Adapter/AsyncAwsS3.php index b8cec1324..a73ba31fd 100644 --- a/src/Gaufrette/Adapter/AsyncAwsS3.php +++ b/src/Gaufrette/Adapter/AsyncAwsS3.php @@ -15,13 +15,12 @@ */ class AsyncAwsS3 implements Adapter, MetadataSupporter, ListKeysAware, SizeCalculator, MimeTypeProvider { - protected SimpleS3Client $service; protected array $options; protected bool $bucketExists; protected array $metadata = []; public function __construct( - SimpleS3Client $service, + private readonly SimpleS3Client $service, private readonly string $bucket, array $options = [], private readonly bool $detectContentType = false @@ -29,7 +28,6 @@ public function __construct( if (!class_exists(SimpleS3Client::class)) { throw new \LogicException('You need to install package "async-aws/simple-s3" to use this adapter'); } - $this->service = $service; $this->options = array_replace( [ 'create' => false, From 79eda31fad197aebe9b93fb0b06a990e3ca2669c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin?= Date: Fri, 21 Apr 2023 16:08:19 +0200 Subject: [PATCH 08/48] Type Flysystem --- src/Gaufrette/Adapter/FileFactory.php | 7 +----- src/Gaufrette/Adapter/Flysystem.php | 35 ++++++++++----------------- 2 files changed, 14 insertions(+), 28 deletions(-) diff --git a/src/Gaufrette/Adapter/FileFactory.php b/src/Gaufrette/Adapter/FileFactory.php index f71be89f0..19faba180 100644 --- a/src/Gaufrette/Adapter/FileFactory.php +++ b/src/Gaufrette/Adapter/FileFactory.php @@ -14,11 +14,6 @@ interface FileFactory { /** * Creates a new File instance and returns it. - * - * @param string $key - * @param Filesystem $filesystem - * - * @return File */ - public function createFile($key, Filesystem $filesystem); + public function createFile(string $key, Filesystem $filesystem): File; } diff --git a/src/Gaufrette/Adapter/Flysystem.php b/src/Gaufrette/Adapter/Flysystem.php index b4038e5ce..cfabad981 100644 --- a/src/Gaufrette/Adapter/Flysystem.php +++ b/src/Gaufrette/Adapter/Flysystem.php @@ -6,37 +6,28 @@ use Gaufrette\Exception\UnsupportedAdapterMethodException; use League\Flysystem\AdapterInterface; use League\Flysystem\Util; +use League\Flysystem\Config; class Flysystem implements Adapter, ListKeysAware { - /** - * @var AdapterInterface - */ - private $adapter; - - /** - * @var Config - */ - private $config; + private Config $config; /** - * @param AdapterInterface $adapter - * @param \League\Flysystem\Config|array|null $config + * @param Config|array|null $config */ - public function __construct(AdapterInterface $adapter, $config = null) + public function __construct(private readonly AdapterInterface $adapter, $config = null) { if (!interface_exists(AdapterInterface::class)) { throw new \LogicException('You need to install package "league/flysystem" to use this adapter'); } - $this->adapter = $adapter; $this->config = Util::ensureConfig($config); } /** * {@inheritdoc} */ - public function read($key) + public function read(string $key): string|bool { return $this->adapter->read($key)['contents']; } @@ -44,7 +35,7 @@ public function read($key) /** * {@inheritdoc} */ - public function write($key, $content) + public function write(string $key, mixed $content): int|bool { return $this->adapter->write($key, $content, $this->config); } @@ -52,7 +43,7 @@ public function write($key, $content) /** * {@inheritdoc} */ - public function exists($key) + public function exists(string $key): bool { return (bool) $this->adapter->has($key); } @@ -60,7 +51,7 @@ public function exists($key) /** * {@inheritdoc} */ - public function keys() + public function keys(): array { return array_map(function ($content) { return $content['path']; @@ -70,7 +61,7 @@ public function keys() /** * {@inheritdoc} */ - public function listKeys($prefix = '') + public function listKeys(string $prefix = ''): array { $dirs = []; $keys = []; @@ -94,7 +85,7 @@ public function listKeys($prefix = '') /** * {@inheritdoc} */ - public function mtime($key) + public function mtime(string $key): int|bool { return $this->adapter->getTimestamp($key); } @@ -102,7 +93,7 @@ public function mtime($key) /** * {@inheritdoc} */ - public function delete($key) + public function delete(string $key): bool { return $this->adapter->delete($key); } @@ -110,7 +101,7 @@ public function delete($key) /** * {@inheritdoc} */ - public function rename($sourceKey, $targetKey) + public function rename(string $sourceKey, string $targetKey): bool { return $this->adapter->rename($sourceKey, $targetKey); } @@ -118,7 +109,7 @@ public function rename($sourceKey, $targetKey) /** * {@inheritdoc} */ - public function isDirectory($key) + public function isDirectory(string $key): bool { throw new UnsupportedAdapterMethodException('isDirectory is not supported by this adapter.'); } From b05376b8edcf977afba67f6b4a85be4d96f80c64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin?= Date: Mon, 24 Apr 2023 15:22:50 +0200 Subject: [PATCH 09/48] Type PhpseclibSftp --- src/Gaufrette/Adapter/PhpseclibSftp.php | 48 ++++++++++++------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/src/Gaufrette/Adapter/PhpseclibSftp.php b/src/Gaufrette/Adapter/PhpseclibSftp.php index 2e71d625c..e16e09010 100644 --- a/src/Gaufrette/Adapter/PhpseclibSftp.php +++ b/src/Gaufrette/Adapter/PhpseclibSftp.php @@ -9,31 +9,27 @@ class PhpseclibSftp implements Adapter, FileFactory, ListKeysAware { - protected $sftp; - protected $directory; - protected $create; - protected $initialized = false; + protected bool $initialized = false; /** - * @param SecLibSFTP $sftp An Sftp instance * @param string $directory The distant directory * @param bool $create Whether to create the remote directory if it * does not exist */ - public function __construct(SecLibSFTP $sftp, $directory = null, $create = false) - { + public function __construct( + private readonly SecLibSFTP $sftp, + private readonly ?string $directory = null, + private readonly bool $create = false + ) { if (!class_exists(SecLibSFTP::class)) { throw new \LogicException('You need to install package "phpseclib/phpseclib" to use this adapter'); } - $this->sftp = $sftp; - $this->directory = $directory; - $this->create = $create; } /** * {@inheritdoc} */ - public function read($key) + public function read(string $key): string|bool { return $this->sftp->get($this->computePath($key)); } @@ -41,7 +37,7 @@ public function read($key) /** * {@inheritdoc} */ - public function rename($sourceKey, $targetKey) + public function rename(string $sourceKey, string $targetKey): bool { $this->initialize(); @@ -56,7 +52,7 @@ public function rename($sourceKey, $targetKey) /** * {@inheritdoc} */ - public function write($key, $content) + public function write(string $key, mixed $content): int|bool { $this->initialize(); @@ -72,7 +68,7 @@ public function write($key, $content) /** * {@inheritdoc} */ - public function exists($key) + public function exists(string $key): bool { $this->initialize(); @@ -82,7 +78,7 @@ public function exists($key) /** * {@inheritdoc} */ - public function isDirectory($key) + public function isDirectory(string $key): bool { $this->initialize(); @@ -99,7 +95,7 @@ public function isDirectory($key) /** * {@inheritdoc} */ - public function keys() + public function keys(): array { $keys = $this->fetchKeys(); @@ -109,7 +105,7 @@ public function keys() /** * {@inheritdoc} */ - public function listKeys($prefix = '') + public function listKeys(string $prefix = ''): array { preg_match('/(.*?)[^\/]*$/', $prefix, $match); $directory = rtrim($match[1], '/'); @@ -136,7 +132,7 @@ public function listKeys($prefix = '') /** * {@inheritdoc} */ - public function mtime($key) + public function mtime(string $key): int|bool { $this->initialize(); @@ -148,7 +144,7 @@ public function mtime($key) /** * {@inheritdoc} */ - public function delete($key) + public function delete(string $key): bool { return $this->sftp->delete($this->computePath($key), false); } @@ -156,7 +152,7 @@ public function delete($key) /** * {@inheritdoc} */ - public function createFile($key, Filesystem $filesystem) + public function createFile(string $key, Filesystem $filesystem): File { $file = new File($key, $filesystem); @@ -173,7 +169,8 @@ public function createFile($key, Filesystem $filesystem) * * It will ensure the root directory exists */ - protected function initialize() + + protected function initialize(): void { if ($this->initialized) { return; @@ -184,7 +181,7 @@ protected function initialize() $this->initialized = true; } - protected function ensureDirectoryExists($directory, $create) + protected function ensureDirectoryExists(string $directory, bool $create) { $pwd = $this->sftp->pwd(); if ($this->sftp->chdir($directory)) { @@ -198,12 +195,15 @@ protected function ensureDirectoryExists($directory, $create) } } - protected function computePath($key) + protected function computePath(string $key): string { return $this->directory . '/' . ltrim($key, '/'); } - protected function fetchKeys($directory = '', $onlyKeys = true) + /** + * @return array> + */ + protected function fetchKeys(string $directory = '', bool $onlyKeys = true): array { $keys = ['keys' => [], 'dirs' => []]; $computedPath = $this->computePath($directory); From 20b44847a6c373798343928fb9c28af2c562569e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin?= Date: Mon, 24 Apr 2023 15:23:02 +0200 Subject: [PATCH 10/48] Type Zip --- src/Gaufrette/Adapter/Zip.php | 39 ++++++++++++----------------------- 1 file changed, 13 insertions(+), 26 deletions(-) diff --git a/src/Gaufrette/Adapter/Zip.php b/src/Gaufrette/Adapter/Zip.php index 4f261f261..2a4b6f691 100644 --- a/src/Gaufrette/Adapter/Zip.php +++ b/src/Gaufrette/Adapter/Zip.php @@ -14,30 +14,21 @@ */ class Zip implements Adapter { - /** - * @var string The zip archive full path - */ - protected $zipFile; + protected ZipArchive $zipArchive; - /** - * @var ZipArchive - */ - protected $zipArchive; - - public function __construct($zipFile) + public function __construct(private readonly string $zipFile) { if (!extension_loaded('zip')) { throw new \RuntimeException(sprintf('Unable to use %s as the ZIP extension is not available.', __CLASS__)); } - $this->zipFile = $zipFile; $this->reinitZipArchive(); } /** * {@inheritdoc} */ - public function read($key) + public function read(string $key): string|bool { if (false === ($content = $this->zipArchive->getFromName($key, 0))) { return false; @@ -49,7 +40,7 @@ public function read($key) /** * {@inheritdoc} */ - public function write($key, $content) + public function write(string $key, mixed $content): int|bool { if (!$this->zipArchive->addFromString($key, $content)) { return false; @@ -65,7 +56,7 @@ public function write($key, $content) /** * {@inheritdoc} */ - public function exists($key) + public function exists(string $key): bool { return (boolean) $this->getStat($key); } @@ -73,7 +64,7 @@ public function exists($key) /** * {@inheritdoc} */ - public function keys() + public function keys(): array { $keys = []; @@ -89,7 +80,7 @@ public function keys() * * {@inheritdoc} */ - public function isDirectory($key) + public function isDirectory(string $key): bool { return false; } @@ -97,7 +88,7 @@ public function isDirectory($key) /** * {@inheritdoc} */ - public function mtime($key) + public function mtime(string $key): int|bool { $stat = $this->getStat($key); @@ -107,7 +98,7 @@ public function mtime($key) /** * {@inheritdoc} */ - public function delete($key) + public function delete(string $key): bool { if (!$this->zipArchive->deleteName($key)) { return false; @@ -119,7 +110,7 @@ public function delete($key) /** * {@inheritdoc} */ - public function rename($sourceKey, $targetKey) + public function rename(string $sourceKey, string $targetKey): bool { if (!$this->zipArchive->renameName($sourceKey, $targetKey)) { return false; @@ -131,12 +122,8 @@ public function rename($sourceKey, $targetKey) /** * Returns the stat of a file in the zip archive * (name, index, crc, mtime, compression size, compression method, filesize). - * - * @param $key - * - * @return array|bool */ - public function getStat($key) + public function getStat(string $key): array { $stat = $this->zipArchive->statName($key); if (false === $stat) { @@ -157,7 +144,7 @@ public function __destruct() } } - protected function reinitZipArchive() + protected function reinitZipArchive(): self { $this->zipArchive = new ZipArchive(); @@ -216,7 +203,7 @@ protected function reinitZipArchive() * * @throws \RuntimeException If file could not be saved */ - protected function save() + protected function save(): bool { // Close to save modification if (!$this->zipArchive->close()) { From f16ad454f8e0426ad6d8f18d4d04310922b9a78a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin?= Date: Mon, 24 Apr 2023 15:37:10 +0200 Subject: [PATCH 11/48] Type GridFS and fix declaration checksum --- src/Gaufrette/Adapter/AzureBlobStorage.php | 2 +- src/Gaufrette/Adapter/ChecksumCalculator.php | 2 +- src/Gaufrette/Adapter/DoctrineDbal.php | 2 +- src/Gaufrette/Adapter/GridFS.php | 37 ++++++++------------ 4 files changed, 18 insertions(+), 25 deletions(-) diff --git a/src/Gaufrette/Adapter/AzureBlobStorage.php b/src/Gaufrette/Adapter/AzureBlobStorage.php index d9d81c329..fe4611a84 100644 --- a/src/Gaufrette/Adapter/AzureBlobStorage.php +++ b/src/Gaufrette/Adapter/AzureBlobStorage.php @@ -304,7 +304,7 @@ public function mimeType(string $key): string /** * {@inheritdoc} */ - public function checksum(string $key): string + public function checksum(string $key): string|bool { $this->init(); list($containerName, $key) = $this->tokenizeKey($key); diff --git a/src/Gaufrette/Adapter/ChecksumCalculator.php b/src/Gaufrette/Adapter/ChecksumCalculator.php index cef02e127..177ac18d5 100644 --- a/src/Gaufrette/Adapter/ChecksumCalculator.php +++ b/src/Gaufrette/Adapter/ChecksumCalculator.php @@ -12,5 +12,5 @@ interface ChecksumCalculator /** * Returns the checksum of the specified key. */ - public function checksum(string $key): string; + public function checksum(string $key): string|bool; } diff --git a/src/Gaufrette/Adapter/DoctrineDbal.php b/src/Gaufrette/Adapter/DoctrineDbal.php index dcb24a2d4..c0495177c 100644 --- a/src/Gaufrette/Adapter/DoctrineDbal.php +++ b/src/Gaufrette/Adapter/DoctrineDbal.php @@ -84,7 +84,7 @@ public function mtime(string $key): int|bool /** * {@inheritdoc} */ - public function checksum(string $key): string + public function checksum(string $key): string|bool { return $this->getColumnValue($key, 'checksum'); } diff --git a/src/Gaufrette/Adapter/GridFS.php b/src/Gaufrette/Adapter/GridFS.php index de9bee6d0..71b47fab2 100644 --- a/src/Gaufrette/Adapter/GridFS.php +++ b/src/Gaufrette/Adapter/GridFS.php @@ -16,27 +16,22 @@ */ class GridFS implements Adapter, ChecksumCalculator, MetadataSupporter, ListKeysAware, SizeCalculator { - /** @var array */ - private $metadata = []; - - /** @var Bucket */ - private $bucket; + private array $metadata = []; /** * @param Bucket $bucket */ - public function __construct(Bucket $bucket) + public function __construct(private readonly Bucket $bucket) { if (!class_exists(Bucket::class)) { throw new \LogicException('You need to install package "mongodb/mongodb" to use this adapter'); } - $this->bucket = $bucket; } /** * {@inheritdoc} */ - public function read($key) + public function read(string $key): string|bool { try { $stream = $this->bucket->openDownloadStreamByName($key); @@ -54,7 +49,7 @@ public function read($key) /** * {@inheritdoc} */ - public function write($key, $content) + public function write(string $key, mixed $content): int|bool { $stream = $this->bucket->openUploadStream($key, ['metadata' => $this->getMetadata($key)]); @@ -63,14 +58,12 @@ public function write($key, $content) } finally { fclose($stream); } - - return false; } /** * {@inheritdoc} */ - public function isDirectory($key) + public function isDirectory(string $key): bool { return false; } @@ -78,7 +71,7 @@ public function isDirectory($key) /** * {@inheritdoc} */ - public function rename($sourceKey, $targetKey) + public function rename(string $sourceKey, string $targetKey): bool { $metadata = $this->getMetadata($sourceKey); $writable = $this->bucket->openUploadStream($targetKey, ['metadata' => $metadata]); @@ -99,7 +92,7 @@ public function rename($sourceKey, $targetKey) /** * {@inheritdoc} */ - public function exists($key) + public function exists(string $key): bool { return (boolean) $this->bucket->findOne(['filename' => $key]); } @@ -107,7 +100,7 @@ public function exists($key) /** * {@inheritdoc} */ - public function keys() + public function keys(): array { $keys = []; $cursor = $this->bucket->find([], ['projection' => ['filename' => 1]]); @@ -122,7 +115,7 @@ public function keys() /** * {@inheritdoc} */ - public function mtime($key) + public function mtime(string $key): int|bool { $file = $this->bucket->findOne(['filename' => $key], ['projection' => ['uploadDate' => 1]]); @@ -132,7 +125,7 @@ public function mtime($key) /** * {@inheritdoc} */ - public function checksum($key) + public function checksum(string $key): string|bool { $file = $this->bucket->findOne(['filename' => $key], ['projection' => ['md5' => 1]]); @@ -142,7 +135,7 @@ public function checksum($key) /** * {@inheritdoc} */ - public function delete($key) + public function delete(string $key): bool { if (null === $file = $this->bucket->findOne(['filename' => $key], ['projection' => ['_id' => 1]])) { return false; @@ -156,7 +149,7 @@ public function delete($key) /** * {@inheritdoc} */ - public function setMetadata($key, $metadata) + public function setMetadata(string $key, array $metadata): void { $this->metadata[$key] = $metadata; } @@ -164,7 +157,7 @@ public function setMetadata($key, $metadata) /** * {@inheritdoc} */ - public function getMetadata($key) + public function getMetadata(string $key): array { if (isset($this->metadata[$key])) { return $this->metadata[$key]; @@ -183,7 +176,7 @@ public function getMetadata($key) /** * {@inheritdoc} */ - public function listKeys($prefix = '') + public function listKeys(string $prefix = ''): array { $prefix = trim($prefix); @@ -208,7 +201,7 @@ public function listKeys($prefix = '') return $result; } - public function size($key) + public function size(string $key): int { if (!$this->exists($key)) { return false; From 1a9a23df2dad96aa643b1c9f62dbe226d346c1ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin?= Date: Fri, 2 Jun 2023 15:04:06 +0200 Subject: [PATCH 12/48] fix muchafm review --- src/Gaufrette/Adapter/AsyncAwsS3.php | 18 ++++++++++++++---- src/Gaufrette/Adapter/AwsS3.php | 8 ++++++-- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/Gaufrette/Adapter/AsyncAwsS3.php b/src/Gaufrette/Adapter/AsyncAwsS3.php index a73ba31fd..972cdf38d 100644 --- a/src/Gaufrette/Adapter/AsyncAwsS3.php +++ b/src/Gaufrette/Adapter/AsyncAwsS3.php @@ -15,19 +15,27 @@ */ class AsyncAwsS3 implements Adapter, MetadataSupporter, ListKeysAware, SizeCalculator, MimeTypeProvider { + protected SimpleS3Client $service; + protected string $bucket; protected array $options; protected bool $bucketExists; protected array $metadata = []; + protected bool $detectContentType; + public function __construct( - private readonly SimpleS3Client $service, - private readonly string $bucket, + SimpleS3Client $service, + string $bucket, array $options = [], - private readonly bool $detectContentType = false + bool $detectContentType = false ) { if (!class_exists(SimpleS3Client::class)) { throw new \LogicException('You need to install package "async-aws/simple-s3" to use this adapter'); } + + $this->service = $service; + $this->bucket = $bucket; + $this->options = array_replace( [ 'create' => false, @@ -36,6 +44,8 @@ public function __construct( ], $options ); + + $this->detectContentType = $detectContentType; } /** @@ -304,7 +314,7 @@ protected function computeKey(string $path): string return ltrim(substr($path, strlen($this->options['directory'])), '/'); } - private function guessContentType(mixed $content): false|string + private function guessContentType(mixed $content): bool|string { $fileInfo = new \finfo(FILEINFO_MIME_TYPE); diff --git a/src/Gaufrette/Adapter/AwsS3.php b/src/Gaufrette/Adapter/AwsS3.php index 6ff0bbf6f..d6e5074f3 100644 --- a/src/Gaufrette/Adapter/AwsS3.php +++ b/src/Gaufrette/Adapter/AwsS3.php @@ -14,20 +14,23 @@ class AwsS3 implements Adapter, MetadataSupporter, ListKeysAware, SizeCalculator, MimeTypeProvider { protected S3Client $service; + protected string $bucket; protected array $options; protected bool $bucketExists; protected array $metadata = []; + protected bool $detectContentType; public function __construct( S3Client $service, - private readonly string $bucket, + string $bucket, array $options = [], - private readonly bool $detectContentType = false + bool $detectContentType = false ) { if (!class_exists(S3Client::class)) { throw new \LogicException('You need to install package "aws/aws-sdk-php" to use this adapter'); } $this->service = $service; + $this->bucket = $bucket; $this->options = array_replace( [ 'create' => false, @@ -36,6 +39,7 @@ public function __construct( ], $options ); + $this->detectContentType = $detectContentType; } /** From a6487f337ebf3cd09a5d45fe54064da5c73b43ed Mon Sep 17 00:00:00 2001 From: Sophie Roussel Date: Mon, 24 Apr 2023 15:55:32 +0200 Subject: [PATCH 13/48] refacto: add types on adapter --- .../AzureBlobStorage/BlobProxyFactory.php | 15 +-- src/Gaufrette/Adapter/Ftp.php | 102 +++++++----------- src/Gaufrette/Adapter/GoogleCloudStorage.php | 83 ++++++-------- src/Gaufrette/Adapter/InMemory.php | 53 +++------ src/Gaufrette/Adapter/Local.php | 74 +++++-------- src/Gaufrette/Adapter/SafeLocal.php | 10 +- src/Gaufrette/Adapter/StreamFactory.php | 8 +- 7 files changed, 123 insertions(+), 222 deletions(-) diff --git a/src/Gaufrette/Adapter/AzureBlobStorage/BlobProxyFactory.php b/src/Gaufrette/Adapter/AzureBlobStorage/BlobProxyFactory.php index 441efae4e..e22e3bf2e 100644 --- a/src/Gaufrette/Adapter/AzureBlobStorage/BlobProxyFactory.php +++ b/src/Gaufrette/Adapter/AzureBlobStorage/BlobProxyFactory.php @@ -12,15 +12,9 @@ */ class BlobProxyFactory implements BlobProxyFactoryInterface { - /** - * @var string - */ - protected $connectionString; + protected string $connectionString; - /** - * @param string $connectionString - */ - public function __construct($connectionString) + public function __construct(string $connectionString) { if (!class_exists(ServicesBuilder::class) && !class_exists(BlobRestProxy::class)) { throw new \LogicException('You need to install package "microsoft/azure-storage-blob" to use this adapter'); @@ -28,10 +22,7 @@ public function __construct($connectionString) $this->connectionString = $connectionString; } - /** - * {@inheritdoc} - */ - public function create() + public function create(): BlobRestProxy { if (class_exists(ServicesBuilder::class)) { // for microsoft/azure-storage < 1.0 diff --git a/src/Gaufrette/Adapter/Ftp.php b/src/Gaufrette/Adapter/Ftp.php index 8ea3bb141..50dff1a16 100644 --- a/src/Gaufrette/Adapter/Ftp.php +++ b/src/Gaufrette/Adapter/Ftp.php @@ -15,25 +15,25 @@ class Ftp implements Adapter, FileFactory, ListKeysAware, SizeCalculator { /** @var null|resource|\FTP\Connection */ protected $connection = null; - protected $directory; - protected $host; - protected $port; - protected $username; - protected $password; - protected $passive; - protected $create; - protected $mode; - protected $ssl; - protected $timeout; - protected $fileData = []; - protected $utf8; + protected string $directory; + protected string $host; + protected mixed $port; + protected mixed $username; + protected mixed $password; + protected mixed $passive; + protected mixed $create; + protected mixed $mode; + protected mixed $ssl; + protected mixed $timeout; + protected array $fileData; + protected mixed $utf8; /** * @param string $directory The directory to use in the ftp server * @param string $host The host of the ftp server - * @param array $options The options like port, username, password, passive, create, mode + * @param array $options The options like port, username, password, passive, create, mode */ - public function __construct($directory, $host, $options = []) + public function __construct(string $directory, string $host, array $options = []) { if (!extension_loaded('ftp')) { throw new \RuntimeException('Unable to use Gaufrette\Adapter\Ftp as the FTP extension is not available.'); @@ -52,10 +52,7 @@ public function __construct($directory, $host, $options = []) $this->utf8 = $options['utf8'] ?? false; } - /** - * {@inheritdoc} - */ - public function read($key) + public function read(string $key): string|bool { $this->ensureDirectoryExists($this->directory, $this->create); @@ -72,10 +69,7 @@ public function read($key) return $contents; } - /** - * {@inheritdoc} - */ - public function write($key, $content) + public function write(string $key, mixed $content): int|bool { $this->ensureDirectoryExists($this->directory, $this->create); @@ -99,10 +93,7 @@ public function write($key, $content) return $size; } - /** - * {@inheritdoc} - */ - public function rename($sourceKey, $targetKey) + public function rename(string $sourceKey, string $targetKey): bool { $this->ensureDirectoryExists($this->directory, $this->create); @@ -114,10 +105,7 @@ public function rename($sourceKey, $targetKey) return ftp_rename($this->getConnection(), $sourcePath, $targetPath); } - /** - * {@inheritdoc} - */ - public function exists($key) + public function exists(string $key): bool { $this->ensureDirectoryExists($this->directory, $this->create); @@ -139,9 +127,10 @@ public function exists($key) } /** - * {@inheritdoc} + * + * @return array */ - public function keys() + public function keys(): array { $this->ensureDirectoryExists($this->directory, $this->create); @@ -150,10 +139,7 @@ public function keys() return $keys['keys']; } - /** - * {@inheritdoc} - */ - public function listKeys($prefix = '') + public function listKeys(string $prefix = ''): array { $this->ensureDirectoryExists($this->directory, $this->create); @@ -179,10 +165,7 @@ public function listKeys($prefix = '') return $filteredKeys; } - /** - * {@inheritdoc} - */ - public function mtime($key) + public function mtime(string $key): int|bool { $this->ensureDirectoryExists($this->directory, $this->create); @@ -196,10 +179,7 @@ public function mtime($key) return $mtime; } - /** - * {@inheritdoc} - */ - public function delete($key) + public function delete(string $key): bool { $this->ensureDirectoryExists($this->directory, $this->create); @@ -210,10 +190,7 @@ public function delete($key) return ftp_delete($this->getConnection(), $this->computePath($key)); } - /** - * {@inheritdoc} - */ - public function isDirectory($key) + public function isDirectory(string $key): bool { $this->ensureDirectoryExists($this->directory, $this->create); @@ -228,7 +205,7 @@ public function isDirectory($key) * * @return array An array of keys and dirs */ - public function listDirectory($directory = '') + public function listDirectory(string $directory = ''): array { $this->ensureDirectoryExists($this->directory, $this->create); @@ -266,10 +243,7 @@ public function listDirectory($directory = '') ]; } - /** - * {@inheritdoc} - */ - public function createFile($key, Filesystem $filesystem) + public function createFile(mixed $key, Filesystem $filesystem): \Gaufrette\File { $this->ensureDirectoryExists($this->directory, $this->create); @@ -298,7 +272,7 @@ public function createFile($key, Filesystem $filesystem) * * @throws \RuntimeException */ - public function size($key) + public function size(string $key): int { $this->ensureDirectoryExists($this->directory, $this->create); @@ -320,7 +294,7 @@ public function size($key) * @throws RuntimeException if the directory does not exist and could not * be created */ - protected function ensureDirectoryExists($directory, $create = false) + protected function ensureDirectoryExists(string $directory, bool $create = false): void { if (!$this->isDir($directory)) { if (!$create) { @@ -338,7 +312,7 @@ protected function ensureDirectoryExists($directory, $create = false) * * @throws RuntimeException if the directory could not be created */ - protected function createDirectory($directory) + protected function createDirectory(string $directory): void { // create parent directory if needed $parent = \Gaufrette\Util\Path::dirname($directory); @@ -358,7 +332,7 @@ protected function createDirectory($directory) * * @return bool */ - private function isDir($directory) + private function isDir(string $directory): bool { if ('/' === $directory) { return true; @@ -374,7 +348,7 @@ private function isDir($directory) return true; } - private function fetchKeys($directory = '', $onlyKeys = true) + private function fetchKeys(string $directory = '', bool $onlyKeys = true): array { $directory = preg_replace('/^[\/]*([^\/].*)$/', '/$1', $directory); @@ -441,7 +415,7 @@ private function fetchKeys($directory = '', $onlyKeys = true) * * @return array */ - private function parseRawlist(array $rawlist) + private function parseRawlist(array $rawlist): array { $parsed = []; foreach ($rawlist as $line) { @@ -478,7 +452,7 @@ private function parseRawlist(array $rawlist) * * @param string $key */ - private function computePath($key) + private function computePath(string $key) { return rtrim($this->directory, '/') . '/' . $key; } @@ -488,7 +462,7 @@ private function computePath($key) * * @return bool */ - private function isConnected() + private function isConnected(): bool { if (class_exists('\FTP\Connection')) { return $this->connection instanceof \FTP\Connection; @@ -517,7 +491,7 @@ private function getConnection() * * @throws RuntimeException if could not connect */ - private function connect() + private function connect(): void { if ($this->ssl && !function_exists('ftp_ssl_connect')) { throw new \RuntimeException('This Server Has No SSL-FTP Available.'); @@ -582,14 +556,14 @@ private function connect() /** * Closes the adapter's ftp connection. */ - public function close() + public function close(): void { if ($this->isConnected()) { ftp_close($this->connection); } } - private function isLinuxListing($info) + private function isLinuxListing(mixed $info): bool { return count($info) >= 9; } diff --git a/src/Gaufrette/Adapter/GoogleCloudStorage.php b/src/Gaufrette/Adapter/GoogleCloudStorage.php index 295dcad14..a5f1f2cfb 100644 --- a/src/Gaufrette/Adapter/GoogleCloudStorage.php +++ b/src/Gaufrette/Adapter/GoogleCloudStorage.php @@ -10,6 +10,8 @@ use Google\Service\Storage\BucketIamConfiguration; use Google\Service\Storage\BucketIamConfigurationUniformBucketLevelAccess; use GuzzleHttp; +use RuntimeException; +use ReflectionException; /** * Google Cloud Storage adapter using the Google APIs Client Library for PHP. @@ -44,9 +46,9 @@ class GoogleCloudStorage implements Adapter, MetadataSupporter, ListKeysAware */ public function __construct( Storage $service, - $bucket, + string $bucket, array $options = [], - $detectContentType = false + bool $detectContentType = false ) { if (!class_exists(Storage::class)) { throw new \LogicException('You need to install package "google/apiclient" to use this adapter'); @@ -63,17 +65,17 @@ public function __construct( } /** - * @return array The actual options + * @return array The actual options */ - public function getOptions() + public function getOptions(): array { return $this->options; } /** - * @param array $options The new options + * @param array $options The new options */ - public function setOptions($options) + public function setOptions(array $options): void { $this->options = array_replace($this->options, $options); } @@ -81,7 +83,7 @@ public function setOptions($options) /** * @return string The current bucket name */ - public function getBucket() + public function getBucket(): string { return $this->bucket; } @@ -91,16 +93,13 @@ public function getBucket() * * @param string $bucket The new bucket name */ - public function setBucket($bucket) + public function setBucket(string $bucket): void { $this->bucketExists = null; $this->bucket = $bucket; } - /** - * {@inheritdoc} - */ - public function read($key) + public function read(string $key): string|bool { $this->ensureBucketExists(); $path = $this->computePath($key); @@ -133,10 +132,7 @@ public function read($key) return false; } - /** - * {@inheritdoc} - */ - public function write($key, $content) + public function write(string $key, mixed $content): int|bool { $this->ensureBucketExists(); $path = $this->computePath($key); @@ -201,10 +197,7 @@ public function write($key, $content) } } - /** - * {@inheritdoc} - */ - public function exists($key) + public function exists(string $key): bool { $this->ensureBucketExists(); $path = $this->computePath($key); @@ -219,17 +212,16 @@ public function exists($key) } /** - * {@inheritdoc} + * @return array + * @throws RuntimeException + * @throws ReflectionException */ - public function keys() + public function keys(): array { return $this->listKeys(); } - /** - * {@inheritdoc} - */ - public function mtime($key) + public function mtime(string $key): int|bool { $this->ensureBucketExists(); $path = $this->computePath($key); @@ -239,10 +231,7 @@ public function mtime($key) return $object ? strtotime($object->getUpdated()) : false; } - /** - * {@inheritdoc} - */ - public function delete($key) + public function delete(string $key): bool { $this->ensureBucketExists(); $path = $this->computePath($key); @@ -256,10 +245,7 @@ public function delete($key) return true; } - /** - * {@inheritdoc} - */ - public function rename($sourceKey, $targetKey) + public function rename(string $sourceKey, string $targetKey): bool { $this->ensureBucketExists(); $sourcePath = $this->computePath($sourceKey); @@ -280,10 +266,7 @@ public function rename($sourceKey, $targetKey) return true; } - /** - * {@inheritdoc} - */ - public function isDirectory($key) + public function isDirectory(string $key): bool { if ($this->exists($key . '/')) { return true; @@ -293,9 +276,11 @@ public function isDirectory($key) } /** - * {@inheritdoc} + * @return array + * @throws RuntimeException + * @throws ReflectionException */ - public function listKeys($prefix = '') + public function listKeys(string $prefix = ''): array { $this->ensureBucketExists(); @@ -326,9 +311,9 @@ public function listKeys($prefix = '') } /** - * {@inheritdoc} + * @param array $content */ - public function setMetadata($key, $content) + public function setMetadata(string $key, array $content): void { $path = $this->computePath($key); @@ -336,9 +321,9 @@ public function setMetadata($key, $content) } /** - * {@inheritdoc} + * @return array */ - public function getMetadata($key) + public function getMetadata(string $key): array { $path = $this->computePath($key); @@ -350,7 +335,7 @@ public function getMetadata($key) * * @throws \RuntimeException if the bucket does not exists */ - protected function ensureBucketExists() + protected function ensureBucketExists(): void { if ($this->bucketExists) { return; @@ -405,7 +390,7 @@ protected function ensureBucketExists() } } - protected function computePath($key) + protected function computePath(string $key): string { if (empty($this->options['directory'])) { return $key; @@ -416,11 +401,11 @@ protected function computePath($key) /** * @param string $path - * @param array $options + * @param array $options * * @return bool|StorageObject */ - private function getObjectData($path, $options = []) + private function getObjectData(string $path, array $options = []) { try { return $this->service->objects->get($this->bucket, $path, $options); @@ -434,7 +419,7 @@ private function getObjectData($path, $options = []) * * @return string */ - private function guessContentType($content) + private function guessContentType(string $content): string { $fileInfo = new \finfo(FILEINFO_MIME_TYPE); diff --git a/src/Gaufrette/Adapter/InMemory.php b/src/Gaufrette/Adapter/InMemory.php index b58cdcb42..53a7cb88d 100644 --- a/src/Gaufrette/Adapter/InMemory.php +++ b/src/Gaufrette/Adapter/InMemory.php @@ -14,10 +14,10 @@ */ class InMemory implements Adapter, MimeTypeProvider { - protected $files = []; + protected array $files = []; /** - * @param array $files An array of files + * @param array $files An array of files */ public function __construct(array $files = []) { @@ -27,9 +27,9 @@ public function __construct(array $files = []) /** * Defines the files. * - * @param array $files An array of files + * @param array $files An array of files */ - public function setFiles(array $files) + public function setFiles(array $files): void { $this->files = []; foreach ($files as $key => $file) { @@ -53,7 +53,7 @@ public function setFiles(array $files) * @param string $content The content * @param int $mtime The last modified time (automatically set to now if NULL) */ - public function setFile($key, $content = null, $mtime = null) + public function setFile(string $key, string $content = null, int $mtime = null): void { if (null === $mtime) { $mtime = time(); @@ -65,18 +65,12 @@ public function setFile($key, $content = null, $mtime = null) ]; } - /** - * {@inheritdoc} - */ - public function read($key) + public function read(string $key): string|bool { return $this->files[$key]['content']; } - /** - * {@inheritdoc} - */ - public function rename($sourceKey, $targetKey) + public function rename(string $sourceKey, mixed $targetKey): bool { $content = $this->read($sourceKey); $this->delete($sourceKey); @@ -85,9 +79,9 @@ public function rename($sourceKey, $targetKey) } /** - * {@inheritdoc} + * @param ?array $metadata */ - public function write($key, $content, array $metadata = null) + public function write(string $key, mixed $content, array $metadata = null): int|bool { $this->files[$key]['content'] = $content; $this->files[$key]['mtime'] = time(); @@ -95,34 +89,25 @@ public function write($key, $content, array $metadata = null) return Util\Size::fromContent($content); } - /** - * {@inheritdoc} - */ - public function exists($key) + public function exists(string $key): bool { return array_key_exists($key, $this->files); } /** - * {@inheritdoc} + * @return array */ - public function keys() + public function keys(): array { return array_keys($this->files); } - /** - * {@inheritdoc} - */ - public function mtime($key) + public function mtime(string $key): int|bool { return $this->files[$key]['mtime'] ?? false; } - /** - * {@inheritdoc} - */ - public function delete($key) + public function delete(string $key): bool { unset($this->files[$key]); clearstatcache(); @@ -130,18 +115,12 @@ public function delete($key) return true; } - /** - * {@inheritdoc} - */ - public function isDirectory($path) + public function isDirectory(string $path): bool { return false; } - /** - * {@inheritdoc} - */ - public function mimeType($key) + public function mimeType(string $key): string { $fileInfo = new \finfo(FILEINFO_MIME_TYPE); diff --git a/src/Gaufrette/Adapter/Local.php b/src/Gaufrette/Adapter/Local.php index 81b253f8a..6bfba27f8 100644 --- a/src/Gaufrette/Adapter/Local.php +++ b/src/Gaufrette/Adapter/Local.php @@ -14,10 +14,9 @@ */ class Local implements Adapter, StreamFactory, ChecksumCalculator, SizeCalculator, MimeTypeProvider { - protected $directory; - private $create; - private $mode; - + protected string $directory; + private bool $create; + private int $mode; /** * @param string $directory Directory where the filesystem is located * @param bool $create Whether to create the directory if it does not @@ -27,8 +26,11 @@ class Local implements Adapter, StreamFactory, ChecksumCalculator, SizeCalculato * @throws \RuntimeException if the specified directory does not exist and * could not be created */ - public function __construct($directory, $create = false, $mode = 0777) - { + public function __construct( + string $directory, + bool $create = false, + int $mode = 0777 + ){ $this->directory = Util\Path::normalize($directory); if (is_link($this->directory)) { @@ -40,13 +42,11 @@ public function __construct($directory, $create = false, $mode = 0777) } /** - * {@inheritdoc} - * * @throws \OutOfBoundsException If the computed path is out of the directory * @throws \InvalidArgumentException if the directory already exists * @throws \RuntimeException if the directory could not be created */ - public function read($key) + public function read(string $key): string|bool { if ($this->isDirectory($key)) { return false; @@ -56,13 +56,11 @@ public function read($key) } /** - * {@inheritdoc} - * * @throws \OutOfBoundsException If the computed path is out of the directory * @throws \InvalidArgumentException if the directory already exists * @throws \RuntimeException if the directory could not be created */ - public function write($key, $content) + public function write(string $key, mixed $content): int|bool { $path = $this->computePath($key); $this->ensureDirectoryExists(\Gaufrette\Util\Path::dirname($path), true); @@ -71,13 +69,11 @@ public function write($key, $content) } /** - * {@inheritdoc} - * * @throws \OutOfBoundsException If the computed path is out of the directory * @throws \InvalidArgumentException if the directory already exists * @throws \RuntimeException if the directory could not be created */ - public function rename($sourceKey, $targetKey) + public function rename(string $sourceKey, string $targetKey): bool { $targetPath = $this->computePath($targetKey); $this->ensureDirectoryExists(\Gaufrette\Util\Path::dirname($targetPath), true); @@ -85,22 +81,18 @@ public function rename($sourceKey, $targetKey) return rename($this->computePath($sourceKey), $targetPath); } - /** - * {@inheritdoc} - */ - public function exists($key) + public function exists(string $key): bool { return is_file($this->computePath($key)); } /** - * {@inheritdoc} - * + * @return array * @throws \OutOfBoundsException If the computed path is out of the directory * @throws \InvalidArgumentException if the directory already exists * @throws \RuntimeException if the directory could not be created */ - public function keys() + public function keys(): array { $this->ensureDirectoryExists($this->directory, $this->create); @@ -126,24 +118,20 @@ public function keys() } /** - * {@inheritdoc} - * * @throws \OutOfBoundsException If the computed path is out of the directory * @throws \InvalidArgumentException if the directory already exists * @throws \RuntimeException if the directory could not be created */ - public function mtime($key) + public function mtime(string $key): int|bool { return filemtime($this->computePath($key)); } /** - * {@inheritdoc} - * * Can also delete a directory recursively when the given $key matches a * directory. */ - public function delete($key) + public function delete(string $key): bool { if ($this->isDirectory($key)) { return $this->deleteDirectory($this->computePath($key)); @@ -163,55 +151,47 @@ public function delete($key) * @throws \InvalidArgumentException if the directory already exists * @throws \RuntimeException if the directory could not be created */ - public function isDirectory($key) + public function isDirectory(string $key): bool { return is_dir($this->computePath($key)); } /** - * {@inheritdoc} - * * @throws \OutOfBoundsException If the computed path is out of the directory * @throws \InvalidArgumentException if the directory already exists * @throws \RuntimeException if the directory could not be created */ - public function createStream($key) + public function createStream(string $key): Stream\Local { return new Stream\Local($this->computePath($key), $this->mode); } /** - * {@inheritdoc} - * * @throws \OutOfBoundsException If the computed path is out of the directory * @throws \InvalidArgumentException if the directory already exists * @throws \RuntimeException if the directory could not be created */ - public function checksum($key) + public function checksum(string $key): string|bool { return Util\Checksum::fromFile($this->computePath($key)); } /** - * {@inheritdoc} - * * @throws \OutOfBoundsException If the computed path is out of the directory * @throws \InvalidArgumentException if the directory already exists * @throws \RuntimeException if the directory could not be created */ - public function size($key) + public function size(string $key): int { return Util\Size::fromFile($this->computePath($key)); } /** - * {@inheritdoc} - * * @throws \OutOfBoundsException If the computed path is out of the directory * @throws \InvalidArgumentException if the directory already exists * @throws \RuntimeException if the directory could not be created */ - public function mimeType($key) + public function mimeType(string $key): string { $fileInfo = new \finfo(FILEINFO_MIME_TYPE); @@ -228,7 +208,7 @@ public function mimeType($key) * @throws \InvalidArgumentException if the directory already exists * @throws \RuntimeException if the directory could not be created */ - public function computeKey($path) + public function computeKey(string $path): string { $path = $this->normalizePath($path); @@ -246,7 +226,7 @@ public function computeKey($path) * @throws \OutOfBoundsException If the computed path is out of the directory * @throws \RuntimeException If directory does not exists and cannot be created */ - protected function computePath($key) + protected function computePath(string $key): string { $this->ensureDirectoryExists($this->directory, $this->create); @@ -262,7 +242,7 @@ protected function computePath($key) * @throws \OutOfBoundsException If the computed path is out of the * directory */ - protected function normalizePath($path) + protected function normalizePath(string $path): string { $path = Util\Path::normalize($path); @@ -284,7 +264,7 @@ protected function normalizePath($path) * @throws \RuntimeException if the directory does not exists and could not * be created */ - protected function ensureDirectoryExists($directory, $create = false) + protected function ensureDirectoryExists(string $directory, bool $create = false): void { if (!is_dir($directory)) { if (!$create) { @@ -303,7 +283,7 @@ protected function ensureDirectoryExists($directory, $create = false) * @throws \InvalidArgumentException if the directory already exists * @throws \RuntimeException if the directory could not be created */ - protected function createDirectory($directory) + protected function createDirectory(string $directory): void { if (!@mkdir($directory, $this->mode, true) && !is_dir($directory)) { throw new \RuntimeException(sprintf('The directory \'%s\' could not be created.', $directory)); @@ -318,7 +298,7 @@ protected function createDirectory($directory) * * @return bool Wheter the operation succeeded or not */ - private function deleteDirectory($directory) + private function deleteDirectory(string $directory): bool { if ($this->directory === $directory) { throw new \InvalidArgumentException( diff --git a/src/Gaufrette/Adapter/SafeLocal.php b/src/Gaufrette/Adapter/SafeLocal.php index 9c3dc6570..d709e36b6 100644 --- a/src/Gaufrette/Adapter/SafeLocal.php +++ b/src/Gaufrette/Adapter/SafeLocal.php @@ -10,18 +10,12 @@ */ class SafeLocal extends Local { - /** - * {@inheritdoc} - */ - public function computeKey($path) + public function computeKey(string $path): string { return base64_decode(parent::computeKey($path)); } - /** - * {@inheritdoc} - */ - protected function computePath($key) + protected function computePath(string $key): string { return parent::computePath(base64_encode($key)); } diff --git a/src/Gaufrette/Adapter/StreamFactory.php b/src/Gaufrette/Adapter/StreamFactory.php index bbf8f21bd..85ce4e6f8 100644 --- a/src/Gaufrette/Adapter/StreamFactory.php +++ b/src/Gaufrette/Adapter/StreamFactory.php @@ -2,6 +2,8 @@ namespace Gaufrette\Adapter; +use Gaufrette\Stream; + /** * Interface for the stream creation class. * @@ -11,10 +13,6 @@ interface StreamFactory { /** * Creates a new stream instance of the specified file. - * - * @param string $key - * - * @return \Gaufrette\Stream */ - public function createStream($key); + public function createStream(string $key): Stream; } From 7a1b35c7fd0c958a20ba8e2c37a0f4e0b13ef580 Mon Sep 17 00:00:00 2001 From: Sophie Roussel Date: Fri, 26 May 2023 15:40:32 +0200 Subject: [PATCH 14/48] fix: review --- src/Gaufrette/Adapter/Ftp.php | 10 ++++++---- src/Gaufrette/Adapter/GoogleCloudStorage.php | 4 +--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Gaufrette/Adapter/Ftp.php b/src/Gaufrette/Adapter/Ftp.php index 50dff1a16..763f05356 100644 --- a/src/Gaufrette/Adapter/Ftp.php +++ b/src/Gaufrette/Adapter/Ftp.php @@ -127,8 +127,7 @@ public function exists(string $key): bool } /** - * - * @return array + * {@inheritdoc} */ public function keys(): array { @@ -243,7 +242,7 @@ public function listDirectory(string $directory = ''): array ]; } - public function createFile(mixed $key, Filesystem $filesystem): \Gaufrette\File + public function createFile(mixed $key, Filesystem $filesystem): File { $this->ensureDirectoryExists($this->directory, $this->create); @@ -563,7 +562,10 @@ public function close(): void } } - private function isLinuxListing(mixed $info): bool + /** + * @param array|false $info + */ + private function isLinuxListing(array $info): bool { return count($info) >= 9; } diff --git a/src/Gaufrette/Adapter/GoogleCloudStorage.php b/src/Gaufrette/Adapter/GoogleCloudStorage.php index a5f1f2cfb..cb72880c1 100644 --- a/src/Gaufrette/Adapter/GoogleCloudStorage.php +++ b/src/Gaufrette/Adapter/GoogleCloudStorage.php @@ -212,9 +212,7 @@ public function exists(string $key): bool } /** - * @return array - * @throws RuntimeException - * @throws ReflectionException + * @{inheritdoc} */ public function keys(): array { From 7bf16a89e42534b718debdbfaadc721284071b40 Mon Sep 17 00:00:00 2001 From: Sophie Roussel Date: Fri, 2 Jun 2023 16:00:29 +0200 Subject: [PATCH 15/48] fix: review --- src/Gaufrette/Adapter/Ftp.php | 8 ++------ src/Gaufrette/Adapter/GoogleCloudStorage.php | 11 ++--------- src/Gaufrette/Adapter/Local.php | 6 +----- 3 files changed, 5 insertions(+), 20 deletions(-) diff --git a/src/Gaufrette/Adapter/Ftp.php b/src/Gaufrette/Adapter/Ftp.php index 763f05356..3c420b29e 100644 --- a/src/Gaufrette/Adapter/Ftp.php +++ b/src/Gaufrette/Adapter/Ftp.php @@ -410,9 +410,9 @@ private function fetchKeys(string $directory = '', bool $onlyKeys = true): array /** * Parses the given raw list. * - * @param array $rawlist + * @param array $rawlist * - * @return array + * @return array */ private function parseRawlist(array $rawlist): array { @@ -448,8 +448,6 @@ private function parseRawlist(array $rawlist): array /** * Computes the path for the given key. - * - * @param string $key */ private function computePath(string $key) { @@ -458,8 +456,6 @@ private function computePath(string $key) /** * Indicates whether the adapter has an open ftp connection. - * - * @return bool */ private function isConnected(): bool { diff --git a/src/Gaufrette/Adapter/GoogleCloudStorage.php b/src/Gaufrette/Adapter/GoogleCloudStorage.php index cb72880c1..d775926dd 100644 --- a/src/Gaufrette/Adapter/GoogleCloudStorage.php +++ b/src/Gaufrette/Adapter/GoogleCloudStorage.php @@ -80,9 +80,6 @@ public function setOptions(array $options): void $this->options = array_replace($this->options, $options); } - /** - * @return string The current bucket name - */ public function getBucket(): string { return $this->bucket; @@ -90,8 +87,6 @@ public function getBucket(): string /** * Sets a new bucket name. - * - * @param string $bucket The new bucket name */ public function setBucket(string $bucket): void { @@ -212,7 +207,7 @@ public function exists(string $key): bool } /** - * @{inheritdoc} + * {@inheritdoc} */ public function keys(): array { @@ -400,10 +395,8 @@ protected function computePath(string $key): string /** * @param string $path * @param array $options - * - * @return bool|StorageObject */ - private function getObjectData(string $path, array $options = []) + private function getObjectData(string $path, array $options = []): bool|StorageObject { try { return $this->service->objects->get($this->bucket, $path, $options); diff --git a/src/Gaufrette/Adapter/Local.php b/src/Gaufrette/Adapter/Local.php index 6bfba27f8..89eb51b82 100644 --- a/src/Gaufrette/Adapter/Local.php +++ b/src/Gaufrette/Adapter/Local.php @@ -143,10 +143,6 @@ public function delete(string $key): bool } /** - * @param string $key - * - * @return bool - * * @throws \OutOfBoundsException If the computed path is out of the directory * @throws \InvalidArgumentException if the directory already exists * @throws \RuntimeException if the directory could not be created @@ -296,7 +292,7 @@ protected function createDirectory(string $directory): void * @throws \InvalidArgumentException When attempting to delete the root * directory of this adapter. * - * @return bool Wheter the operation succeeded or not + * @return bool Whether the operation succeeded or not */ private function deleteDirectory(string $directory): bool { From aecd1fae0ff3147b7dfd808ffd864cac17a8f60b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin?= Date: Mon, 24 Apr 2023 16:31:58 +0200 Subject: [PATCH 16/48] Refacto: Add type on Stream classes --- src/Gaufrette/Stream.php | 41 +++++---------- src/Gaufrette/Stream/InMemoryBuffer.php | 56 ++++++++------------ src/Gaufrette/Stream/Local.php | 68 +++++++------------------ 3 files changed, 52 insertions(+), 113 deletions(-) diff --git a/src/Gaufrette/Stream.php b/src/Gaufrette/Stream.php index 7f640b80d..b016e0547 100644 --- a/src/Gaufrette/Stream.php +++ b/src/Gaufrette/Stream.php @@ -16,7 +16,7 @@ interface Stream * * @return bool TRUE on success or FALSE on failure */ - public function open(StreamMode $mode); + public function open(StreamMode $mode): bool; /** * Reads the specified number of bytes from the current position. @@ -25,10 +25,8 @@ public function open(StreamMode $mode); * string. * * @param int $count The number of bytes - * - * @return string */ - public function read($count); + public function read(int $count): string|false; /** * Writes the specified data. @@ -36,11 +34,9 @@ public function read($count); * Don't forget to update the current position of the stream by number of * bytes that were successfully written. * - * @param string $data - * * @return int The number of bytes that were successfully written */ - public function write($data); + public function write(string $data): int; /** * Closes the stream. @@ -48,7 +44,7 @@ public function write($data); * It must free all the resources. If there is any data to flush, you * should do so */ - public function close(); + public function close(): void; /** * Flushes the output. @@ -58,52 +54,41 @@ public function close(); * * @return bool TRUE on success or FALSE on failure */ - public function flush(); + public function flush(): bool; /** * Seeks to the specified offset. - * - * @param int $offset - * @param int $whence - * - * @return bool */ - public function seek($offset, $whence = SEEK_SET); + public function seek(int $offset, int $whence = SEEK_SET): bool; /** * Returns the current position. - * - * @return int */ - public function tell(); + public function tell(): int; /** * Indicates whether the current position is the end-of-file. - * - * @return bool */ - public function eof(); + public function eof(): bool; /** * Gathers statistics of the stream. * - * @return array + * @return array|false */ - public function stat(); + public function stat(): array|false; /** * Retrieve the underlying resource. * - * @param int $castAs - * - * @return mixed using resource or false + * @return resource|false using resource or false */ - public function cast($castAs); + public function cast(int $castAs); /** * Delete a file. * * @return bool TRUE on success FALSE otherwise */ - public function unlink(); + public function unlink(): bool; } diff --git a/src/Gaufrette/Stream/InMemoryBuffer.php b/src/Gaufrette/Stream/InMemoryBuffer.php index 30ac9be62..9c2294db0 100644 --- a/src/Gaufrette/Stream/InMemoryBuffer.php +++ b/src/Gaufrette/Stream/InMemoryBuffer.php @@ -9,28 +9,25 @@ class InMemoryBuffer implements Stream { - private $filesystem; - private $key; - private $mode; - private $content; - private $numBytes; - private $position; - private $synchronized; + private Filesystem $filesystem; + private string $key; + private StreamMode $mode; + private string $content; + private int $numBytes; + private int $position; + private bool $synchronized; /** * @param Filesystem $filesystem The filesystem managing the file to stream * @param string $key The file key */ - public function __construct(Filesystem $filesystem, $key) + public function __construct(Filesystem $filesystem, string $key) { $this->filesystem = $filesystem; $this->key = $key; } - /** - * {@inheritdoc} - */ - public function open(StreamMode $mode) + public function open(StreamMode $mode): bool { $this->mode = $mode; @@ -57,7 +54,7 @@ public function open(StreamMode $mode) return true; } - public function read($count) + public function read(int $count): string|false { if (false === $this->mode->allowsRead()) { throw new \LogicException('The stream does not allow read.'); @@ -69,7 +66,7 @@ public function read($count) return $chunk; } - public function write($data) + public function write(string $data): int { if (false === $this->mode->allowsWrite()) { throw new \LogicException('The stream does not allow write.'); @@ -99,14 +96,14 @@ public function write($data) return $numWrittenBytes; } - public function close() + public function close(): void { if (!$this->synchronized) { $this->flush(); } } - public function seek($offset, $whence = SEEK_SET) + public function seek(int $offset, int $whence = SEEK_SET): bool { switch ($whence) { case SEEK_SET: @@ -128,12 +125,12 @@ public function seek($offset, $whence = SEEK_SET) return true; } - public function tell() + public function tell(): int { return $this->position; } - public function flush() + public function flush(): bool { if ($this->synchronized) { return true; @@ -148,15 +145,15 @@ public function flush() return true; } - public function eof() + public function eof(): bool { return $this->position >= $this->numBytes; } /** - * {@inheritdoc} + * @return array|false */ - public function stat() + public function stat(): array|false { if ($this->filesystem->has($this->key)) { $isDirectory = $this->filesystem->isDirectory($this->key); @@ -184,18 +181,12 @@ public function stat() return false; } - /** - * {@inheritdoc} - */ public function cast($castAst) { return false; } - /** - * {@inheritdoc} - */ - public function unlink() + public function unlink(): bool { if ($this->mode && $this->mode->impliesExistingContentDeletion()) { return $this->filesystem->delete($this->key); @@ -204,10 +195,7 @@ public function unlink() return false; } - /** - * @return bool - */ - protected function hasNewContentAtFurtherPosition() + protected function hasNewContentAtFurtherPosition(): bool { return $this->position > 0 && !$this->content; } @@ -215,10 +203,8 @@ protected function hasNewContentAtFurtherPosition() /** * @param string $content Empty string by default * @param bool $overwrite Overwrite by default - * - * @return string */ - protected function writeContent($content = '', $overwrite = true) + protected function writeContent(string $content = '', bool $overwrite = true): string { $this->filesystem->write($this->key, $content, $overwrite); diff --git a/src/Gaufrette/Stream/Local.php b/src/Gaufrette/Stream/Local.php index 306119c5e..5ba3ffdb1 100644 --- a/src/Gaufrette/Stream/Local.php +++ b/src/Gaufrette/Stream/Local.php @@ -12,25 +12,22 @@ */ class Local implements Stream { - private $path; + private string $path; private $mode; private $fileHandle; - private $mkdirMode; + private int $mkdirMode; /** * @param string $path * @param int $mkdirMode */ - public function __construct($path, $mkdirMode = 0755) + public function __construct(string $path, int $mkdirMode = 0755) { $this->path = $path; $this->mkdirMode = $mkdirMode; } - /** - * {@inheritdoc} - */ - public function open(StreamMode $mode) + public function open(StreamMode $mode): bool { $baseDirPath = \Gaufrette\Util\Path::dirname($this->path); if ($mode->allowsWrite() && !is_dir($baseDirPath)) { @@ -53,10 +50,7 @@ public function open(StreamMode $mode) return true; } - /** - * {@inheritdoc} - */ - public function read($count) + public function read(int $count): string|false { if (!$this->fileHandle) { return false; @@ -69,29 +63,23 @@ public function read($count) return fread($this->fileHandle, $count); } - /** - * {@inheritdoc} - */ - public function write($data) + public function write(string $data): int { if (!$this->fileHandle) { - return false; + return 0; } if (false === $this->mode->allowsWrite()) { throw new \LogicException('The stream does not allow write.'); } - return fwrite($this->fileHandle, $data); + return fwrite($this->fileHandle, $data)?: 0; } - /** - * {@inheritdoc} - */ - public function close() + public function close(): void { if (!$this->fileHandle) { - return false; + return; } $closed = fclose($this->fileHandle); @@ -100,14 +88,9 @@ public function close() $this->mode = null; $this->fileHandle = null; } - - return $closed; } - /** - * {@inheritdoc} - */ - public function flush() + public function flush(): bool { if ($this->fileHandle) { return fflush($this->fileHandle); @@ -116,10 +99,7 @@ public function flush() return false; } - /** - * {@inheritdoc} - */ - public function seek($offset, $whence = SEEK_SET) + public function seek(int $offset, int $whence = SEEK_SET): bool { if ($this->fileHandle) { return 0 === fseek($this->fileHandle, $offset, $whence); @@ -128,10 +108,7 @@ public function seek($offset, $whence = SEEK_SET) return false; } - /** - * {@inheritdoc} - */ - public function tell() + public function tell(): int { if ($this->fileHandle) { return ftell($this->fileHandle); @@ -140,10 +117,7 @@ public function tell() return false; } - /** - * {@inheritdoc} - */ - public function eof() + public function eof(): bool { if ($this->fileHandle) { return feof($this->fileHandle); @@ -153,9 +127,9 @@ public function eof() } /** - * {@inheritdoc} + * @return array|false */ - public function stat() + public function stat(): array|false { if ($this->fileHandle) { return fstat($this->fileHandle); @@ -166,10 +140,7 @@ public function stat() return false; } - /** - * {@inheritdoc} - */ - public function cast($castAs) + public function cast(int $castAs) { if ($this->fileHandle) { return $this->fileHandle; @@ -178,10 +149,7 @@ public function cast($castAs) return false; } - /** - * {@inheritdoc} - */ - public function unlink() + public function unlink(): bool { if ($this->mode && $this->mode->impliesExistingContentDeletion()) { return @unlink($this->path); From c7d798a8a722d894331a8e31201b17832b3a20ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin?= Date: Thu, 25 May 2023 14:18:44 +0200 Subject: [PATCH 17/48] fix pedro review --- src/Gaufrette/Stream.php | 8 ++++++-- src/Gaufrette/Stream/InMemoryBuffer.php | 6 +++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/Gaufrette/Stream.php b/src/Gaufrette/Stream.php index b016e0547..9d99e140d 100644 --- a/src/Gaufrette/Stream.php +++ b/src/Gaufrette/Stream.php @@ -26,7 +26,7 @@ public function open(StreamMode $mode): bool; * * @param int $count The number of bytes */ - public function read(int $count): string|false; + public function read(int $count): string|bool; /** * Writes the specified data. @@ -59,6 +59,9 @@ public function flush(): bool; /** * Seeks to the specified offset. */ + /** + * @param SEEK_SET|SEEK_CUR|SEEK_END $whence + */ public function seek(int $offset, int $whence = SEEK_SET): bool; /** @@ -76,11 +79,12 @@ public function eof(): bool; * * @return array|false */ - public function stat(): array|false; + public function stat(): array|bool; /** * Retrieve the underlying resource. * + * @param STREAM_CAST_FOR_SELECT|STREAM_CAST_AS_STREAM $castAs * @return resource|false using resource or false */ public function cast(int $castAs); diff --git a/src/Gaufrette/Stream/InMemoryBuffer.php b/src/Gaufrette/Stream/InMemoryBuffer.php index 9c2294db0..3b7e97aee 100644 --- a/src/Gaufrette/Stream/InMemoryBuffer.php +++ b/src/Gaufrette/Stream/InMemoryBuffer.php @@ -11,11 +11,11 @@ class InMemoryBuffer implements Stream { private Filesystem $filesystem; private string $key; - private StreamMode $mode; + private ?StreamMode $mode = null; private string $content; private int $numBytes; private int $position; - private bool $synchronized; + private bool $synchronized = false; /** * @param Filesystem $filesystem The filesystem managing the file to stream @@ -181,7 +181,7 @@ public function stat(): array|false return false; } - public function cast($castAst) + public function cast(int $castAs): bool { return false; } From 15971984433f6b605239c07e9ba9cd1de653a5b5 Mon Sep 17 00:00:00 2001 From: PedroTroller Date: Mon, 24 Apr 2023 16:35:09 +0200 Subject: [PATCH 18/48] refactor: add typeint to FilesystemMap, StreamWrapper and StreamMode --- src/Gaufrette/FilesystemMap.php | 32 ++---- src/Gaufrette/FilesystemMapInterface.php | 14 +-- src/Gaufrette/StreamMode.php | 52 +++------ src/Gaufrette/StreamWrapper.php | 133 +++++++++-------------- 4 files changed, 85 insertions(+), 146 deletions(-) diff --git a/src/Gaufrette/FilesystemMap.php b/src/Gaufrette/FilesystemMap.php index 2a700dcaa..0eddd6a32 100644 --- a/src/Gaufrette/FilesystemMap.php +++ b/src/Gaufrette/FilesystemMap.php @@ -9,15 +9,18 @@ */ class FilesystemMap implements FilesystemMapInterface { - private $filesystems = []; + /** + * @var array + */ + private array $filesystems = []; /** * Returns an array of all the registered filesystems where the key is the * name and the value the filesystem. * - * @return array + * @return array */ - public function all() + public function all(): array { return $this->filesystems; } @@ -25,13 +28,10 @@ public function all() /** * Register the given filesystem for the specified name. * - * @param string $name - * @param FilesystemInterface $filesystem - * * @throws \InvalidArgumentException when the specified name contains - * forbidden characters + * forbidden characters */ - public function set($name, FilesystemInterface $filesystem) + public function set(string $name, FilesystemInterface $filesystem): void { if (!preg_match('/^[-_a-zA-Z0-9]+$/', $name)) { throw new \InvalidArgumentException(sprintf( @@ -43,18 +43,12 @@ public function set($name, FilesystemInterface $filesystem) $this->filesystems[$name] = $filesystem; } - /** - * {@inheritdoc} - */ - public function has($name) + public function has(string $name): bool { return isset($this->filesystems[$name]); } - /** - * {@inheritdoc} - */ - public function get($name) + public function get(string $name): FilesystemInterface { if (!$this->has($name)) { throw new \InvalidArgumentException(sprintf( @@ -68,10 +62,8 @@ public function get($name) /** * Removes the filesystem registered for the specified name. - * - * @param string $name */ - public function remove($name) + public function remove(string $name): void { if (!$this->has($name)) { throw new \InvalidArgumentException(sprintf( @@ -86,7 +78,7 @@ public function remove($name) /** * Clears all the registered filesystems. */ - public function clear() + public function clear(): void { $this->filesystems = []; } diff --git a/src/Gaufrette/FilesystemMapInterface.php b/src/Gaufrette/FilesystemMapInterface.php index b2ced3bea..970ca5a9c 100644 --- a/src/Gaufrette/FilesystemMapInterface.php +++ b/src/Gaufrette/FilesystemMapInterface.php @@ -10,22 +10,14 @@ interface FilesystemMapInterface /** * Indicates whether there is a filesystem registered for the specified * name. - * - * @param string $name - * - * @return bool */ - public function has($name); + public function has(string $name): bool; /** * Returns the filesystem registered for the specified name. * - * @param string $name - * - * @return FilesystemInterface - * * @throw \InvalidArgumentException when there is no filesystem registered - * for the specified name + * for the specified name */ - public function get($name); + public function get(string $name): FilesystemInterface; } diff --git a/src/Gaufrette/StreamMode.php b/src/Gaufrette/StreamMode.php index 7dbf83a1c..82ced3b95 100644 --- a/src/Gaufrette/StreamMode.php +++ b/src/Gaufrette/StreamMode.php @@ -9,15 +9,17 @@ */ class StreamMode { - private $mode; - private $base; - private $plus; - private $flag; + private string $mode; + private string $base; + private bool $plus; + private string $flag; /** * @param string $mode A stream mode as for the use of fopen() + * + * @see https://www.php.net/manual/en/function.fopen.php */ - public function __construct($mode) + public function __construct(string $mode) { $this->mode = $mode; @@ -31,20 +33,16 @@ public function __construct($mode) /** * Returns the underlying mode. - * - * @return string */ - public function getMode() + public function getMode(): string { return $this->mode; } /** * Indicates whether the mode allows to read. - * - * @return bool */ - public function allowsRead() + public function allowsRead(): bool { if ($this->plus) { return true; @@ -55,10 +53,8 @@ public function allowsRead() /** * Indicates whether the mode allows to write. - * - * @return bool */ - public function allowsWrite() + public function allowsWrite(): bool { if ($this->plus) { return true; @@ -69,20 +65,16 @@ public function allowsWrite() /** * Indicates whether the mode allows to open an existing file. - * - * @return bool */ - public function allowsExistingFileOpening() + public function allowsExistingFileOpening(): bool { return 'x' !== $this->base; } /** * Indicates whether the mode allows to create a new file. - * - * @return bool */ - public function allowsNewFileOpening() + public function allowsNewFileOpening(): bool { return 'r' !== $this->base; } @@ -90,10 +82,8 @@ public function allowsNewFileOpening() /** * Indicates whether the mode implies to delete the existing content of the * file when it already exists. - * - * @return bool */ - public function impliesExistingContentDeletion() + public function impliesExistingContentDeletion(): bool { return 'w' === $this->base; } @@ -101,10 +91,8 @@ public function impliesExistingContentDeletion() /** * Indicates whether the mode implies positioning the cursor at the * beginning of the file. - * - * @return bool */ - public function impliesPositioningCursorAtTheBeginning() + public function impliesPositioningCursorAtTheBeginning(): bool { return 'a' !== $this->base; } @@ -112,30 +100,24 @@ public function impliesPositioningCursorAtTheBeginning() /** * Indicates whether the mode implies positioning the cursor at the end of * the file. - * - * @return bool */ - public function impliesPositioningCursorAtTheEnd() + public function impliesPositioningCursorAtTheEnd(): bool { return 'a' === $this->base; } /** * Indicates whether the stream is in binary mode. - * - * @return bool */ - public function isBinary() + public function isBinary(): bool { return 'b' === $this->flag; } /** * Indicates whether the stream is in text mode. - * - * @return bool */ - public function isText() + public function isText(): bool { return false === $this->isBinary(); } diff --git a/src/Gaufrette/StreamWrapper.php b/src/Gaufrette/StreamWrapper.php index bde74a61d..d101ce933 100644 --- a/src/Gaufrette/StreamWrapper.php +++ b/src/Gaufrette/StreamWrapper.php @@ -10,30 +10,30 @@ */ class StreamWrapper { - private static $filesystemMap; + private static FilesystemMap $filesystemMap; - private $stream; + private Stream $stream; + /** + * @var ?resource + * @see https://www.php.net/manual/en/class.streamwrapper.php#streamwrapper.props.context + */ public $context; /** * Defines the filesystem map. - * - * @param FilesystemMap $map */ - public static function setFilesystemMap(FilesystemMap $map) + public static function setFilesystemMap(FilesystemMap $map): void { self::$filesystemMap = $map; } /** * Returns the filesystem map. - * - * @return FilesystemMap $map */ - public static function getFilesystemMap() + public static function getFilesystemMap(): FilesystemMap { - if (null === self::$filesystemMap) { + if (false === isset(self::$filesystemMap)) { self::$filesystemMap = self::createFilesystemMap(); } @@ -42,10 +42,8 @@ public static function getFilesystemMap() /** * Registers the stream wrapper to handle the specified scheme. - * - * @param string $scheme Default is gaufrette */ - public static function register($scheme = 'gaufrette') + public static function register(string $scheme = 'gaufrette'): void { self::streamWrapperUnregister($scheme); @@ -58,36 +56,32 @@ public static function register($scheme = 'gaufrette') } } - /** - * @return FilesystemMap - */ - protected static function createFilesystemMap() + protected static function createFilesystemMap(): FilesystemMap { return new FilesystemMap(); } /** - * @param string $scheme - protocol scheme + * @param string $scheme Protocol scheme */ - protected static function streamWrapperUnregister($scheme) + protected static function streamWrapperUnregister(string $scheme): bool { if (in_array($scheme, stream_get_wrappers())) { return stream_wrapper_unregister($scheme); } + + return false; } /** - * @param string $scheme - protocol scheme - * @param string $className - * - * @return bool + * @param string $scheme Protocol scheme */ - protected static function streamWrapperRegister($scheme, $className) + protected static function streamWrapperRegister(string $scheme, string $className): bool { return stream_wrapper_register($scheme, $className); } - public function stream_open($path, $mode) + public function stream_open(string $path, string $mode, int $options, ?string &$opened_path): bool { $this->stream = $this->createStream($path); @@ -95,46 +89,36 @@ public function stream_open($path, $mode) } /** - * @param int $bytes - * - * @return mixed + * @return string|false */ - public function stream_read($bytes) + public function stream_read(int $count): string|bool { - if ($this->stream) { - return $this->stream->read($bytes); + if (isset($this->stream)) { + return $this->stream->read($count); } return false; } - /** - * @param string $data - * - * @return int - */ - public function stream_write($data) + public function stream_write(string $data): int { - if ($this->stream) { + if (isset($this->stream)) { return $this->stream->write($data); } return 0; } - public function stream_close() + public function stream_close(): void { - if ($this->stream) { + if (isset($this->stream)) { $this->stream->close(); } } - /** - * @return bool - */ - public function stream_flush() + public function stream_flush(): bool { - if ($this->stream) { + if (isset($this->stream)) { return $this->stream->flush(); } @@ -142,14 +126,11 @@ public function stream_flush() } /** - * @param int $offset - * @param int $whence - one of values [SEEK_SET, SEEK_CUR, SEEK_END] - * - * @return bool + * @param SEEK_SET|SEEK_CUR|SEEK_END $whence */ - public function stream_seek($offset, $whence = SEEK_SET) + public function stream_seek(int $offset, int $whence = SEEK_SET): bool { - if ($this->stream) { + if (isset($this->stream)) { return $this->stream->seek($offset, $whence); } @@ -157,23 +138,20 @@ public function stream_seek($offset, $whence = SEEK_SET) } /** - * @return mixed + * Retrieve the current position of a stream */ - public function stream_tell() + public function stream_tell(): int { - if ($this->stream) { + if (isset($this->stream)) { return $this->stream->tell(); } - return false; + return 0; } - /** - * @return bool - */ - public function stream_eof() + public function stream_eof(): bool { - if ($this->stream) { + if (isset($this->stream)) { return $this->stream->eof(); } @@ -181,11 +159,11 @@ public function stream_eof() } /** - * @return mixed + * @return array|false */ - public function stream_stat() + public function stream_stat(): array|bool { - if ($this->stream) { + if (isset($this->stream)) { return $this->stream->stat(); } @@ -193,14 +171,11 @@ public function stream_stat() } /** - * @param string $path - * @param int $flags - * - * @return mixed + * @return array|false * - * @todo handle $flags parameter + * @TODO handle $flags parameter */ - public function url_stat($path, $flags) + public function url_stat(string $path, int $flags): array|bool { $stream = $this->createStream($path); @@ -212,12 +187,7 @@ public function url_stat($path, $flags) return $stream->stat(); } - /** - * @param string $path - * - * @return mixed - */ - public function unlink($path) + public function unlink(string $path): bool { $stream = $this->createStream($path); @@ -231,18 +201,18 @@ public function unlink($path) } /** - * @return mixed + * @return resource|false */ - public function stream_cast($castAs) + public function stream_cast(int $castAs) { - if ($this->stream) { + if (isset($this->stream)) { return $this->stream->cast($castAs); } return false; } - protected function createStream($path) + protected function createStream(string $path): Stream { $parts = array_merge( [ @@ -273,10 +243,13 @@ protected function createStream($path) )); } - return self::getFilesystemMap()->get($domain)->createStream($key); + return self::getFilesystemMap() + ->get($domain) + ->createStream($key) + ; } - protected function createStreamMode($mode) + protected function createStreamMode(string $mode): StreamMode { return new StreamMode($mode); } From aa1b69f0707db0527bd9f2b5206fb285b767f40c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin?= Date: Mon, 24 Apr 2023 16:40:45 +0200 Subject: [PATCH 19/48] Refacto: Add type on Util classes --- src/Gaufrette/Util/Checksum.php | 14 +++----------- src/Gaufrette/Util/Path.php | 22 +++++----------------- src/Gaufrette/Util/Size.php | 16 +++------------- 3 files changed, 11 insertions(+), 41 deletions(-) diff --git a/src/Gaufrette/Util/Checksum.php b/src/Gaufrette/Util/Checksum.php index 63afffaed..a5cd50416 100644 --- a/src/Gaufrette/Util/Checksum.php +++ b/src/Gaufrette/Util/Checksum.php @@ -5,30 +5,22 @@ /** * Checksum utils. * - * @author Antoine Hérault + * @author Antoine Hérault */ class Checksum { /** * Returns the checksum of the given content. - * - * @param string $content - * - * @return string */ - public static function fromContent($content) + public static function fromContent(string $content): string { return md5($content); } /** * Returns the checksum of the specified file. - * - * @param string $filename - * - * @return string */ - public static function fromFile($filename) + public static function fromFile(string $filename): false|string { return md5_file($filename); } diff --git a/src/Gaufrette/Util/Path.php b/src/Gaufrette/Util/Path.php index 4dec5c50a..c2d8d2af5 100644 --- a/src/Gaufrette/Util/Path.php +++ b/src/Gaufrette/Util/Path.php @@ -5,18 +5,14 @@ /** * Path utils. * - * @author Antoine Hérault + * @author Antoine Hérault */ class Path { /** * Normalizes the given path. - * - * @param string $path - * - * @return string */ - public static function normalize($path) + public static function normalize(string $path): string { $path = str_replace('\\', '/', $path); $prefix = static::getAbsolutePrefix($path); @@ -48,10 +44,8 @@ public static function normalize($path) * Indicates whether the given path is absolute or not. * * @param string $path A normalized path - * - * @return bool */ - public static function isAbsolute($path) + public static function isAbsolute(string $path): bool { return '' !== static::getAbsolutePrefix($path); } @@ -60,10 +54,8 @@ public static function isAbsolute($path) * Returns the absolute prefix of the given path. * * @param string $path A normalized path - * - * @return string */ - public static function getAbsolutePrefix($path) + public static function getAbsolutePrefix(string $path): string { preg_match('|^(?P([a-zA-Z]+:)?//?)|', $path, $matches); @@ -77,13 +69,9 @@ public static function getAbsolutePrefix($path) /** * Wrap native dirname function in order to handle only UNIX-style paths * - * @param string $path - * - * @return string - * * @see http://php.net/manual/en/function.dirname.php */ - public static function dirname($path) + public static function dirname(string $path): string { return str_replace('\\', '/', \dirname($path)); } diff --git a/src/Gaufrette/Util/Size.php b/src/Gaufrette/Util/Size.php index 7dd53aba3..970712b71 100644 --- a/src/Gaufrette/Util/Size.php +++ b/src/Gaufrette/Util/Size.php @@ -12,13 +12,9 @@ class Size /** * Returns the size in bytes from the given content. * - * @param string $content - * - * @return int - * * @todo handle the case the mbstring is not loaded */ - public static function fromContent($content) + public static function fromContent(string $content): int { // Make sure to get the real length in byte and not // accidentally mistake some bytes as a UTF BOM. @@ -27,12 +23,8 @@ public static function fromContent($content) /** * Returns the size in bytes from the given file. - * - * @param string $filename - * - * @return int */ - public static function fromFile($filename) + public static function fromFile(string $filename): false|int { return filesize($filename); } @@ -41,10 +33,8 @@ public static function fromFile($filename) * Returns the size in bytes from the given resource. * * @param resource $handle - * - * @return string */ - public static function fromResource($handle) + public static function fromResource($handle): int { $cStat = fstat($handle); // if the resource is a remote file, $cStat will be false From b134d9c41a5540a773dc2b1ec1175e966646be58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin?= Date: Fri, 28 Apr 2023 09:43:15 +0200 Subject: [PATCH 20/48] fix muchafm review --- src/Gaufrette/Util/Size.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Gaufrette/Util/Size.php b/src/Gaufrette/Util/Size.php index 970712b71..b91176f5b 100644 --- a/src/Gaufrette/Util/Size.php +++ b/src/Gaufrette/Util/Size.php @@ -34,7 +34,7 @@ public static function fromFile(string $filename): false|int * * @param resource $handle */ - public static function fromResource($handle): int + public static function fromResource($handle): array|false|int { $cStat = fstat($handle); // if the resource is a remote file, $cStat will be false From d91a8a248b9eacf10ad25cbd6881411f949874e2 Mon Sep 17 00:00:00 2001 From: Sophie Roussel Date: Fri, 28 Apr 2023 16:20:29 +0200 Subject: [PATCH 21/48] fix: pedro review --- src/Gaufrette/Util/Checksum.php | 2 +- src/Gaufrette/Util/Size.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Gaufrette/Util/Checksum.php b/src/Gaufrette/Util/Checksum.php index a5cd50416..188f61c7b 100644 --- a/src/Gaufrette/Util/Checksum.php +++ b/src/Gaufrette/Util/Checksum.php @@ -20,7 +20,7 @@ public static function fromContent(string $content): string /** * Returns the checksum of the specified file. */ - public static function fromFile(string $filename): false|string + public static function fromFile(string $filename): bool|string { return md5_file($filename); } diff --git a/src/Gaufrette/Util/Size.php b/src/Gaufrette/Util/Size.php index b91176f5b..7b7f049fc 100644 --- a/src/Gaufrette/Util/Size.php +++ b/src/Gaufrette/Util/Size.php @@ -24,7 +24,7 @@ public static function fromContent(string $content): int /** * Returns the size in bytes from the given file. */ - public static function fromFile(string $filename): false|int + public static function fromFile(string $filename): bool|int { return filesize($filename); } @@ -34,7 +34,7 @@ public static function fromFile(string $filename): false|int * * @param resource $handle */ - public static function fromResource($handle): array|false|int + public static function fromResource($handle): array|bool|int { $cStat = fstat($handle); // if the resource is a remote file, $cStat will be false From ffe0412a4be6275f9ac7bc85b3a23dfd0a16dbe7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin?= Date: Fri, 2 Jun 2023 15:17:15 +0200 Subject: [PATCH 22/48] fix pedro's review --- src/Gaufrette/Util/Checksum.php | 4 ++-- src/Gaufrette/Util/Size.php | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Gaufrette/Util/Checksum.php b/src/Gaufrette/Util/Checksum.php index 188f61c7b..3e50326af 100644 --- a/src/Gaufrette/Util/Checksum.php +++ b/src/Gaufrette/Util/Checksum.php @@ -20,8 +20,8 @@ public static function fromContent(string $content): string /** * Returns the checksum of the specified file. */ - public static function fromFile(string $filename): bool|string + public static function fromFile(string $filename): string { - return md5_file($filename); + return md5_file($filename)?: ''; } } diff --git a/src/Gaufrette/Util/Size.php b/src/Gaufrette/Util/Size.php index 7b7f049fc..6a7fee966 100644 --- a/src/Gaufrette/Util/Size.php +++ b/src/Gaufrette/Util/Size.php @@ -24,9 +24,9 @@ public static function fromContent(string $content): int /** * Returns the size in bytes from the given file. */ - public static function fromFile(string $filename): bool|int + public static function fromFile(string $filename): int { - return filesize($filename); + return filesize($filename)?: 0; } /** @@ -34,7 +34,7 @@ public static function fromFile(string $filename): bool|int * * @param resource $handle */ - public static function fromResource($handle): array|bool|int + public static function fromResource($handle): int { $cStat = fstat($handle); // if the resource is a remote file, $cStat will be false From 4a4e4ac5ddc679b08293c80e492b1983370f01a8 Mon Sep 17 00:00:00 2001 From: Sophie Roussel Date: Fri, 28 Apr 2023 14:45:14 +0200 Subject: [PATCH 23/48] refacto: spec types --- spec/Gaufrette/Adapter/AsyncAwsS3Spec.php | 3 - spec/Gaufrette/Adapter/AwsS3Spec.php | 3 - spec/Gaufrette/Adapter/AzureBlobStorage.php | 147 ++++-------------- .../AzureBlobStorage/BlobProxyFactory.php | 5 +- spec/Gaufrette/Adapter/DoctrineDbalSpec.php | 30 ---- spec/Gaufrette/Adapter/FlysystemSpec.php | 2 +- spec/Gaufrette/Adapter/GridFSSpec.php | 20 +-- spec/Gaufrette/Adapter/PhpseclibSftpSpec.php | 25 --- spec/Gaufrette/Adapter/functions.php | 14 +- spec/Gaufrette/FileSpec.php | 46 ------ spec/Gaufrette/FilesystemMapSpec.php | 12 -- spec/Gaufrette/FilesystemSpec.php | 91 ----------- spec/Gaufrette/StreamWrapperSpec.php | 63 -------- .../Functional/Adapter/AsyncAwsS3Test.php | 6 +- .../Functional/Adapter/AwsS3Test.php | 9 +- .../Adapter/AzureBlobStorageTest.php | 4 +- .../AzureMultiContainerBlobStorageTest.php | 4 +- .../Functional/Adapter/DoctrineDbalTest.php | 4 +- .../Functional/Adapter/FunctionalTestCase.php | 5 +- .../Functional/Adapter/LocalTest.php | 2 +- .../Functional/Adapter/PhpseclibSftpTest.php | 6 +- .../FileStream/FunctionalTestCase.php | 3 +- .../Functional/FileStream/LocalTest.php | 2 +- 23 files changed, 64 insertions(+), 442 deletions(-) diff --git a/spec/Gaufrette/Adapter/AsyncAwsS3Spec.php b/spec/Gaufrette/Adapter/AsyncAwsS3Spec.php index 6c0ae7408..1556cf9d6 100644 --- a/spec/Gaufrette/Adapter/AsyncAwsS3Spec.php +++ b/spec/Gaufrette/Adapter/AsyncAwsS3Spec.php @@ -8,9 +8,6 @@ class AsyncAwsS3Spec extends ObjectBehavior { - /** - * @param \AsyncAws\SimpleS3\SimpleS3Client $service - */ function let(SimpleS3Client $service) { $this->beConstructedWith($service, 'bucketName'); diff --git a/spec/Gaufrette/Adapter/AwsS3Spec.php b/spec/Gaufrette/Adapter/AwsS3Spec.php index 7dd38a8f9..6fa971cc5 100644 --- a/spec/Gaufrette/Adapter/AwsS3Spec.php +++ b/spec/Gaufrette/Adapter/AwsS3Spec.php @@ -8,9 +8,6 @@ class AwsS3Spec extends ObjectBehavior { - /** - * @param \Aws\S3\S3Client $service - */ function let(S3Client $service) { $this->beConstructedWith($service, 'bucketName'); diff --git a/spec/Gaufrette/Adapter/AzureBlobStorage.php b/spec/Gaufrette/Adapter/AzureBlobStorage.php index c6cee8572..cf8a3cb66 100644 --- a/spec/Gaufrette/Adapter/AzureBlobStorage.php +++ b/spec/Gaufrette/Adapter/AzureBlobStorage.php @@ -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 AzureBlobStorage extends ObjectBehavior { - /** - * @param \Gaufrette\Adapter\AzureBlobStorage\BlobProxyFactoryInterface $blobProxyFactory - */ - function let($blobProxyFactory) + function let(BlobProxyFactoryInterface $blobProxyFactory) { $this->beConstructedWith($blobProxyFactory, 'containerName'); } @@ -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() @@ -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') @@ -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') @@ -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') @@ -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') @@ -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') @@ -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( @@ -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( @@ -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( @@ -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() @@ -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() @@ -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() @@ -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() @@ -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() @@ -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() @@ -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() @@ -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() @@ -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 = []; @@ -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() @@ -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() @@ -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() @@ -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() diff --git a/spec/Gaufrette/Adapter/AzureBlobStorage/BlobProxyFactory.php b/spec/Gaufrette/Adapter/AzureBlobStorage/BlobProxyFactory.php index 88b9f50c9..85ab1c7ae 100644 --- a/spec/Gaufrette/Adapter/AzureBlobStorage/BlobProxyFactory.php +++ b/spec/Gaufrette/Adapter/AzureBlobStorage/BlobProxyFactory.php @@ -6,10 +6,7 @@ class BlobProxyFactory extends ObjectBehavior { - /** - * @param string $connectionString - */ - function let($connectionString) + function let(string $connectionString) { $this->beConstructedWith($connectionString); } diff --git a/spec/Gaufrette/Adapter/DoctrineDbalSpec.php b/spec/Gaufrette/Adapter/DoctrineDbalSpec.php index 4e723e148..e78a3f7f0 100644 --- a/spec/Gaufrette/Adapter/DoctrineDbalSpec.php +++ b/spec/Gaufrette/Adapter/DoctrineDbalSpec.php @@ -12,9 +12,6 @@ class DoctrineDbalSpec extends ObjectBehavior { - /** - * @param \Doctrine\DBAL\Connection $connection - */ function let(Connection $connection) { $this->beConstructedWith($connection, 'someTableName'); @@ -35,9 +32,6 @@ function it_does_not_handle_directories() $this->isDirectory('filename')->shouldReturn(false); } - /** - * @param \Doctrine\DBAL\Connection $connection - */ function it_checks_if_file_exists(Connection $connection) { $connection @@ -62,9 +56,6 @@ function it_checks_if_file_exists(Connection $connection) $this->exists('filename')->shouldReturn(false); } - /** - * @param \Doctrine\DBAL\Connection $connection - */ function it_writes_to_new_file(Connection $connection) { $connection @@ -96,9 +87,6 @@ function it_writes_to_new_file(Connection $connection) $this->write('filename', 'some content')->shouldReturn(12); } - /** - * @param \Doctrine\DBAL\Connection $connection - */ function it_write_file(Connection $connection) { $method = 'fetchOne'; // dbal 3.x @@ -131,9 +119,6 @@ function it_write_file(Connection $connection) $this->write('filename', 'some content')->shouldReturn(12); } - /** - * @param \Doctrine\DBAL\Connection $connection - */ function it_reads_file(Connection $connection) { $method = 'fetchOne'; // dbal 3.x @@ -153,9 +138,6 @@ function it_reads_file(Connection $connection) $this->read('filename')->shouldReturn('some content'); } - /** - * @param \Doctrine\DBAL\Connection $connection - */ function it_calculates_checksum(Connection $connection) { $method = 'fetchOne'; // dbal 3.x @@ -175,9 +157,6 @@ function it_calculates_checksum(Connection $connection) $this->checksum('filename')->shouldReturn(1234); } - /** - * @param \Doctrine\DBAL\Connection $connection - */ function it_gets_mtime(Connection $connection) { $method = 'fetchOne'; // dbal 3.x @@ -197,9 +176,6 @@ function it_gets_mtime(Connection $connection) $this->mtime('filename')->shouldReturn(1234); } - /** - * @param \Doctrine\DBAL\Connection $connection - */ function it_renames_file(Connection $connection) { $connection @@ -223,9 +199,6 @@ function it_renames_file(Connection $connection) $this->rename('filename', 'newFile')->shouldReturn(true); } - /** - * @param \Doctrine\DBAL\Connection $connection - */ function it_get_keys(Connection $connection, $result) { if (class_exists(Result::class)) { @@ -250,9 +223,6 @@ function it_get_keys(Connection $connection, $result) $this->keys()->shouldReturn(['filename', 'filename1', 'filename2']); } - /** - * @param \Doctrine\DBAL\Connection $connection - */ function it_deletes_file(Connection $connection) { $connection diff --git a/spec/Gaufrette/Adapter/FlysystemSpec.php b/spec/Gaufrette/Adapter/FlysystemSpec.php index 48f9934da..26ce52708 100644 --- a/spec/Gaufrette/Adapter/FlysystemSpec.php +++ b/spec/Gaufrette/Adapter/FlysystemSpec.php @@ -99,7 +99,7 @@ function it_renames_file(AdapterInterface $adapter) $this->rename('oldfilename', 'newfilename')->shouldReturn(true); } - function it_does_not_support_is_directory(AdapterInterface $adapter) + function it_does_not_support_is_directory() { $this->shouldThrow('Gaufrette\Exception\UnsupportedAdapterMethodException')->duringisDirectory('folder'); } diff --git a/spec/Gaufrette/Adapter/GridFSSpec.php b/spec/Gaufrette/Adapter/GridFSSpec.php index 87ec43f17..271a296de 100644 --- a/spec/Gaufrette/Adapter/GridFSSpec.php +++ b/spec/Gaufrette/Adapter/GridFSSpec.php @@ -46,7 +46,7 @@ function it_supports_native_list_keys() $this->shouldHaveType('Gaufrette\Adapter\ListKeysAware'); } - function it_reads_file($bucket) + function it_reads_file(Bucket $bucket) { $this->resources[] = $readable = fopen('php://memory', 'rw'); fwrite($readable, 'some content'); @@ -61,14 +61,14 @@ function it_reads_file($bucket) $this->read('filename')->shouldReturn('some content'); } - function it_does_not_fail_when_cannot_read($bucket) + function it_does_not_fail_when_cannot_read(Bucket $bucket) { $bucket->openDownloadStreamByName('filename')->willThrow(FileNotFoundException::class); $this->read('filename')->shouldReturn(false); } - function it_checks_if_file_exists($bucket, BSONDocument $file) + function it_checks_if_file_exists(Bucket $bucket, BSONDocument $file) { $bucket ->findOne(['filename' => 'filename']) @@ -83,7 +83,7 @@ function it_checks_if_file_exists($bucket, BSONDocument $file) $this->exists('filename2')->shouldReturn(false); } - function it_deletes_file($bucket) + function it_deletes_file(Bucket $bucket) { $bucket ->findOne(['filename' => 'filename'], ['projection' => ['_id' => 1]]) @@ -94,14 +94,14 @@ function it_deletes_file($bucket) $this->delete('filename')->shouldReturn(true); } - function it_does_not_delete_file($bucket) + function it_does_not_delete_file(Bucket $bucket) { $bucket->findOne(['filename' => 'filename'], ['projection' => ['_id' => 1]])->willReturn(null); $this->delete('filename')->shouldReturn(false); } - function it_writes_file($bucket) + function it_writes_file(Bucket $bucket) { $this->resources[] = $writable = fopen('php://memory', 'rw'); @@ -117,7 +117,7 @@ function it_writes_file($bucket) ; } - function it_renames_file($bucket) + function it_renames_file(Bucket $bucket) { $this->resources[] = $writable = fopen('php://memory', 'rw'); $this->resources[] = $readable = fopen('php://memory', 'rw'); @@ -137,7 +137,7 @@ function it_renames_file($bucket) $this->rename('filename', 'otherFilename')->shouldReturn(true); } - function it_fetches_keys($bucket) + function it_fetches_keys(Bucket $bucket) { $bucket ->find([], ['projection' => ['filename' => 1]]) @@ -147,7 +147,7 @@ function it_fetches_keys($bucket) $this->keys()->shouldReturn(['filename', 'otherFilename']); } - function it_fetches_mtime($bucket) + function it_fetches_mtime(Bucket $bucket) { $bucket ->findOne(['filename' => 'filename'], ['projection' => ['uploadDate' => 1]]) @@ -157,7 +157,7 @@ function it_fetches_mtime($bucket) $this->mtime('filename')->shouldReturn(12345); } - function it_calculates_checksum($bucket) + function it_calculates_checksum(Bucket $bucket) { $bucket ->findOne(['filename' => 'filename'], ['projection' => ['md5' => 1]]) diff --git a/spec/Gaufrette/Adapter/PhpseclibSftpSpec.php b/spec/Gaufrette/Adapter/PhpseclibSftpSpec.php index 7f6703cdd..465f3ba37 100644 --- a/spec/Gaufrette/Adapter/PhpseclibSftpSpec.php +++ b/spec/Gaufrette/Adapter/PhpseclibSftpSpec.php @@ -23,9 +23,6 @@ public function __construct() class PhpseclibSftpSpec extends ObjectBehavior { - /** - * @param \spec\Gaufrette\Adapter\SFTP $sftp - */ function let(SFTP $sftp) { $this->beConstructedWith($sftp, '/home/l3l0', false, 'l3lo', 'password'); @@ -46,9 +43,6 @@ function it_supports_native_list_keys() $this->shouldHaveType('Gaufrette\Adapter\ListKeysAware'); } - /** - * @param \spec\Gaufrette\Adapter\SFTP $sftp - */ function it_fetches_keys(SFTP $sftp) { $sftp @@ -73,9 +67,6 @@ function it_fetches_keys(SFTP $sftp) $this->keys()->shouldReturn(['filename', 'filename1', 'aaa', 'aaa/filename']); } - /** - * @param \spec\Gaufrette\Adapter\SFTP $sftp - */ function it_reads_file(SFTP $sftp) { $sftp->get('/home/l3l0/filename')->willReturn('some content'); @@ -83,9 +74,6 @@ function it_reads_file(SFTP $sftp) $this->read('filename')->shouldReturn('some content'); } - /** - * @param \spec\Gaufrette\Adapter\SFTP $sftp - */ function it_creates_and_writes_file(SFTP $sftp) { $sftp->pwd()->willReturn('/home/l3l0'); @@ -96,9 +84,6 @@ function it_creates_and_writes_file(SFTP $sftp) $this->write('filename', 'some content')->shouldReturn(12); } - /** - * @param \spec\Gaufrette\Adapter\SFTP $sftp - */ function it_renames_file(SFTP $sftp) { $sftp->pwd()->willReturn('/home/l3l0'); @@ -111,9 +96,6 @@ function it_renames_file(SFTP $sftp) $this->rename('filename', 'filename1')->shouldReturn(true); } - /** - * @param \spec\Gaufrette\Adapter\SFTP $sftp - */ function it_should_check_if_file_exists(SFTP $sftp) { $sftp->pwd()->willReturn('/home/l3l0'); @@ -127,9 +109,6 @@ function it_should_check_if_file_exists(SFTP $sftp) $this->exists('filename1')->shouldReturn(false); } - /** - * @param \spec\Gaufrette\Adapter\SFTP $sftp - */ function it_should_check_is_directory(SFTP $sftp) { $sftp->pwd()->willReturn('/home/l3l0'); @@ -141,10 +120,6 @@ function it_should_check_is_directory(SFTP $sftp) $this->isDirectory('filename')->shouldReturn(false); } - /** - * @param \spec\Gaufrette\Adapter\SFTP $sftp - * @param \Gaufrette\Filesystem $filesystem - */ function it_should_create_file(SFTP $sftp, Filesystem $filesystem) { $sftp->stat('/home/l3l0/filename')->willReturn([ diff --git a/spec/Gaufrette/Adapter/functions.php b/spec/Gaufrette/Adapter/functions.php index 177bf120f..77c68131a 100644 --- a/spec/Gaufrette/Adapter/functions.php +++ b/spec/Gaufrette/Adapter/functions.php @@ -9,7 +9,7 @@ function time() return \strtotime('2012-10-10 23:10:10'); } -function file_exists($path) +function file_exists(string $path) { //fake it for ssh+ssl: protocol for SFTP testing, otherwise delegate to global if (strpos($path, 'ssh+ssl:') === 0) { @@ -19,7 +19,7 @@ function file_exists($path) return \file_exists($path); } -function extension_loaded($name) +function extension_loaded() { global $extensionLoaded; @@ -30,17 +30,17 @@ function extension_loaded($name) return $extensionLoaded; } -function opendir($url) +function opendir() { return true; } -function apc_fetch($path) +function apc_fetch(string $path) { return sprintf('%s content', $path); } -function apc_store($path, $content, $ttl) +function apc_store(string $path) { if ('prefix-apc-test/invalid' === $path) { return false; @@ -49,7 +49,7 @@ function apc_store($path, $content, $ttl) return sprintf('%s content', $path); } -function apc_delete($path) +function apc_delete(string $path) { if ('prefix-apc-test/invalid' === $path) { return false; @@ -58,7 +58,7 @@ function apc_delete($path) return true; } -function apc_exists($path) +function apc_exists(string $path) { if ('prefix-apc-test/invalid' === $path) { return false; diff --git a/spec/Gaufrette/FileSpec.php b/spec/Gaufrette/FileSpec.php index 80576bbda..4ebddd974 100644 --- a/spec/Gaufrette/FileSpec.php +++ b/spec/Gaufrette/FileSpec.php @@ -12,9 +12,6 @@ interface MetadataAdapter extends \Gaufrette\Adapter, class FileSpec extends ObjectBehavior { - /** - * @param \Gaufrette\Filesystem $filesystem - */ function let(Filesystem $filesystem) { $this->beConstructedWith('filename', $filesystem); @@ -30,9 +27,6 @@ function it_gives_access_to_key() $this->getKey()->shouldReturn('filename'); } - /** - * @param \Gaufrette\Filesystem $filesystem - */ function it_gets_content(Filesystem $filesystem) { $filesystem->read('filename')->shouldBeCalled()->willReturn('Some content'); @@ -40,9 +34,6 @@ function it_gets_content(Filesystem $filesystem) $this->getContent()->shouldReturn('Some content'); } - /** - * @param \Gaufrette\Filesystem $filesystem - */ function it_gets_mtime(Filesystem $filesystem) { $filesystem->mtime('filename')->shouldBeCalled()->willReturn(1358797854); @@ -50,10 +41,6 @@ function it_gets_mtime(Filesystem $filesystem) $this->getMtime()->shouldReturn(1358797854); } - /** - * @param \Gaufrette\Filesystem $filesystem - * @param \spec\Gaufrette\MetadataAdapter $adapter - */ function it_pass_metadata_when_write_content(Filesystem $filesystem, MetadataAdapter $adapter) { $metadata = ['id' => '123']; @@ -64,10 +51,6 @@ function it_pass_metadata_when_write_content(Filesystem $filesystem, MetadataAda $this->setContent('some content', $metadata); } - /** - * @param \Gaufrette\Filesystem $filesystem - * @param \spec\Gaufrette\MetadataAdapter $adapter - */ function it_pass_metadata_when_read_content(Filesystem $filesystem, MetadataAdapter $adapter) { $metadata = ['id' => '123']; @@ -78,10 +61,6 @@ function it_pass_metadata_when_read_content(Filesystem $filesystem, MetadataAdap $this->getContent($metadata); } - /** - * @param \Gaufrette\Filesystem $filesystem - * @param \spec\Gaufrette\MetadataAdapter $adapter - */ function it_pass_metadata_when_delete_content(Filesystem $filesystem, MetadataAdapter $adapter) { $metadata = ['id' => '123']; @@ -92,10 +71,6 @@ function it_pass_metadata_when_delete_content(Filesystem $filesystem, MetadataAd $this->delete($metadata); } - /** - * @param \Gaufrette\Filesystem $filesystem - * @param \spec\Gaufrette\MetadataAdapter $adapter - */ function it_sets_content_of_file(Filesystem $filesystem, MetadataAdapter $adapter) { $adapter->setMetadata('filename', [])->shouldNotBeCalled(); @@ -117,9 +92,6 @@ function it_sets_name() $this->getName()->shouldReturn('name'); } - /** - * @param \Gaufrette\Filesystem $filesystem - */ function it_sets_size_for_new_file(Filesystem $filesystem) { $filesystem->write('filename', 'some content', true)->shouldBeCalled()->willReturn(21); @@ -128,9 +100,6 @@ function it_sets_size_for_new_file(Filesystem $filesystem) $this->getSize()->shouldReturn(21); } - /** - * @param \Gaufrette\Filesystem $filesystem - */ function it_calculates_size_from_filesystem(Filesystem $filesystem) { $filesystem->size('filename')->shouldBeCalled()->willReturn(12); @@ -138,9 +107,6 @@ function it_calculates_size_from_filesystem(Filesystem $filesystem) $this->getSize()->shouldReturn(12); } - /** - * @param \Gaufrette\Filesystem $filesystem - */ function it_allows_to_set_size(Filesystem $filesystem) { $filesystem->read('filename')->shouldNotBeCalled(); @@ -149,9 +115,6 @@ function it_allows_to_set_size(Filesystem $filesystem) $this->getSize()->shouldReturn(21); } - /** - * @param \Gaufrette\Filesystem $filesystem - */ function it_gets_zero_size_when_file_not_found(Filesystem $filesystem) { $filesystem->size('filename')->willThrow(new \Gaufrette\Exception\FileNotFound('filename')); @@ -159,9 +122,6 @@ function it_gets_zero_size_when_file_not_found(Filesystem $filesystem) $this->getSize()->shouldReturn(0); } - /** - * @param \Gaufrette\Filesystem $filesystem - */ function it_check_if_file_with_key_exists_in_filesystem(Filesystem $filesystem) { $filesystem->has('filename')->willReturn(true); @@ -171,18 +131,12 @@ function it_check_if_file_with_key_exists_in_filesystem(Filesystem $filesystem) $this->exists()->shouldReturn(false); } - /** - * @param \Gaufrette\Filesystem $filesystem - */ function it_deletes_file_from_filesystem(Filesystem $filesystem) { $filesystem->delete('filename')->shouldBeCalled()->willReturn(true); $this->delete()->shouldReturn(true); } - /** - * @param \Gaufrette\Filesystem $filesystem - */ function it_renames_file_from_filesystem(Filesystem $filesystem) { $filesystem->rename('filename', 'newname')->shouldBeCalled(); diff --git a/spec/Gaufrette/FilesystemMapSpec.php b/spec/Gaufrette/FilesystemMapSpec.php index 358b94241..33263d1c3 100644 --- a/spec/Gaufrette/FilesystemMapSpec.php +++ b/spec/Gaufrette/FilesystemMapSpec.php @@ -12,9 +12,6 @@ function it_is_initializable() $this->shouldHaveType('Gaufrette\FilesystemMap'); } - /** - * @param Gaufrette\Filesystem $filesystem - */ function it_checks_if_has_mapped_filesystem(Filesystem $filesystem) { $this->set('some', $filesystem); @@ -22,9 +19,6 @@ function it_checks_if_has_mapped_filesystem(Filesystem $filesystem) $this->has('other')->shouldReturn(false); } - /** - * @param Gaufrette\Filesystem $filesystem - */ function it_sets_mapped_filesystem(Filesystem $filesystem) { $this->set('some', $filesystem); @@ -39,9 +33,6 @@ function it_fails_when_get_filesystem_which_was_not_mapped() ; } - /** - * @param Gaufrette\Filesystem $filesystem - */ function it_removes_mapped_filesystem(Filesystem $filesystem) { $this->set('some', $filesystem); @@ -58,9 +49,6 @@ function it_fails_when_try_to_remove_filesystem_which_was_not_mapped() ; } - /** - * @param Gaufrette\Filesystem $filesystem - */ function it_removes_all_filesystems(Filesystem $filesystem) { $this->set('some', $filesystem); diff --git a/spec/Gaufrette/FilesystemSpec.php b/spec/Gaufrette/FilesystemSpec.php index ad8d66405..533b744f5 100644 --- a/spec/Gaufrette/FilesystemSpec.php +++ b/spec/Gaufrette/FilesystemSpec.php @@ -18,9 +18,6 @@ interface ExtendedAdapter extends \Gaufrette\Adapter, class FilesystemSpec extends ObjectBehavior { - /** - * @param \Gaufrette\Adapter $adapter - */ function let(Adapter $adapter) { $this->beConstructedWith($adapter); @@ -32,17 +29,11 @@ function it_is_initializable() $this->shouldBeAnInstanceOf('Gaufrette\FilesystemInterface'); } - /** - * @param \Gaufrette\Adapter $adapter - */ function it_gives_access_to_adapter(Adapter $adapter) { $this->getAdapter()->shouldBe($adapter); } - /** - * @param \Gaufrette\Adapter $adapter - */ function it_check_if_file_exists_using_adapter(Adapter $adapter) { $adapter->exists('filename')->willReturn(true); @@ -52,9 +43,6 @@ function it_check_if_file_exists_using_adapter(Adapter $adapter) $this->has('otherFilename')->shouldReturn(false); } - /** - * @param \Gaufrette\Adapter $adapter - */ function it_renames_file(Adapter $adapter) { $adapter->exists('filename')->shouldBeCalled()->willReturn(true); @@ -64,9 +52,6 @@ function it_renames_file(Adapter $adapter) $this->rename('filename', 'otherFilename')->shouldReturn(true); } - /** - * @param \Gaufrette\Adapter $adapter - */ function it_fails_when_renamed_source_file_does_not_exist(Adapter $adapter) { $adapter->exists('filename')->willReturn(false); @@ -77,9 +62,6 @@ function it_fails_when_renamed_source_file_does_not_exist(Adapter $adapter) ; } - /** - * @param \Gaufrette\Adapter $adapter - */ function it_fails_when_renamed_target_file_exists(Adapter $adapter) { $adapter->exists('filename')->willReturn(true); @@ -91,9 +73,6 @@ function it_fails_when_renamed_target_file_exists(Adapter $adapter) ; } - /** - * @param \Gaufrette\Adapter $adapter - */ function it_fails_when_rename_is_not_successful(Adapter $adapter) { $adapter->exists('filename')->willReturn(true); @@ -106,9 +85,6 @@ function it_fails_when_rename_is_not_successful(Adapter $adapter) ; } - /** - * @param \Gaufrette\Adapter $adapter - */ function it_creates_file_object_for_key(Adapter $adapter) { $adapter->exists('filename')->willReturn(true); @@ -116,9 +92,6 @@ function it_creates_file_object_for_key(Adapter $adapter) $this->get('filename')->shouldBeAnInstanceOf('Gaufrette\File'); } - /** - * @param \Gaufrette\Adapter $adapter - */ function it_does_not_get_file_object_when_file_with_key_does_not_exist(Adapter $adapter) { $adapter->exists('filename')->willReturn(false); @@ -129,9 +102,6 @@ function it_does_not_get_file_object_when_file_with_key_does_not_exist(Adapter $ ; } - /** - * @param \Gaufrette\Adapter $adapter - */ function it_gets_file_object_when_file_does_not_exist_but_can_be_created(Adapter $adapter) { $adapter->exists('filename')->willReturn(false); @@ -139,10 +109,6 @@ function it_gets_file_object_when_file_does_not_exist_but_can_be_created(Adapter $this->get('filename', true)->shouldBeAnInstanceOf('Gaufrette\File'); } - /** - * @param \spec\Gaufrette\ExtendedAdapter $extendedAdapter - * @param \Gaufrette\File $file - */ function it_delegates_file_creation_to_adapter_when_adapter_is_file_factory(ExtendedAdapter $extendedAdapter, File $file) { $this->beConstructedWith($extendedAdapter); @@ -152,9 +118,6 @@ function it_delegates_file_creation_to_adapter_when_adapter_is_file_factory(Exte $this->get('filename')->shouldBe($file); } - /** - * @param \Gaufrette\Adapter $adapter - */ function it_writes_content_to_new_file(Adapter $adapter) { $adapter->exists('filename')->shouldBeCalled()->willReturn(false); @@ -163,9 +126,6 @@ function it_writes_content_to_new_file(Adapter $adapter) $this->write('filename', 'some content to write')->shouldReturn(21); } - /** - * @param \Gaufrette\Adapter $adapter - */ function it_updates_content_of_file(Adapter $adapter) { $adapter->write('filename', 'some content to write')->shouldBeCalled()->willReturn(21); @@ -173,9 +133,6 @@ function it_updates_content_of_file(Adapter $adapter) $this->write('filename', 'some content to write', true)->shouldReturn(21); } - /** - * @param \Gaufrette\Adapter $adapter - */ function it_does_not_update_content_of_file_when_file_cannot_be_overwriten(Adapter $adapter) { $adapter->exists('filename')->willReturn(true); @@ -187,9 +144,6 @@ function it_does_not_update_content_of_file_when_file_cannot_be_overwriten(Adapt ; } - /** - * @param \Gaufrette\Adapter $adapter - */ function it_fails_when_write_is_not_successful(Adapter $adapter) { $adapter->exists('filename')->willReturn(false); @@ -201,9 +155,6 @@ function it_fails_when_write_is_not_successful(Adapter $adapter) ; } - /** - * @param \Gaufrette\Adapter $adapter - */ function it_read_file(Adapter $adapter) { $adapter->exists('filename')->shouldBeCalled()->willReturn(true); @@ -212,9 +163,6 @@ function it_read_file(Adapter $adapter) $this->read('filename')->shouldReturn('Some content'); } - /** - * @param \Gaufrette\Adapter $adapter - */ function it_does_not_read_file_which_does_not_exist(Adapter $adapter) { $adapter->exists('filename')->willReturn(false); @@ -224,9 +172,6 @@ function it_does_not_read_file_which_does_not_exist(Adapter $adapter) ->duringRead('filename'); } - /** - * @param \Gaufrette\Adapter $adapter - */ function it_fails_when_read_is_not_successful(Adapter $adapter) { $adapter->exists('filename')->willReturn(true); @@ -238,9 +183,6 @@ function it_fails_when_read_is_not_successful(Adapter $adapter) ; } - /** - * @param \Gaufrette\Adapter $adapter - */ function it_deletes_file(Adapter $adapter) { $adapter->exists('filename')->shouldBeCalled()->willReturn(true); @@ -249,9 +191,6 @@ function it_deletes_file(Adapter $adapter) $this->delete('filename')->shouldReturn(true); } - /** - * @param \Gaufrette\Adapter $adapter - */ function it_does_not_delete_file_which_does_not_exist(Adapter $adapter) { $adapter->exists('filename')->willReturn(false); @@ -262,9 +201,6 @@ function it_does_not_delete_file_which_does_not_exist(Adapter $adapter) ; } - /** - * @param \Gaufrette\Adapter $adapter - */ function it_fails_when_delete_is_not_successful(Adapter $adapter) { $adapter->exists('filename')->willReturn(true); @@ -276,9 +212,6 @@ function it_fails_when_delete_is_not_successful(Adapter $adapter) ; } - /** - * @param \Gaufrette\Adapter $adapter - */ function it_should_get_all_keys(Adapter $adapter) { $keys = ['filename', 'filename1', 'filename2']; @@ -287,9 +220,6 @@ function it_should_get_all_keys(Adapter $adapter) $this->keys()->shouldReturn($keys); } - /** - * @param \Gaufrette\Adapter $adapter - */ function it_match_listed_keys_using_specified_pattern(Adapter $adapter) { $keys = ['filename', 'filename1', 'filename2', 'testKey', 'KeyTest', 'testkey']; @@ -317,9 +247,6 @@ function it_match_listed_keys_using_specified_pattern(Adapter $adapter) ); } - /** - * @param \Gaufrette\Adapter $adapter - */ function it_listing_directories_using_adapter_is_directory_method(Adapter $adapter) { $keys = ['filename', 'filename1', 'filename2', 'testKey', 'KeyTest', 'testkey']; @@ -353,9 +280,6 @@ function it_listing_directories_using_adapter_is_directory_method(Adapter $adapt ); } - /** - * @param \Gaufrette\Adapter $adapter - */ function it_gets_mtime_of_file_using_adapter(Adapter $adapter) { $adapter->exists('filename')->willReturn(true); @@ -364,9 +288,6 @@ function it_gets_mtime_of_file_using_adapter(Adapter $adapter) $this->mtime('filename')->shouldReturn(1234567); } - /** - * @param \Gaufrette\Adapter $adapter - */ function it_does_not_get_mtime_of_file_which_does_not_exist(Adapter $adapter) { $adapter->exists('filename')->willReturn(false); @@ -377,9 +298,6 @@ function it_does_not_get_mtime_of_file_which_does_not_exist(Adapter $adapter) ; } - /** - * @param \Gaufrette\Adapter $adapter - */ function it_calculates_file_checksum(Adapter $adapter) { $adapter->exists('filename')->shouldBeCalled()->willReturn(true); @@ -388,9 +306,6 @@ function it_calculates_file_checksum(Adapter $adapter) $this->checksum('filename')->shouldReturn(md5('some content')); } - /** - * @param \Gaufrette\Adapter $adapter - */ function it_does_not_calculate_checksum_of_file_which_does_not_exist(Adapter $adapter) { $adapter->exists('filename')->shouldBeCalled()->willReturn(false); @@ -400,9 +315,6 @@ function it_does_not_calculate_checksum_of_file_which_does_not_exist(Adapter $ad ->duringChecksum('filename'); } - /** - * @param \spec\Gaufrette\ExtendedAdapter $extendedAdapter - */ function it_delegates_checksum_calculation_to_adapter_when_adapter_is_checksum_calculator(ExtendedAdapter $extendedAdapter) { $this->beConstructedWith($extendedAdapter); @@ -413,9 +325,6 @@ function it_delegates_checksum_calculation_to_adapter_when_adapter_is_checksum_c $this->checksum('filename')->shouldReturn(12); } - /** - * @param \spec\Gaufrette\ExtendedAdapter $extendedAdapter - */ function it_delegates_mime_type_resolution_to_adapter_when_adapter_is_mime_type_provider(ExtendedAdapter $extendedAdapter) { $this->beConstructedWith($extendedAdapter); diff --git a/spec/Gaufrette/StreamWrapperSpec.php b/spec/Gaufrette/StreamWrapperSpec.php index 00eafce40..613d2b4b8 100644 --- a/spec/Gaufrette/StreamWrapperSpec.php +++ b/spec/Gaufrette/StreamWrapperSpec.php @@ -10,11 +10,6 @@ class StreamWrapperSpec extends ObjectBehavior { - /** - * @param \Gaufrette\FilesystemMap $map - * @param \Gaufrette\Filesystem $filesystem - * @param \Gaufrette\Stream $stream - */ function let(FilesystemMap $map, Filesystem $filesystem, Stream $stream) { $filesystem->createStream('filename')->willReturn($stream); @@ -27,9 +22,6 @@ function it_is_initializable() $this->shouldHaveType('Gaufrette\StreamWrapper'); } - /** - * @param \Gaufrette\Stream $stream - */ function it_opens_stream(Stream $stream) { $stream->open(Argument::any())->willReturn(true); @@ -57,9 +49,6 @@ function it_does_not_read_from_stream_when_is_not_opened() $this->stream_read(10)->shouldReturn(false); } - /** - * @param \Gaufrette\Stream $stream - */ function it_does_not_read_from_stream(Stream $stream) { $stream->open(Argument::any())->willReturn(true); @@ -74,9 +63,6 @@ function it_does_not_write_to_stream_when_is_not_opened() $this->stream_write('some content')->shouldReturn(0); } - /** - * @param \Gaufrette\Stream $stream - */ function it_writes_to_stream(Stream $stream) { $stream->open(Argument::any())->willReturn(true); @@ -86,18 +72,12 @@ function it_writes_to_stream(Stream $stream) $this->stream_write('some content')->shouldReturn(12); } - /** - * @param \Gaufrette\Stream $stream - */ function it_does_not_close_stream_when_is_not_opened($stream) { $stream->close()->shouldNotBeCalled(); $this->stream_close(); } - /** - * @param \Gaufrette\Stream $stream - */ function it_closes_stream(Stream $stream) { $stream->open(Argument::any())->willReturn(true); @@ -106,18 +86,12 @@ function it_closes_stream(Stream $stream) $this->stream_close(); } - /** - * @param \Gaufrette\Stream $stream - */ function it_does_not_flush_stream_when_is_not_opened(Stream $stream) { $stream->flush()->shouldNotBeCalled(); $this->stream_flush(); } - /** - * @param \Gaufrette\Stream $stream - */ function it_flushes_stream(Stream $stream) { $stream->open(Argument::any())->willReturn(true); @@ -126,18 +100,12 @@ function it_flushes_stream(Stream $stream) $this->stream_flush(); } - /** - * @param \Gaufrette\Stream $stream - */ function it_does_not_seek_in_stream_when_is_not_opened(Stream $stream) { $stream->seek(12, SEEK_SET)->shouldNotBeCalled(); $this->stream_seek(12, SEEK_SET); } - /** - * @param \Gaufrette\Stream $stream - */ function it_seeks_in_stream(Stream $stream) { $stream->open(Argument::any())->willReturn(true); @@ -146,18 +114,12 @@ function it_seeks_in_stream(Stream $stream) $this->stream_seek(12, SEEK_SET)->shouldReturn(true); } - /** - * @param \Gaufrette\Stream $stream - */ function it_does_not_tell_about_position_in_stream_when_is_not_opened(Stream $stream) { $stream->tell()->shouldNotBeCalled(); $this->stream_tell(); } - /** - * @param \Gaufrette\Stream $stream - */ function it_does_tell_about_position_in_stream(Stream $stream) { $stream->open(Argument::any())->willReturn(true); @@ -166,18 +128,12 @@ function it_does_tell_about_position_in_stream(Stream $stream) $this->stream_tell()->shouldReturn(12); } - /** - * @param \Gaufrette\Stream $stream - */ function it_does_not_mark_as_eof_if_stream_is_not_opened(Stream $stream) { $stream->eof()->shouldNotBeCalled(); $this->stream_eof(); } - /** - * @param \Gaufrette\Stream $stream - */ function it_checks_if_eof(Stream $stream) { $stream->open(Argument::any())->willReturn(true); @@ -195,9 +151,6 @@ function it_does_not_get_stat_when_is_not_open() $this->stream_stat()->shouldReturn(false); } - /** - * @param \Gaufrette\Stream $stream - */ function it_stats_file(Stream $stream) { $stat = [ @@ -222,9 +175,6 @@ function it_stats_file(Stream $stream) $this->stream_stat()->shouldReturn($stat); } - /** - * @param \Gaufrette\Stream $stream - */ function it_should_stat_from_url(Stream $stream) { $stat = [ @@ -248,10 +198,6 @@ function it_should_stat_from_url(Stream $stream) $this->url_stat('gaufrette://some/filename', STREAM_URL_STAT_LINK)->shouldReturn($stat); } - /** - * @param \Gaufrette\Filesystem $stream - * @param \Gaufrette\Stream $stream - */ function it_stats_even_if_it_cannot_be_open(Filesystem $filesystem, Stream $stream) { $filesystem->createStream('dir/')->willReturn($stream); @@ -260,18 +206,12 @@ function it_stats_even_if_it_cannot_be_open(Filesystem $filesystem, Stream $stre $this->url_stat('gaufrette://some/dir/', STREAM_URL_STAT_LINK)->shouldReturn(['mode' => 16893]); } - /** - * @param \Gaufrette\Stream $stream - */ function it_does_not_unlink_when_cannot_open(Stream $stream) { $stream->open(Argument::any())->willThrow(new \RuntimeException); $this->unlink('gaufrette://some/filename')->shouldReturn(false); } - /** - * @param \Gaufrette\Stream $stream - */ function it_unlinks_file(Stream $stream) { $stream->open(Argument::any())->willReturn(true); @@ -285,9 +225,6 @@ function it_does_not_cast_stream_if_is_not_opened() $this->stream_cast(STREAM_CAST_FOR_SELECT)->shouldReturn(false); } - /** - * @param \Gaufrette\Stream $stream - */ function it_casts_stream(Stream $stream) { $stream->open(Argument::any())->willReturn(true); diff --git a/tests/Gaufrette/Functional/Adapter/AsyncAwsS3Test.php b/tests/Gaufrette/Functional/Adapter/AsyncAwsS3Test.php index 559010188..ca1db955e 100644 --- a/tests/Gaufrette/Functional/Adapter/AsyncAwsS3Test.php +++ b/tests/Gaufrette/Functional/Adapter/AsyncAwsS3Test.php @@ -9,11 +9,9 @@ class AsyncAwsS3Test extends FunctionalTestCase { - /** @var string */ - private $bucket; + private string $bucket; - /** @var SimpleS3Client */ - private $client; + private SimpleS3Client $client; protected function setUp(): void { diff --git a/tests/Gaufrette/Functional/Adapter/AwsS3Test.php b/tests/Gaufrette/Functional/Adapter/AwsS3Test.php index 037ba72a3..0b79171c2 100644 --- a/tests/Gaufrette/Functional/Adapter/AwsS3Test.php +++ b/tests/Gaufrette/Functional/Adapter/AwsS3Test.php @@ -8,14 +8,11 @@ class AwsS3Test extends FunctionalTestCase { - /** @var int */ - private static $SDK_VERSION; + private static int $SDK_VERSION; - /** @var string */ - private $bucket; + private string $bucket; - /** @var S3Client */ - private $client; + private S3Client $client; protected function setUp(): void { diff --git a/tests/Gaufrette/Functional/Adapter/AzureBlobStorageTest.php b/tests/Gaufrette/Functional/Adapter/AzureBlobStorageTest.php index 88fda4301..521c2d224 100644 --- a/tests/Gaufrette/Functional/Adapter/AzureBlobStorageTest.php +++ b/tests/Gaufrette/Functional/Adapter/AzureBlobStorageTest.php @@ -13,10 +13,10 @@ class AzureBlobStorageTest extends FunctionalTestCase { /** @var string Name of the Azure container used */ - private $container; + private string $container; /** @var AzureBlobStorage */ - private $adapter; + private AzureBlobStorage $adapter; protected function setUp(): void { diff --git a/tests/Gaufrette/Functional/Adapter/AzureMultiContainerBlobStorageTest.php b/tests/Gaufrette/Functional/Adapter/AzureMultiContainerBlobStorageTest.php index f01989aae..d8a678336 100644 --- a/tests/Gaufrette/Functional/Adapter/AzureMultiContainerBlobStorageTest.php +++ b/tests/Gaufrette/Functional/Adapter/AzureMultiContainerBlobStorageTest.php @@ -13,9 +13,9 @@ */ class AzureMultiContainerBlobStorageTest extends FunctionalTestCase { - private $adapter; + private AzureBlobStorage $adapter; - private $containers = []; + private array $containers = []; protected function setUp(): void { diff --git a/tests/Gaufrette/Functional/Adapter/DoctrineDbalTest.php b/tests/Gaufrette/Functional/Adapter/DoctrineDbalTest.php index aa9d8a39f..581acb791 100644 --- a/tests/Gaufrette/Functional/Adapter/DoctrineDbalTest.php +++ b/tests/Gaufrette/Functional/Adapter/DoctrineDbalTest.php @@ -2,14 +2,14 @@ namespace Gaufrette\Functional\Adapter; +use Doctrine\DBAL\Connection; use Doctrine\DBAL\DriverManager; use Gaufrette\Adapter\DoctrineDbal; use Gaufrette\Filesystem; class DoctrineDbalTest extends FunctionalTestCase { - /** @var \Doctrine\DBAL\Connection */ - private $connection; + private Connection $connection; public static function setUpBeforeClass(): void { diff --git a/tests/Gaufrette/Functional/Adapter/FunctionalTestCase.php b/tests/Gaufrette/Functional/Adapter/FunctionalTestCase.php index a78aa0edf..0e29888c4 100644 --- a/tests/Gaufrette/Functional/Adapter/FunctionalTestCase.php +++ b/tests/Gaufrette/Functional/Adapter/FunctionalTestCase.php @@ -8,10 +8,7 @@ abstract class FunctionalTestCase extends TestCase { - /** - * @var Filesystem - */ - protected $filesystem; + protected Filesystem $filesystem; public function getAdapterName() { diff --git a/tests/Gaufrette/Functional/Adapter/LocalTest.php b/tests/Gaufrette/Functional/Adapter/LocalTest.php index 4b319a7be..e4400810a 100644 --- a/tests/Gaufrette/Functional/Adapter/LocalTest.php +++ b/tests/Gaufrette/Functional/Adapter/LocalTest.php @@ -7,7 +7,7 @@ class LocalTest extends FunctionalTestCase { - private $directory; + private string $directory; protected function setUp(): void { diff --git a/tests/Gaufrette/Functional/Adapter/PhpseclibSftpTest.php b/tests/Gaufrette/Functional/Adapter/PhpseclibSftpTest.php index 9a50ab685..d840a91fb 100644 --- a/tests/Gaufrette/Functional/Adapter/PhpseclibSftpTest.php +++ b/tests/Gaufrette/Functional/Adapter/PhpseclibSftpTest.php @@ -8,11 +8,9 @@ class PhpseclibSftpTest extends FunctionalTestCase { - /** @var SFTP */ - private $sftp; + private SFTP $sftp; - /** @var string */ - private $baseDir; + private string $baseDir; protected function setUp(): void { diff --git a/tests/Gaufrette/Functional/FileStream/FunctionalTestCase.php b/tests/Gaufrette/Functional/FileStream/FunctionalTestCase.php index 4a041436d..c41ae9501 100644 --- a/tests/Gaufrette/Functional/FileStream/FunctionalTestCase.php +++ b/tests/Gaufrette/Functional/FileStream/FunctionalTestCase.php @@ -2,12 +2,13 @@ namespace Gaufrette\Functional\FileStream; +use Gaufrette\Filesystem; use Gaufrette\StreamWrapper; use PHPUnit\Framework\TestCase; abstract class FunctionalTestCase extends TestCase { - protected $filesystem; + protected Filesystem $filesystem; /** * @test diff --git a/tests/Gaufrette/Functional/FileStream/LocalTest.php b/tests/Gaufrette/Functional/FileStream/LocalTest.php index 49e5a8e60..8a23f1cb7 100644 --- a/tests/Gaufrette/Functional/FileStream/LocalTest.php +++ b/tests/Gaufrette/Functional/FileStream/LocalTest.php @@ -7,7 +7,7 @@ class LocalTest extends FunctionalTestCase { - protected $directory; + protected string $directory; protected function setUp(): void { From c282e475edb82ca1e66751c45897e549806883d0 Mon Sep 17 00:00:00 2001 From: Sophie Roussel Date: Fri, 26 May 2023 15:23:43 +0200 Subject: [PATCH 24/48] fix: review --- spec/Gaufrette/Adapter/functions.php | 6 +++--- tests/Gaufrette/Functional/Adapter/AzureBlobStorageTest.php | 3 +-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/spec/Gaufrette/Adapter/functions.php b/spec/Gaufrette/Adapter/functions.php index 77c68131a..bfc066742 100644 --- a/spec/Gaufrette/Adapter/functions.php +++ b/spec/Gaufrette/Adapter/functions.php @@ -30,7 +30,7 @@ function extension_loaded() return $extensionLoaded; } -function opendir() +function opendir(string $url) { return true; } @@ -40,7 +40,7 @@ function apc_fetch(string $path) return sprintf('%s content', $path); } -function apc_store(string $path) +function apc_store(string $path, mixed $content, int $ttl) { if ('prefix-apc-test/invalid' === $path) { return false; @@ -58,7 +58,7 @@ function apc_delete(string $path) return true; } -function apc_exists(string $path) +function apc_exists(mixed $path) { if ('prefix-apc-test/invalid' === $path) { return false; diff --git a/tests/Gaufrette/Functional/Adapter/AzureBlobStorageTest.php b/tests/Gaufrette/Functional/Adapter/AzureBlobStorageTest.php index 521c2d224..d21c01edf 100644 --- a/tests/Gaufrette/Functional/Adapter/AzureBlobStorageTest.php +++ b/tests/Gaufrette/Functional/Adapter/AzureBlobStorageTest.php @@ -12,10 +12,9 @@ */ class AzureBlobStorageTest extends FunctionalTestCase { - /** @var string Name of the Azure container used */ + /** Name of the Azure container used */ private string $container; - /** @var AzureBlobStorage */ private AzureBlobStorage $adapter; protected function setUp(): void From af1fda7066c5c4b2bbde3f6d10737968b6739fef Mon Sep 17 00:00:00 2001 From: PedroTroller Date: Mon, 23 Oct 2023 15:40:46 +0200 Subject: [PATCH 25/48] refactor: fix Ftp and StreamWrapper errors --- src/Gaufrette/Adapter/Ftp.php | 2 +- src/Gaufrette/StreamWrapper.php | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Gaufrette/Adapter/Ftp.php b/src/Gaufrette/Adapter/Ftp.php index 3c420b29e..f279efd42 100644 --- a/src/Gaufrette/Adapter/Ftp.php +++ b/src/Gaufrette/Adapter/Ftp.php @@ -561,7 +561,7 @@ public function close(): void /** * @param array|false $info */ - private function isLinuxListing(array $info): bool + private function isLinuxListing(bool|array $info): bool { return count($info) >= 9; } diff --git a/src/Gaufrette/StreamWrapper.php b/src/Gaufrette/StreamWrapper.php index d101ce933..5eb052a9a 100644 --- a/src/Gaufrette/StreamWrapper.php +++ b/src/Gaufrette/StreamWrapper.php @@ -202,6 +202,7 @@ public function unlink(string $path): bool /** * @return resource|false + * @param STREAM_CAST_FOR_SELECT|STREAM_CAST_AS_STREAM $castAs */ public function stream_cast(int $castAs) { From fd3ac321c492f61e6bc6af01ec6121a7ee6226c9 Mon Sep 17 00:00:00 2001 From: PedroTroller Date: Mon, 23 Oct 2023 15:57:52 +0200 Subject: [PATCH 26/48] refactor: fix lvl5 errors for AwsS3 and AzureBlobStorage adapters --- src/Gaufrette/Adapter/AwsS3.php | 2 +- src/Gaufrette/Adapter/AzureBlobStorage.php | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Gaufrette/Adapter/AwsS3.php b/src/Gaufrette/Adapter/AwsS3.php index d6e5074f3..ba9c3f37b 100644 --- a/src/Gaufrette/Adapter/AwsS3.php +++ b/src/Gaufrette/Adapter/AwsS3.php @@ -45,7 +45,7 @@ public function __construct( /** * {@inheritdoc} */ - public function setMetadata(string $key, array $content): void + public function setMetadata(string $key, array $metadata): void { // BC with AmazonS3 adapter if (isset($metadata['contentType'])) { diff --git a/src/Gaufrette/Adapter/AzureBlobStorage.php b/src/Gaufrette/Adapter/AzureBlobStorage.php index fe4611a84..c24ffa5a5 100644 --- a/src/Gaufrette/Adapter/AzureBlobStorage.php +++ b/src/Gaufrette/Adapter/AzureBlobStorage.php @@ -5,6 +5,7 @@ use Gaufrette\Adapter; use Gaufrette\Util; use Gaufrette\Adapter\AzureBlobStorage\BlobProxyFactoryInterface; +use MicrosoftAzure\Storage\Blob\Internal\IBlob; use MicrosoftAzure\Storage\Blob\Models\Blob; use MicrosoftAzure\Storage\Blob\Models\BlobServiceOptions; use MicrosoftAzure\Storage\Blob\Models\Container; @@ -28,7 +29,7 @@ class AzureBlobStorage implements Adapter, MetadataSupporter, SizeCalculator, Ch const ERROR_CONTAINER_ALREADY_EXISTS = 'ContainerAlreadyExists'; const ERROR_CONTAINER_NOT_FOUND = 'ContainerNotFound'; - protected \MicrosoftAzure\Storage\Blob\Internal\IBlob $blobProxy; + protected ?IBlob $blobProxy = null; protected bool $multiContainerMode = false; @@ -479,7 +480,7 @@ private function guessContentType($content): string } /** - * @return array + * @return array{string, string} */ private function tokenizeKey(string $key): array { From 06d948ccd2ed907b8075e5f5f349953da3ece970 Mon Sep 17 00:00:00 2001 From: PedroTroller Date: Mon, 23 Oct 2023 16:00:37 +0200 Subject: [PATCH 27/48] ci: upgrade phpstan to 1.10.39 --- .github/workflows/static.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/static.yml b/.github/workflows/static.yml index 3f7c8c86d..19c32b905 100644 --- a/.github/workflows/static.yml +++ b/.github/workflows/static.yml @@ -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 From dd628b0759a9693be4a5f71547abaa4da259a174 Mon Sep 17 00:00:00 2001 From: PedroTroller Date: Mon, 23 Oct 2023 16:02:45 +0200 Subject: [PATCH 28/48] test: fix filesystem typehint in phpunit tests --- tests/Gaufrette/Functional/Adapter/FunctionalTestCase.php | 2 +- tests/Gaufrette/Functional/FileStream/FunctionalTestCase.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Gaufrette/Functional/Adapter/FunctionalTestCase.php b/tests/Gaufrette/Functional/Adapter/FunctionalTestCase.php index 0e29888c4..204f77806 100644 --- a/tests/Gaufrette/Functional/Adapter/FunctionalTestCase.php +++ b/tests/Gaufrette/Functional/Adapter/FunctionalTestCase.php @@ -8,7 +8,7 @@ abstract class FunctionalTestCase extends TestCase { - protected Filesystem $filesystem; + protected ?Filesystem $filesystem = null; public function getAdapterName() { diff --git a/tests/Gaufrette/Functional/FileStream/FunctionalTestCase.php b/tests/Gaufrette/Functional/FileStream/FunctionalTestCase.php index c41ae9501..112b71c1f 100644 --- a/tests/Gaufrette/Functional/FileStream/FunctionalTestCase.php +++ b/tests/Gaufrette/Functional/FileStream/FunctionalTestCase.php @@ -8,7 +8,7 @@ abstract class FunctionalTestCase extends TestCase { - protected Filesystem $filesystem; + protected ?Filesystem $filesystem = null; /** * @test From b3fa95deb53d9785c28caa78ec2e01f4f4e3522b Mon Sep 17 00:00:00 2001 From: PedroTroller Date: Mon, 23 Oct 2023 16:20:16 +0200 Subject: [PATCH 29/48] fix: fix phpspec tests --- spec/Gaufrette/Adapter/DoctrineDbalSpec.php | 2 +- spec/Gaufrette/Adapter/FlysystemSpec.php | 2 +- src/Gaufrette/Adapter/Flysystem.php | 12 +++++++++++- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/spec/Gaufrette/Adapter/DoctrineDbalSpec.php b/spec/Gaufrette/Adapter/DoctrineDbalSpec.php index e78a3f7f0..e55c73c32 100644 --- a/spec/Gaufrette/Adapter/DoctrineDbalSpec.php +++ b/spec/Gaufrette/Adapter/DoctrineDbalSpec.php @@ -154,7 +154,7 @@ function it_calculates_checksum(Connection $connection) ->$method('SELECT "checksum" FROM "someTableName" WHERE "key" = :key', ['key' => 'filename']) ->willReturn(1234); - $this->checksum('filename')->shouldReturn(1234); + $this->checksum('filename')->shouldReturn("1234"); } function it_gets_mtime(Connection $connection) diff --git a/spec/Gaufrette/Adapter/FlysystemSpec.php b/spec/Gaufrette/Adapter/FlysystemSpec.php index 26ce52708..bf0c0031f 100644 --- a/spec/Gaufrette/Adapter/FlysystemSpec.php +++ b/spec/Gaufrette/Adapter/FlysystemSpec.php @@ -34,7 +34,7 @@ function it_writes_file(AdapterInterface $adapter, Config $config) { $adapter->write('filename', 'Hello.', $config)->willReturn([]); - $this->write('filename', 'Hello.')->shouldReturn([]); + $this->write('filename', 'Hello.')->shouldReturn(0); } function it_checks_if_file_exists(AdapterInterface $adapter) diff --git a/src/Gaufrette/Adapter/Flysystem.php b/src/Gaufrette/Adapter/Flysystem.php index cfabad981..fc8dc53df 100644 --- a/src/Gaufrette/Adapter/Flysystem.php +++ b/src/Gaufrette/Adapter/Flysystem.php @@ -37,7 +37,17 @@ public function read(string $key): string|bool */ public function write(string $key, mixed $content): int|bool { - return $this->adapter->write($key, $content, $this->config); + $metadata = $this->adapter->write($key, $content, $this->config); + + if (false === $metadata) { + return false; + } + + if (is_int($metadata['size'] ?? 0)) { + return $metadata['size'] ?? 0; + } + + return 0; } /** From 4fbaebf4d621d8a4b15e92c572db8139bf53e557 Mon Sep 17 00:00:00 2001 From: PedroTroller Date: Fri, 27 Oct 2023 15:05:01 +0200 Subject: [PATCH 30/48] refactor: apply cs fixing --- .php-cs-fixer.dist.php | 2 +- spec/Gaufrette/Adapter/DoctrineDbalSpec.php | 2 +- src/Gaufrette/Adapter/GoogleCloudStorage.php | 8 ++++---- src/Gaufrette/Adapter/InMemory.php | 2 +- src/Gaufrette/Adapter/Local.php | 8 ++++---- src/Gaufrette/Adapter/PhpseclibSftp.php | 1 - src/Gaufrette/Util/Size.php | 1 + 7 files changed, 12 insertions(+), 12 deletions(-) diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index d68945fde..2f829560f 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -21,7 +21,7 @@ 'no_break_comment' => false, 'no_extra_blank_lines' => true, 'no_spaces_around_offset' => true, - 'no_trailing_comma_in_singleline_array' => true, + 'no_trailing_comma_in_singleline' => true, 'no_unused_imports' => true, 'no_useless_else' => true, 'no_useless_return' => true, diff --git a/spec/Gaufrette/Adapter/DoctrineDbalSpec.php b/spec/Gaufrette/Adapter/DoctrineDbalSpec.php index e55c73c32..259e09aa8 100644 --- a/spec/Gaufrette/Adapter/DoctrineDbalSpec.php +++ b/spec/Gaufrette/Adapter/DoctrineDbalSpec.php @@ -154,7 +154,7 @@ function it_calculates_checksum(Connection $connection) ->$method('SELECT "checksum" FROM "someTableName" WHERE "key" = :key', ['key' => 'filename']) ->willReturn(1234); - $this->checksum('filename')->shouldReturn("1234"); + $this->checksum('filename')->shouldReturn('1234'); } function it_gets_mtime(Connection $connection) diff --git a/src/Gaufrette/Adapter/GoogleCloudStorage.php b/src/Gaufrette/Adapter/GoogleCloudStorage.php index d775926dd..04f3102bb 100644 --- a/src/Gaufrette/Adapter/GoogleCloudStorage.php +++ b/src/Gaufrette/Adapter/GoogleCloudStorage.php @@ -269,9 +269,9 @@ public function isDirectory(string $key): bool } /** - * @return array - * @throws RuntimeException - * @throws ReflectionException + * @return array + * @throws RuntimeException + * @throws ReflectionException */ public function listKeys(string $prefix = ''): array { @@ -304,7 +304,7 @@ public function listKeys(string $prefix = ''): array } /** - * @param array $content + * @param array $content */ public function setMetadata(string $key, array $content): void { diff --git a/src/Gaufrette/Adapter/InMemory.php b/src/Gaufrette/Adapter/InMemory.php index 53a7cb88d..7f76b3881 100644 --- a/src/Gaufrette/Adapter/InMemory.php +++ b/src/Gaufrette/Adapter/InMemory.php @@ -95,7 +95,7 @@ public function exists(string $key): bool } /** - * @return array + * @return array */ public function keys(): array { diff --git a/src/Gaufrette/Adapter/Local.php b/src/Gaufrette/Adapter/Local.php index 89eb51b82..e19af1a1b 100644 --- a/src/Gaufrette/Adapter/Local.php +++ b/src/Gaufrette/Adapter/Local.php @@ -27,10 +27,10 @@ class Local implements Adapter, StreamFactory, ChecksumCalculator, SizeCalculato * could not be created */ public function __construct( - string $directory, - bool $create = false, + string $directory, + bool $create = false, int $mode = 0777 - ){ + ) { $this->directory = Util\Path::normalize($directory); if (is_link($this->directory)) { @@ -87,7 +87,7 @@ public function exists(string $key): bool } /** - * @return array + * @return array * @throws \OutOfBoundsException If the computed path is out of the directory * @throws \InvalidArgumentException if the directory already exists * @throws \RuntimeException if the directory could not be created diff --git a/src/Gaufrette/Adapter/PhpseclibSftp.php b/src/Gaufrette/Adapter/PhpseclibSftp.php index e16e09010..f4202d1f3 100644 --- a/src/Gaufrette/Adapter/PhpseclibSftp.php +++ b/src/Gaufrette/Adapter/PhpseclibSftp.php @@ -169,7 +169,6 @@ public function createFile(string $key, Filesystem $filesystem): File * * It will ensure the root directory exists */ - protected function initialize(): void { if ($this->initialized) { diff --git a/src/Gaufrette/Util/Size.php b/src/Gaufrette/Util/Size.php index 6a7fee966..f2cb5b917 100644 --- a/src/Gaufrette/Util/Size.php +++ b/src/Gaufrette/Util/Size.php @@ -37,6 +37,7 @@ public static function fromFile(string $filename): int public static function fromResource($handle): int { $cStat = fstat($handle); + // if the resource is a remote file, $cStat will be false return $cStat ? $cStat['size'] : 0; } From 178fe56ea3ef62eb1fc0dc3ed38ac7e514771972 Mon Sep 17 00:00:00 2001 From: PedroTroller Date: Fri, 27 Oct 2023 15:26:49 +0200 Subject: [PATCH 31/48] test: fix phpspec tests --- spec/Gaufrette/Adapter/PhpseclibSftpSpec.php | 9 +----- spec/Gaufrette/Adapter/ZipSpec.php | 3 +- spec/Gaufrette/FilesystemSpec.php | 2 +- spec/Gaufrette/StreamWrapperSpec.php | 30 +++++++++++--------- src/Gaufrette/Adapter/Zip.php | 4 +-- src/Gaufrette/StreamWrapper.php | 5 +++- 6 files changed, 27 insertions(+), 26 deletions(-) diff --git a/spec/Gaufrette/Adapter/PhpseclibSftpSpec.php b/spec/Gaufrette/Adapter/PhpseclibSftpSpec.php index 465f3ba37..622aa1cd8 100644 --- a/spec/Gaufrette/Adapter/PhpseclibSftpSpec.php +++ b/spec/Gaufrette/Adapter/PhpseclibSftpSpec.php @@ -11,16 +11,9 @@ } use Gaufrette\Filesystem; -use phpseclib\Net\SFTP as Base; +use phpseclib\Net\SFTP; use PhpSpec\ObjectBehavior; -class SFTP extends Base -{ - public function __construct() - { - } -} - class PhpseclibSftpSpec extends ObjectBehavior { function let(SFTP $sftp) diff --git a/spec/Gaufrette/Adapter/ZipSpec.php b/spec/Gaufrette/Adapter/ZipSpec.php index 76bb1c13a..ca7c1df28 100644 --- a/spec/Gaufrette/Adapter/ZipSpec.php +++ b/spec/Gaufrette/Adapter/ZipSpec.php @@ -2,6 +2,7 @@ namespace spec\Gaufrette\Adapter; +use Gaufrette\Adapter; use PhpSpec\ObjectBehavior; class ZipSpec extends ObjectBehavior @@ -13,6 +14,6 @@ function let() function it_is_adapter() { - $this->shouldHaveType('Gaufrette\Adapter'); + $this->shouldHaveType(Adapter::class); } } diff --git a/spec/Gaufrette/FilesystemSpec.php b/spec/Gaufrette/FilesystemSpec.php index 533b744f5..6924bad5f 100644 --- a/spec/Gaufrette/FilesystemSpec.php +++ b/spec/Gaufrette/FilesystemSpec.php @@ -322,7 +322,7 @@ function it_delegates_checksum_calculation_to_adapter_when_adapter_is_checksum_c $extendedAdapter->read('filename')->shouldNotBeCalled(); $extendedAdapter->checksum('filename')->shouldBeCalled()->willReturn(12); - $this->checksum('filename')->shouldReturn(12); + $this->checksum('filename')->shouldReturn("12"); } function it_delegates_mime_type_resolution_to_adapter_when_adapter_is_mime_type_provider(ExtendedAdapter $extendedAdapter) diff --git a/spec/Gaufrette/StreamWrapperSpec.php b/spec/Gaufrette/StreamWrapperSpec.php index 613d2b4b8..f8b6dd94a 100644 --- a/spec/Gaufrette/StreamWrapperSpec.php +++ b/spec/Gaufrette/StreamWrapperSpec.php @@ -5,6 +5,7 @@ use Gaufrette\FilesystemMap; use Gaufrette\Filesystem; use Gaufrette\Stream; +use Gaufrette\StreamWrapper; use PhpSpec\ObjectBehavior; use Prophecy\Argument; @@ -19,28 +20,31 @@ function let(FilesystemMap $map, Filesystem $filesystem, Stream $stream) function it_is_initializable() { - $this->shouldHaveType('Gaufrette\StreamWrapper'); + $this->shouldHaveType(StreamWrapper::class); } function it_opens_stream(Stream $stream) { $stream->open(Argument::any())->willReturn(true); - $this->stream_open('gaufrette://some/filename', 'r+')->shouldReturn(true); + $this + ->stream_open('gaufrette://some/filename', 'r+', STREAM_REPORT_ERRORS) + ->shouldReturn(true) + ; } function it_does_not_open_stream_when_key_is_not_defined() { $this ->shouldThrow(new \InvalidArgumentException('The specified path (gaufrette://some) is invalid.')) - ->duringStream_open('gaufrette://some', 'r+'); + ->duringStream_open('gaufrette://some', 'r+', STREAM_REPORT_ERRORS); } function it_does_not_open_stream_when_host_is_not_defined() { $this ->shouldThrow(new \InvalidArgumentException('The specified path (gaufrette:///somefile) is invalid.')) - ->duringStream_open('gaufrette:///somefile', 'r+') + ->duringStream_open('gaufrette:///somefile', 'r+', STREAM_REPORT_ERRORS) ; } @@ -54,7 +58,7 @@ function it_does_not_read_from_stream(Stream $stream) $stream->open(Argument::any())->willReturn(true); $stream->read(4)->willReturn('some'); - $this->stream_open('gaufrette://some/filename', 'r+'); + $this->stream_open('gaufrette://some/filename', 'r+', STREAM_REPORT_ERRORS); $this->stream_read(4)->shouldReturn('some'); } @@ -68,7 +72,7 @@ function it_writes_to_stream(Stream $stream) $stream->open(Argument::any())->willReturn(true); $stream->write('some content')->shouldBeCalled()->willReturn(12); - $this->stream_open('gaufrette://some/filename', 'w+'); + $this->stream_open('gaufrette://some/filename', 'w+', STREAM_REPORT_ERRORS); $this->stream_write('some content')->shouldReturn(12); } @@ -82,7 +86,7 @@ function it_closes_stream(Stream $stream) { $stream->open(Argument::any())->willReturn(true); $stream->close()->shouldBeCalled(); - $this->stream_open('gaufrette://some/filename', 'w+'); + $this->stream_open('gaufrette://some/filename', 'w+', STREAM_REPORT_ERRORS); $this->stream_close(); } @@ -96,7 +100,7 @@ function it_flushes_stream(Stream $stream) { $stream->open(Argument::any())->willReturn(true); $stream->flush()->shouldBeCalled(); - $this->stream_open('gaufrette://some/filename', 'w+'); + $this->stream_open('gaufrette://some/filename', 'w+', STREAM_REPORT_ERRORS); $this->stream_flush(); } @@ -110,7 +114,7 @@ function it_seeks_in_stream(Stream $stream) { $stream->open(Argument::any())->willReturn(true); $stream->seek(12, SEEK_SET)->shouldBeCalled()->willReturn(true); - $this->stream_open('gaufrette://some/filename', 'w+'); + $this->stream_open('gaufrette://some/filename', 'w+', STREAM_REPORT_ERRORS); $this->stream_seek(12, SEEK_SET)->shouldReturn(true); } @@ -124,7 +128,7 @@ function it_does_tell_about_position_in_stream(Stream $stream) { $stream->open(Argument::any())->willReturn(true); $stream->tell()->shouldBeCalled()->willReturn(12); - $this->stream_open('gaufrette://some/filename', 'w+'); + $this->stream_open('gaufrette://some/filename', 'w+', STREAM_REPORT_ERRORS); $this->stream_tell()->shouldReturn(12); } @@ -137,7 +141,7 @@ function it_does_not_mark_as_eof_if_stream_is_not_opened(Stream $stream) function it_checks_if_eof(Stream $stream) { $stream->open(Argument::any())->willReturn(true); - $this->stream_open('gaufrette://some/filename', 'w+'); + $this->stream_open('gaufrette://some/filename', 'w+', STREAM_REPORT_ERRORS); $stream->eof()->willReturn(false); $this->stream_eof()->shouldReturn(false); @@ -171,7 +175,7 @@ function it_stats_file(Stream $stream) $stream->open(Argument::any())->willReturn(true); $stream->stat()->willReturn($stat); - $this->stream_open('gaufrette://some/filename', 'w+'); + $this->stream_open('gaufrette://some/filename', 'w+', STREAM_REPORT_ERRORS); $this->stream_stat()->shouldReturn($stat); } @@ -230,7 +234,7 @@ function it_casts_stream(Stream $stream) $stream->open(Argument::any())->willReturn(true); $stream->cast(STREAM_CAST_FOR_SELECT)->willReturn('resource'); - $this->stream_open('gaufrette://some/filename', 'w+'); + $this->stream_open('gaufrette://some/filename', 'w+', STREAM_REPORT_ERRORS); $this->stream_cast(STREAM_CAST_FOR_SELECT)->shouldReturn('resource'); } } diff --git a/src/Gaufrette/Adapter/Zip.php b/src/Gaufrette/Adapter/Zip.php index 2a4b6f691..4a45a1c43 100644 --- a/src/Gaufrette/Adapter/Zip.php +++ b/src/Gaufrette/Adapter/Zip.php @@ -16,7 +16,7 @@ class Zip implements Adapter { protected ZipArchive $zipArchive; - public function __construct(private readonly string $zipFile) + public function __construct(private string $zipFile) { if (!extension_loaded('zip')) { throw new \RuntimeException(sprintf('Unable to use %s as the ZIP extension is not available.', __CLASS__)); @@ -135,7 +135,7 @@ public function getStat(string $key): array public function __destruct() { - if ($this->zipArchive) { + if (isset($this->zipArchive)) { try { $this->zipArchive->close(); } catch (\Exception $e) { diff --git a/src/Gaufrette/StreamWrapper.php b/src/Gaufrette/StreamWrapper.php index 5eb052a9a..94e2cf284 100644 --- a/src/Gaufrette/StreamWrapper.php +++ b/src/Gaufrette/StreamWrapper.php @@ -81,7 +81,10 @@ protected static function streamWrapperRegister(string $scheme, string $classNam return stream_wrapper_register($scheme, $className); } - public function stream_open(string $path, string $mode, int $options, ?string &$opened_path): bool + /** + * @param STREAM_USE_PATH|STREAM_REPORT_ERRORS|9 $options + */ + public function stream_open(string $path, string $mode, int $options, ?string &$opened_path = null): bool { $this->stream = $this->createStream($path); From bc76e7488124e945c9be8bbe98592ff26d47aabc Mon Sep 17 00:00:00 2001 From: Pierre PLAZANET Date: Fri, 27 Oct 2023 15:49:55 +0200 Subject: [PATCH 32/48] Update src/Gaufrette/Adapter/AwsS3.php MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Grégoire Drapeau --- src/Gaufrette/Adapter/AwsS3.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Gaufrette/Adapter/AwsS3.php b/src/Gaufrette/Adapter/AwsS3.php index ba9c3f37b..ace91dc4f 100644 --- a/src/Gaufrette/Adapter/AwsS3.php +++ b/src/Gaufrette/Adapter/AwsS3.php @@ -173,7 +173,7 @@ public function size(string $key): int } } - public function mimeType(string $key): string + public function mimeType(string $key): string|bool { try { $result = $this->service->headObject($this->getOptions($key)); From ec744b9826fa97eb49d2bc1ccf0455f63b8b46a3 Mon Sep 17 00:00:00 2001 From: Pierre PLAZANET Date: Fri, 27 Oct 2023 15:59:17 +0200 Subject: [PATCH 33/48] Update src/Gaufrette/Adapter/PhpseclibSftp.php MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Grégoire Drapeau --- src/Gaufrette/Adapter/PhpseclibSftp.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Gaufrette/Adapter/PhpseclibSftp.php b/src/Gaufrette/Adapter/PhpseclibSftp.php index f4202d1f3..befa19241 100644 --- a/src/Gaufrette/Adapter/PhpseclibSftp.php +++ b/src/Gaufrette/Adapter/PhpseclibSftp.php @@ -180,7 +180,7 @@ protected function initialize(): void $this->initialized = true; } - protected function ensureDirectoryExists(string $directory, bool $create) + protected function ensureDirectoryExists(string $directory, bool $create): void { $pwd = $this->sftp->pwd(); if ($this->sftp->chdir($directory)) { From b99b550b0396e74795a398b7cff285815bd6d0f7 Mon Sep 17 00:00:00 2001 From: Pierre PLAZANET Date: Fri, 27 Oct 2023 16:08:25 +0200 Subject: [PATCH 34/48] Update src/Gaufrette/Adapter/AzureBlobStorage.php MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Kévin --- src/Gaufrette/Adapter/AzureBlobStorage.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Gaufrette/Adapter/AzureBlobStorage.php b/src/Gaufrette/Adapter/AzureBlobStorage.php index c24ffa5a5..92875f0de 100644 --- a/src/Gaufrette/Adapter/AzureBlobStorage.php +++ b/src/Gaufrette/Adapter/AzureBlobStorage.php @@ -92,7 +92,7 @@ public function createContainer(string $containerName, CreateContainerOptions $o * * @throws \RuntimeException if cannot delete the container */ - public function deleteContainer(string $containerName, BlobServiceOptions $options = null) + public function deleteContainer(string $containerName, BlobServiceOptions $options = null): void { $this->init(); From 826acdf98675b9fd1d491a72adf3958019fb9fb0 Mon Sep 17 00:00:00 2001 From: Pierre PLAZANET Date: Fri, 27 Oct 2023 16:08:35 +0200 Subject: [PATCH 35/48] Update src/Gaufrette/Adapter.php --- src/Gaufrette/Adapter.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Gaufrette/Adapter.php b/src/Gaufrette/Adapter.php index b4a412df4..916980ef4 100644 --- a/src/Gaufrette/Adapter.php +++ b/src/Gaufrette/Adapter.php @@ -13,7 +13,7 @@ interface Adapter /** * Reads the content of the file. * - * @return string|bool if cannot read content + * @return string|false Returns FALSE in content is not readable */ public function read(string $key): string|bool; From 8e7ecbe6c87dadc8c6dfa463464df247c21329db Mon Sep 17 00:00:00 2001 From: Pierre PLAZANET Date: Fri, 27 Oct 2023 16:09:09 +0200 Subject: [PATCH 36/48] Update src/Gaufrette/Adapter/AzureBlobStorage.php MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Kévin --- src/Gaufrette/Adapter/AzureBlobStorage.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Gaufrette/Adapter/AzureBlobStorage.php b/src/Gaufrette/Adapter/AzureBlobStorage.php index 92875f0de..4a8707aed 100644 --- a/src/Gaufrette/Adapter/AzureBlobStorage.php +++ b/src/Gaufrette/Adapter/AzureBlobStorage.php @@ -53,7 +53,7 @@ public function getCreateContainerOptions(): CreateContainerOptions return $this->createContainerOptions; } - public function setCreateContainerOptions(CreateContainerOptions $options) + public function setCreateContainerOptions(CreateContainerOptions $options): void { $this->createContainerOptions = $options; } From c4fba3881d24144321547867456c5b79ea7ce272 Mon Sep 17 00:00:00 2001 From: Pierre PLAZANET Date: Fri, 27 Oct 2023 16:09:30 +0200 Subject: [PATCH 37/48] Update src/Gaufrette/Adapter/Ftp.php MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Kévin --- src/Gaufrette/Adapter/Ftp.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Gaufrette/Adapter/Ftp.php b/src/Gaufrette/Adapter/Ftp.php index f279efd42..fdb29bebf 100644 --- a/src/Gaufrette/Adapter/Ftp.php +++ b/src/Gaufrette/Adapter/Ftp.php @@ -449,7 +449,7 @@ private function parseRawlist(array $rawlist): array /** * Computes the path for the given key. */ - private function computePath(string $key) + private function computePath(string $key): string { return rtrim($this->directory, '/') . '/' . $key; } From 3539ec7d39ba29dad2c1b365c964d4a4e26d71a9 Mon Sep 17 00:00:00 2001 From: Pierre PLAZANET Date: Fri, 27 Oct 2023 16:09:38 +0200 Subject: [PATCH 38/48] Update src/Gaufrette/Adapter/AzureBlobStorage.php MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Kévin --- src/Gaufrette/Adapter/AzureBlobStorage.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Gaufrette/Adapter/AzureBlobStorage.php b/src/Gaufrette/Adapter/AzureBlobStorage.php index 4a8707aed..f94d03b28 100644 --- a/src/Gaufrette/Adapter/AzureBlobStorage.php +++ b/src/Gaufrette/Adapter/AzureBlobStorage.php @@ -63,7 +63,7 @@ public function setCreateContainerOptions(CreateContainerOptions $options): void * * @throws \RuntimeException if cannot create the container */ - public function createContainer(string $containerName, CreateContainerOptions $options = null) + public function createContainer(string $containerName, CreateContainerOptions $options = null): void { $this->init(); From 94d89cd352f303ff4a6a09f9fe62858a6facefa1 Mon Sep 17 00:00:00 2001 From: Pierre PLAZANET Date: Fri, 27 Oct 2023 16:10:00 +0200 Subject: [PATCH 39/48] Update src/Gaufrette/Adapter/DoctrineDbal.php --- src/Gaufrette/Adapter/DoctrineDbal.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Gaufrette/Adapter/DoctrineDbal.php b/src/Gaufrette/Adapter/DoctrineDbal.php index c0495177c..207081b1d 100644 --- a/src/Gaufrette/Adapter/DoctrineDbal.php +++ b/src/Gaufrette/Adapter/DoctrineDbal.php @@ -163,7 +163,7 @@ public function isDirectory(string $key): bool } /** - * @return mixed|false + * @return mixed */ private function getColumnValue(string $key, string $column) { From bf12aefa1d0b2b2594fc89b86f8285bb8f315520 Mon Sep 17 00:00:00 2001 From: PedroTroller Date: Mon, 30 Oct 2023 15:12:55 +0100 Subject: [PATCH 40/48] refactor: set type for mimetype aware adapters --- .php-cs-fixer.dist.php | 2 +- spec/Gaufrette/FilesystemSpec.php | 2 +- src/Gaufrette/Adapter/AsyncAwsS3.php | 4 ++-- src/Gaufrette/Adapter/AwsS3.php | 2 +- src/Gaufrette/Adapter/AzureBlobStorage.php | 2 +- src/Gaufrette/Adapter/InMemory.php | 2 +- src/Gaufrette/Adapter/Local.php | 3 ++- src/Gaufrette/Adapter/MimeTypeProvider.php | 4 ++-- src/Gaufrette/FilesystemInterface.php | 2 +- 9 files changed, 12 insertions(+), 11 deletions(-) diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index 2f829560f..d68945fde 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -21,7 +21,7 @@ 'no_break_comment' => false, 'no_extra_blank_lines' => true, 'no_spaces_around_offset' => true, - 'no_trailing_comma_in_singleline' => true, + 'no_trailing_comma_in_singleline_array' => true, 'no_unused_imports' => true, 'no_useless_else' => true, 'no_useless_return' => true, diff --git a/spec/Gaufrette/FilesystemSpec.php b/spec/Gaufrette/FilesystemSpec.php index 6924bad5f..f40b13b01 100644 --- a/spec/Gaufrette/FilesystemSpec.php +++ b/spec/Gaufrette/FilesystemSpec.php @@ -322,7 +322,7 @@ function it_delegates_checksum_calculation_to_adapter_when_adapter_is_checksum_c $extendedAdapter->read('filename')->shouldNotBeCalled(); $extendedAdapter->checksum('filename')->shouldBeCalled()->willReturn(12); - $this->checksum('filename')->shouldReturn("12"); + $this->checksum('filename')->shouldReturn('12'); } function it_delegates_mime_type_resolution_to_adapter_when_adapter_is_mime_type_provider(ExtendedAdapter $extendedAdapter) diff --git a/src/Gaufrette/Adapter/AsyncAwsS3.php b/src/Gaufrette/Adapter/AsyncAwsS3.php index 972cdf38d..a11b7cd9b 100644 --- a/src/Gaufrette/Adapter/AsyncAwsS3.php +++ b/src/Gaufrette/Adapter/AsyncAwsS3.php @@ -176,11 +176,11 @@ public function size(string $key): int return (int) $result->getContentLength(); } - public function mimeType(string $key): string + public function mimeType(string $key): string|bool { $result = $this->service->headObject($this->getOptions($key)); - return $result->getContentType(); + return $result->getContentType() ?: false; } /** diff --git a/src/Gaufrette/Adapter/AwsS3.php b/src/Gaufrette/Adapter/AwsS3.php index ace91dc4f..9e9141de5 100644 --- a/src/Gaufrette/Adapter/AwsS3.php +++ b/src/Gaufrette/Adapter/AwsS3.php @@ -173,7 +173,7 @@ public function size(string $key): int } } - public function mimeType(string $key): string|bool + public function mimeType(string $key): bool|string { try { $result = $this->service->headObject($this->getOptions($key)); diff --git a/src/Gaufrette/Adapter/AzureBlobStorage.php b/src/Gaufrette/Adapter/AzureBlobStorage.php index f94d03b28..5352e5bc0 100644 --- a/src/Gaufrette/Adapter/AzureBlobStorage.php +++ b/src/Gaufrette/Adapter/AzureBlobStorage.php @@ -286,7 +286,7 @@ public function size(string $key): int /** * {@inheritdoc} */ - public function mimeType(string $key): string + public function mimeType(string $key): string|bool { $this->init(); list($containerName, $key) = $this->tokenizeKey($key); diff --git a/src/Gaufrette/Adapter/InMemory.php b/src/Gaufrette/Adapter/InMemory.php index 7f76b3881..f87d68924 100644 --- a/src/Gaufrette/Adapter/InMemory.php +++ b/src/Gaufrette/Adapter/InMemory.php @@ -120,7 +120,7 @@ public function isDirectory(string $path): bool return false; } - public function mimeType(string $key): string + public function mimeType(string $key): bool|string { $fileInfo = new \finfo(FILEINFO_MIME_TYPE); diff --git a/src/Gaufrette/Adapter/Local.php b/src/Gaufrette/Adapter/Local.php index e19af1a1b..e56da5f0a 100644 --- a/src/Gaufrette/Adapter/Local.php +++ b/src/Gaufrette/Adapter/Local.php @@ -183,11 +183,12 @@ public function size(string $key): int } /** + * {@inheritdoc} * @throws \OutOfBoundsException If the computed path is out of the directory * @throws \InvalidArgumentException if the directory already exists * @throws \RuntimeException if the directory could not be created */ - public function mimeType(string $key): string + public function mimeType(string $key): bool|string { $fileInfo = new \finfo(FILEINFO_MIME_TYPE); diff --git a/src/Gaufrette/Adapter/MimeTypeProvider.php b/src/Gaufrette/Adapter/MimeTypeProvider.php index 53617beaf..863e9a75e 100644 --- a/src/Gaufrette/Adapter/MimeTypeProvider.php +++ b/src/Gaufrette/Adapter/MimeTypeProvider.php @@ -10,7 +10,7 @@ interface MimeTypeProvider { /** - * Returns the mime type of the specified key. + * @return false|string the mime type of the specified key. */ - public function mimeType(string $key): string; + public function mimeType(string $key): string|bool; } diff --git a/src/Gaufrette/FilesystemInterface.php b/src/Gaufrette/FilesystemInterface.php index 9a686ab8f..57d16dd76 100644 --- a/src/Gaufrette/FilesystemInterface.php +++ b/src/Gaufrette/FilesystemInterface.php @@ -167,7 +167,7 @@ public function createFile($key); * * @param string $key * - * @return string + * @return string|false * * @throws \InvalidArgumentException If $key is invalid */ From 74be6f5984cfa81afe0ef7a3a5803fd68151e76f Mon Sep 17 00:00:00 2001 From: PedroTroller Date: Mon, 30 Oct 2023 15:16:46 +0100 Subject: [PATCH 41/48] docs: add explanation for bitwire value in StreamWrapper --- src/Gaufrette/StreamWrapper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Gaufrette/StreamWrapper.php b/src/Gaufrette/StreamWrapper.php index 94e2cf284..2e6759bb4 100644 --- a/src/Gaufrette/StreamWrapper.php +++ b/src/Gaufrette/StreamWrapper.php @@ -82,7 +82,7 @@ protected static function streamWrapperRegister(string $scheme, string $classNam } /** - * @param STREAM_USE_PATH|STREAM_REPORT_ERRORS|9 $options + * @param STREAM_USE_PATH|STREAM_REPORT_ERRORS|9 $options "9" is the result of a bitwize operation between STREAM_USE_PATH and STREAM_REPORT_ERRORS (STREAM_USE_PATH|STREAM_REPORT_ERRORS). */ public function stream_open(string $path, string $mode, int $options, ?string &$opened_path = null): bool { From e2bcd990949be1cbd5cddf3059ee671af25263a9 Mon Sep 17 00:00:00 2001 From: PedroTroller Date: Mon, 30 Oct 2023 15:22:02 +0100 Subject: [PATCH 42/48] fix: introduction of readonly promoted properties --- src/Gaufrette/Adapter/AzureBlobStorage.php | 6 +++--- src/Gaufrette/Adapter/DoctrineDbal.php | 4 ++-- src/Gaufrette/Adapter/Flysystem.php | 2 +- src/Gaufrette/Adapter/GridFS.php | 2 +- src/Gaufrette/Adapter/PhpseclibSftp.php | 6 +++--- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/Gaufrette/Adapter/AzureBlobStorage.php b/src/Gaufrette/Adapter/AzureBlobStorage.php index 5352e5bc0..ce3daf01d 100644 --- a/src/Gaufrette/Adapter/AzureBlobStorage.php +++ b/src/Gaufrette/Adapter/AzureBlobStorage.php @@ -36,10 +36,10 @@ class AzureBlobStorage implements Adapter, MetadataSupporter, SizeCalculator, Ch protected CreateContainerOptions $createContainerOptions; public function __construct( - private readonly BlobProxyFactoryInterface $blobProxyFactory, - private readonly ?string $containerName = null, + private BlobProxyFactoryInterface $blobProxyFactory, + private ?string $containerName = null, bool $create = false, - private readonly bool $detectContentType = true + private bool $detectContentType = true ) { if (null === $containerName) { $this->multiContainerMode = true; diff --git a/src/Gaufrette/Adapter/DoctrineDbal.php b/src/Gaufrette/Adapter/DoctrineDbal.php index 207081b1d..467639d06 100644 --- a/src/Gaufrette/Adapter/DoctrineDbal.php +++ b/src/Gaufrette/Adapter/DoctrineDbal.php @@ -29,8 +29,8 @@ class DoctrineDbal implements Adapter, ChecksumCalculator, ListKeysAware * @param array $columns The column names */ public function __construct( - private readonly Connection $connection, - private readonly string $table, + private Connection $connection, + private string $table, array $columns = [] ) { if (!class_exists(Connection::class)) { diff --git a/src/Gaufrette/Adapter/Flysystem.php b/src/Gaufrette/Adapter/Flysystem.php index fc8dc53df..c3a231144 100644 --- a/src/Gaufrette/Adapter/Flysystem.php +++ b/src/Gaufrette/Adapter/Flysystem.php @@ -15,7 +15,7 @@ class Flysystem implements Adapter, ListKeysAware /** * @param Config|array|null $config */ - public function __construct(private readonly AdapterInterface $adapter, $config = null) + public function __construct(private AdapterInterface $adapter, $config = null) { if (!interface_exists(AdapterInterface::class)) { throw new \LogicException('You need to install package "league/flysystem" to use this adapter'); diff --git a/src/Gaufrette/Adapter/GridFS.php b/src/Gaufrette/Adapter/GridFS.php index 71b47fab2..e71d5cae2 100644 --- a/src/Gaufrette/Adapter/GridFS.php +++ b/src/Gaufrette/Adapter/GridFS.php @@ -21,7 +21,7 @@ class GridFS implements Adapter, ChecksumCalculator, MetadataSupporter, ListKeys /** * @param Bucket $bucket */ - public function __construct(private readonly Bucket $bucket) + public function __construct(private Bucket $bucket) { if (!class_exists(Bucket::class)) { throw new \LogicException('You need to install package "mongodb/mongodb" to use this adapter'); diff --git a/src/Gaufrette/Adapter/PhpseclibSftp.php b/src/Gaufrette/Adapter/PhpseclibSftp.php index befa19241..14e87cfe2 100644 --- a/src/Gaufrette/Adapter/PhpseclibSftp.php +++ b/src/Gaufrette/Adapter/PhpseclibSftp.php @@ -17,9 +17,9 @@ class PhpseclibSftp implements Adapter, FileFactory, ListKeysAware * does not exist */ public function __construct( - private readonly SecLibSFTP $sftp, - private readonly ?string $directory = null, - private readonly bool $create = false + private SecLibSFTP $sftp, + private ?string $directory = null, + private bool $create = false ) { if (!class_exists(SecLibSFTP::class)) { throw new \LogicException('You need to install package "phpseclib/phpseclib" to use this adapter'); From 64a9a23b57904c9d6cd3fbcc8199a64ce14ea9fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin?= Date: Mon, 30 Oct 2023 15:27:02 +0100 Subject: [PATCH 43/48] Update src/Gaufrette/Adapter/AwsS3.php MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Grégoire Drapeau --- src/Gaufrette/Adapter/AwsS3.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Gaufrette/Adapter/AwsS3.php b/src/Gaufrette/Adapter/AwsS3.php index 9e9141de5..185446fd7 100644 --- a/src/Gaufrette/Adapter/AwsS3.php +++ b/src/Gaufrette/Adapter/AwsS3.php @@ -315,7 +315,7 @@ protected function computeKey(string $path): string return ltrim(substr($path, strlen($this->options['directory'])), '/'); } - private function guessContentType(mixed $content): false|string + private function guessContentType(mixed $content): bool|string { $fileInfo = new \finfo(FILEINFO_MIME_TYPE); From 1173c0e3f1cd2364ba8f1adb58ea6198f8242407 Mon Sep 17 00:00:00 2001 From: Pierre PLAZANET Date: Mon, 30 Oct 2023 15:29:03 +0100 Subject: [PATCH 44/48] Update src/Gaufrette/Stream/InMemoryBuffer.php MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Kévin --- src/Gaufrette/Stream/InMemoryBuffer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Gaufrette/Stream/InMemoryBuffer.php b/src/Gaufrette/Stream/InMemoryBuffer.php index 3b7e97aee..38f54832b 100644 --- a/src/Gaufrette/Stream/InMemoryBuffer.php +++ b/src/Gaufrette/Stream/InMemoryBuffer.php @@ -54,7 +54,7 @@ public function open(StreamMode $mode): bool return true; } - public function read(int $count): string|false + public function read(int $count): string|bool { if (false === $this->mode->allowsRead()) { throw new \LogicException('The stream does not allow read.'); From 55ad928cc9268ba437f7bccee053fe9fc9182896 Mon Sep 17 00:00:00 2001 From: Pierre PLAZANET Date: Mon, 30 Oct 2023 15:29:20 +0100 Subject: [PATCH 45/48] Update src/Gaufrette/Stream/Local.php MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Kévin --- src/Gaufrette/Stream/Local.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Gaufrette/Stream/Local.php b/src/Gaufrette/Stream/Local.php index 5ba3ffdb1..17367b48b 100644 --- a/src/Gaufrette/Stream/Local.php +++ b/src/Gaufrette/Stream/Local.php @@ -129,7 +129,7 @@ public function eof(): bool /** * @return array|false */ - public function stat(): array|false + public function stat(): array|bool { if ($this->fileHandle) { return fstat($this->fileHandle); From 3a5592dfc9b2aa4e1dc9260a6663dac3806d6132 Mon Sep 17 00:00:00 2001 From: Pierre PLAZANET Date: Mon, 30 Oct 2023 15:29:28 +0100 Subject: [PATCH 46/48] Update src/Gaufrette/Stream/Local.php MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Kévin --- src/Gaufrette/Stream/Local.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Gaufrette/Stream/Local.php b/src/Gaufrette/Stream/Local.php index 17367b48b..689bfef9d 100644 --- a/src/Gaufrette/Stream/Local.php +++ b/src/Gaufrette/Stream/Local.php @@ -50,7 +50,7 @@ public function open(StreamMode $mode): bool return true; } - public function read(int $count): string|false + public function read(int $count): string|bool { if (!$this->fileHandle) { return false; From b797abe681773cf292ed9d4dae307463a7d863bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin?= Date: Mon, 30 Oct 2023 15:29:41 +0100 Subject: [PATCH 47/48] Update src/Gaufrette/Adapter/AsyncAwsS3.php --- src/Gaufrette/Adapter/AsyncAwsS3.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Gaufrette/Adapter/AsyncAwsS3.php b/src/Gaufrette/Adapter/AsyncAwsS3.php index a11b7cd9b..f283c8491 100644 --- a/src/Gaufrette/Adapter/AsyncAwsS3.php +++ b/src/Gaufrette/Adapter/AsyncAwsS3.php @@ -20,7 +20,6 @@ class AsyncAwsS3 implements Adapter, MetadataSupporter, ListKeysAware, SizeCalcu protected array $options; protected bool $bucketExists; protected array $metadata = []; - protected bool $detectContentType; public function __construct( From 3881d3e8cbca55ade698b9cc78d1a2dd645a0c78 Mon Sep 17 00:00:00 2001 From: Pierre PLAZANET Date: Mon, 30 Oct 2023 15:36:03 +0100 Subject: [PATCH 48/48] Update src/Gaufrette/Stream/InMemoryBuffer.php MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Kévin --- src/Gaufrette/Stream/InMemoryBuffer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Gaufrette/Stream/InMemoryBuffer.php b/src/Gaufrette/Stream/InMemoryBuffer.php index 38f54832b..7d74c70e6 100644 --- a/src/Gaufrette/Stream/InMemoryBuffer.php +++ b/src/Gaufrette/Stream/InMemoryBuffer.php @@ -153,7 +153,7 @@ public function eof(): bool /** * @return array|false */ - public function stat(): array|false + public function stat(): array|bool { if ($this->filesystem->has($this->key)) { $isDirectory = $this->filesystem->isDirectory($this->key);