From 912ba3e5595280999b9fa99a3c20c5ecb7de6870 Mon Sep 17 00:00:00 2001 From: Frank de Jonge Date: Sat, 15 Jan 2022 23:42:13 +0100 Subject: [PATCH] CS fixes --- .php-cs-fixer.dist.php | 7 +++---- bin/check-versions.php | 17 ++++++++++------- bin/set-flysystem-version.php | 14 ++++++++++---- composer.json | 2 +- mocked-functions.php | 6 ++++-- phpunit.php | 6 +++--- .../FilesystemAdapterTestCase.php | 6 +++--- .../RetryOnTestException.php | 3 ++- src/AsyncAwsS3/AsyncAwsS3AdapterTest.php | 1 - src/AwsS3V3/AwsS3V3Adapter.php | 7 ++++++- src/Ftp/FtpAdapter.php | 1 - src/GoogleCloudStorage/StubRiggedBucket.php | 2 -- src/GoogleCloudStorage/StubStorageClient.php | 1 + src/InMemory/InMemoryFilesystemAdapter.php | 1 - src/Local/LocalFilesystemAdapter.php | 3 +-- src/Local/LocalFilesystemAdapterTest.php | 6 +++--- test_files/wait_for_ftp.php | 2 +- 17 files changed, 48 insertions(+), 37 deletions(-) diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index 4193ba5a9..00535eb4c 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -1,8 +1,8 @@ in([__DIR__ . '/src']) -; + ->in([__DIR__ . '/']) + ->exclude(__DIR__ . '/vendor'); return (new PhpCsFixer\Config()) ->setRules([ @@ -35,5 +35,4 @@ 'no_extra_blank_lines' => true, 'no_whitespace_in_blank_line' => true, ]) - ->setFinder($finder) - ; + ->setFinder($finder); diff --git a/bin/check-versions.php b/bin/check-versions.php index 095108b26..a0d524b0a 100644 --- a/bin/check-versions.php +++ b/bin/check-versions.php @@ -3,7 +3,7 @@ declare(strict_types=1); /** - * This script check for composer dependency incompatibilities: + * This script check for composer dependency incompatibilities:. * * - All required dependencies of the extracted packages MUST be * present in the main composer.json's require(-dev) section. @@ -23,7 +23,6 @@ include_once __DIR__ . '/tools.php'; - function constraint_has_conflict(string $mainConstraint, string $packageConstraint): bool { $parser = new VersionParser(); @@ -34,7 +33,6 @@ function constraint_has_conflict(string $mainConstraint, string $packageConstrai $packageLowerBound = $packageConstraint->getLowerBound()->getVersion(); $packageUpperBound = $packageConstraint->getUpperBound()->getVersion(); - if (Comparator::compare($mainUpperBound, '<=', $packageLowerBound)) { return true; } @@ -58,9 +56,15 @@ function constraint_has_conflict(string $mainConstraint, string $packageConstrai $mainComposer = $filesystem->read('composer.json'); /** @var string[] $otherComposers */ $otherComposers = $filesystem->listContents('src', true) - ->filter(function(StorageAttributes $item) { return $item->isFile(); }) - ->filter(function(FileAttributes $item) { return substr($item->path(), -5) === '.json'; }) - ->map(function(FileAttributes $item) { return $item->path(); }) + ->filter(function (StorageAttributes $item) { + return $item->isFile(); + }) + ->filter(function (FileAttributes $item) { + return substr($item->path(), -5) === '.json'; + }) + ->map(function (FileAttributes $item) { + return $item->path(); + }) ->toArray(); $mainInformation = json_decode($mainComposer, true); @@ -107,4 +111,3 @@ function constraint_has_conflict(string $mainConstraint, string $packageConstrai } write_line("✅ Composer dependencies are looking fine."); - diff --git a/bin/set-flysystem-version.php b/bin/set-flysystem-version.php index 1036e08b4..354126512 100644 --- a/bin/set-flysystem-version.php +++ b/bin/set-flysystem-version.php @@ -19,14 +19,20 @@ /** @var string[] $otherComposers */ $composerFiles = $filesystem->listContents('src', true) - ->filter(function(StorageAttributes $item) { return $item->isFile(); }) - ->filter(function(FileAttributes $item) { return substr($item->path(), -5) === '.json'; }) - ->map(function(FileAttributes $item) { return $item->path(); }) + ->filter(function (StorageAttributes $item) { + return $item->isFile(); + }) + ->filter(function (FileAttributes $item) { + return substr($item->path(), -5) === '.json'; + }) + ->map(function (FileAttributes $item) { + return $item->path(); + }) ->toArray(); foreach ($composerFiles as $composerFile) { $contents = $filesystem->read($composerFile); $mainVersionRegex = preg_quote($mainVersion, '~'); - $updated = preg_replace('~("league/flysystem": "\\^[a-zA-Z0-9\\.-]+")~ms', '"league/flysystem": "^'.$mainVersion.'"', $contents); + $updated = preg_replace('~("league/flysystem": "\\^[a-zA-Z0-9\\.-]+")~ms', '"league/flysystem": "^' . $mainVersion . '"', $contents); $filesystem->write($composerFile, $updated); } diff --git a/composer.json b/composer.json index 1df9589c0..073340f39 100644 --- a/composer.json +++ b/composer.json @@ -29,7 +29,7 @@ "phpseclib/phpseclib": "^2.0", "aws/aws-sdk-php": "^3.198.1", "composer/semver": "^3.0", - "friendsofphp/php-cs-fixer": "^3.2", + "friendsofphp/php-cs-fixer": "^3.5", "google/cloud-storage": "^1.23", "async-aws/s3": "^1.5", "async-aws/simple-s3": "^1.0", diff --git a/mocked-functions.php b/mocked-functions.php index b7de797fe..e6cb6d187 100644 --- a/mocked-functions.php +++ b/mocked-functions.php @@ -39,7 +39,8 @@ function filesize(...$arguments) } namespace League\Flysystem\InMemory { - function time() { + function time() + { if ( ! is_mocked('time')) { return \time(); } @@ -141,7 +142,8 @@ function ftp_rawlist(...$arguments) } namespace League\Flysystem\ZipArchive { - function stream_get_contents(...$arguments) { + function stream_get_contents(...$arguments) + { if ( ! is_mocked('stream_get_contents')) { return \stream_get_contents(...$arguments); } diff --git a/phpunit.php b/phpunit.php index d25ffc08a..e6b37d245 100644 --- a/phpunit.php +++ b/phpunit.php @@ -1,5 +1,5 @@ runScenario(function() { + $this->runScenario(function () { $adapter = $this->adapter(); $fileExistsBefore = $adapter->fileExists('some/path.txt'); $adapter->write('some/path.txt', 'contents', new Config()); diff --git a/src/AdapterTestUtilities/RetryOnTestException.php b/src/AdapterTestUtilities/RetryOnTestException.php index 9e63ec62a..1b52fc51f 100644 --- a/src/AdapterTestUtilities/RetryOnTestException.php +++ b/src/AdapterTestUtilities/RetryOnTestException.php @@ -4,9 +4,9 @@ namespace League\Flysystem\AdapterTestUtilities; -use League\Flysystem\FilesystemException; use const PHP_EOL; use const STDOUT; +use League\Flysystem\FilesystemException; use Throwable; /** @@ -43,6 +43,7 @@ protected function dontRetryOnException(): void /** * @internal + * * @throws Throwable */ protected function runSetup(callable $scenario): void diff --git a/src/AsyncAwsS3/AsyncAwsS3AdapterTest.php b/src/AsyncAwsS3/AsyncAwsS3AdapterTest.php index 72f20145e..0dceda0e8 100644 --- a/src/AsyncAwsS3/AsyncAwsS3AdapterTest.php +++ b/src/AsyncAwsS3/AsyncAwsS3AdapterTest.php @@ -19,7 +19,6 @@ use League\Flysystem\Config; use League\Flysystem\FileAttributes; use League\Flysystem\FilesystemAdapter; -use League\Flysystem\Ftp\UnableToConnectToFtpHost; use League\Flysystem\StorageAttributes; use League\Flysystem\UnableToCheckFileExistence; use League\Flysystem\UnableToDeleteFile; diff --git a/src/AwsS3V3/AwsS3V3Adapter.php b/src/AwsS3V3/AwsS3V3Adapter.php index f95986012..b4c566c6a 100644 --- a/src/AwsS3V3/AwsS3V3Adapter.php +++ b/src/AwsS3V3/AwsS3V3Adapter.php @@ -328,7 +328,12 @@ private function mapS3ObjectMetadata(array $metadata, string $path = null): Stor $lastModified = $dateTime instanceof DateTimeResult ? $dateTime->getTimeStamp() : null; return new FileAttributes( - $path, $fileSize, null, $lastModified, $mimetype, $this->extractExtraMetadata($metadata) + $path, + $fileSize, + null, + $lastModified, + $mimetype, + $this->extractExtraMetadata($metadata) ); } diff --git a/src/Ftp/FtpAdapter.php b/src/Ftp/FtpAdapter.php index bef0292ed..b6fe24edc 100644 --- a/src/Ftp/FtpAdapter.php +++ b/src/Ftp/FtpAdapter.php @@ -10,7 +10,6 @@ use League\Flysystem\DirectoryAttributes; use League\Flysystem\FileAttributes; use League\Flysystem\FilesystemAdapter; -use League\Flysystem\FilesystemException; use League\Flysystem\PathPrefixer; use League\Flysystem\StorageAttributes; use League\Flysystem\UnableToCopyFile; diff --git a/src/GoogleCloudStorage/StubRiggedBucket.php b/src/GoogleCloudStorage/StubRiggedBucket.php index 024e9454a..798529d15 100644 --- a/src/GoogleCloudStorage/StubRiggedBucket.php +++ b/src/GoogleCloudStorage/StubRiggedBucket.php @@ -8,8 +8,6 @@ use LogicException; use Throwable; -use function array_key_exists; - class StubRiggedBucket extends Bucket { private array $triggers = []; diff --git a/src/GoogleCloudStorage/StubStorageClient.php b/src/GoogleCloudStorage/StubStorageClient.php index 1cad84b9f..b9cd1db82 100644 --- a/src/GoogleCloudStorage/StubStorageClient.php +++ b/src/GoogleCloudStorage/StubStorageClient.php @@ -27,6 +27,7 @@ public function bucket($name, $userProject = false) 'requesterProjectId' => $this->projectId, ]); } + return $name === 'flysystem' ? $this->riggedBucket : parent::bucket($name, $userProject); } } diff --git a/src/InMemory/InMemoryFilesystemAdapter.php b/src/InMemory/InMemoryFilesystemAdapter.php index d64c8d42c..773067070 100644 --- a/src/InMemory/InMemoryFilesystemAdapter.php +++ b/src/InMemory/InMemoryFilesystemAdapter.php @@ -8,7 +8,6 @@ use League\Flysystem\DirectoryAttributes; use League\Flysystem\FileAttributes; use League\Flysystem\FilesystemAdapter; -use League\Flysystem\FilesystemException; use League\Flysystem\UnableToCopyFile; use League\Flysystem\UnableToMoveFile; use League\Flysystem\UnableToReadFile; diff --git a/src/Local/LocalFilesystemAdapter.php b/src/Local/LocalFilesystemAdapter.php index 1b4ddaad8..5af4273c4 100644 --- a/src/Local/LocalFilesystemAdapter.php +++ b/src/Local/LocalFilesystemAdapter.php @@ -4,7 +4,6 @@ namespace League\Flysystem\Local; -use function file_put_contents; use const DIRECTORY_SEPARATOR; use const LOCK_EX; use DirectoryIterator; @@ -38,11 +37,11 @@ use function error_clear_last; use function error_get_last; use function file_exists; +use function file_put_contents; use function is_dir; use function is_file; use function mkdir; use function rename; -use function stream_copy_to_stream; class LocalFilesystemAdapter implements FilesystemAdapter { diff --git a/src/Local/LocalFilesystemAdapterTest.php b/src/Local/LocalFilesystemAdapterTest.php index c9aa0050b..b90cd4e98 100644 --- a/src/Local/LocalFilesystemAdapterTest.php +++ b/src/Local/LocalFilesystemAdapterTest.php @@ -4,8 +4,6 @@ namespace League\Flysystem\Local; -use function strnatcasecmp; -use function usort; use const LOCK_EX; use League\Flysystem\AdapterTestUtilities\FilesystemAdapterTestCase; use League\Flysystem\Config; @@ -32,7 +30,9 @@ use function is_resource; use function iterator_to_array; use function mkdir; +use function strnatcasecmp; use function symlink; +use function usort; /** * @group local @@ -305,7 +305,7 @@ public function retrieving_visibility_while_listing_directory_contents(): void /** @var Traversable $contentListing */ $contentListing = $adapter->listContents('/', true); $listing = iterator_to_array($contentListing); - usort($listing, function(StorageAttributes $a, StorageAttributes $b) { + usort($listing, function (StorageAttributes $a, StorageAttributes $b) { return strnatcasecmp($a->path(), $b->path()); }); /** diff --git a/test_files/wait_for_ftp.php b/test_files/wait_for_ftp.php index 4a4bc816d..88efff439 100644 --- a/test_files/wait_for_ftp.php +++ b/test_files/wait_for_ftp.php @@ -17,7 +17,7 @@ $start = time(); $connected = false; -while(time() - $start < 60) { +while (time() - $start < 60) { try { $provider->createConnection($options); $connected = true;