diff --git a/.editorconfig b/.editorconfig index fed584a77..299bd7006 100644 --- a/.editorconfig +++ b/.editorconfig @@ -13,3 +13,6 @@ trim_trailing_whitespace = false [*.yml] indent_size = 2 + +[Makefile] +indent_style = tab diff --git a/.env.dist b/.env.dist index 5c79dddaa..f02376e62 100644 --- a/.env.dist +++ b/.env.dist @@ -2,6 +2,16 @@ AWS_KEY= AWS_SECRET= AWS_BUCKET= +AZURE_ACCOUNT= +AZURE_KEY= +AZURE_CONTAINER= + +FTP_HOST=ftp +FTP_PORT=21 +FTP_USER=gaufrette +FTP_PASSWORD=gaufrette +FTP_BASE_DIR=/gaufrette + # see /doc/adapters/google-cloud-storage.md GCS_PROJECT_ID= GCS_BUCKET_NAME= @@ -28,13 +38,3 @@ SFTP_PORT=22 SFTP_USER=gaufrette SFTP_PASSWORD=gaufrette SFTP_BASE_DIR=gaufrette - -FTP_HOST=ftp -FTP_PORT=21 -FTP_USER=gaufrette -FTP_PASSWORD=gaufrette -FTP_BASE_DIR=/gaufrette - -AZURE_ACCOUNT= -AZURE_KEY= -AZURE_CONTAINER= diff --git a/.gitignore b/.gitignore index 0083e891d..ad51fb2ec 100644 --- a/.gitignore +++ b/.gitignore @@ -1,11 +1,12 @@ bin/* !bin/tests !bin/tests-all +composer.lock doc/.couscous -tests/adapters/* -!tests/adapters/*.dist -vendor/ .env -composer.lock +.php_cs.cache phpunit.xml secrets/ +tests/adapters/* +!tests/adapters/*.dist +vendor/ diff --git a/.php_cs.dist b/.php_cs.dist new file mode 100644 index 000000000..10089ee4a --- /dev/null +++ b/.php_cs.dist @@ -0,0 +1,41 @@ +setFinder(PhpCsFixer\Finder::create() + ->exclude('vendor') + ->in(__DIR__) + ) + ->setRules([ + '@PSR1' => true, + '@PSR2' => true, + 'array_syntax' => [ 'syntax' => 'short' ], + 'binary_operator_spaces' => [ 'align_equals' => false, 'align_double_arrow' => false ], + 'blank_line_before_statement' => true, + 'cast_spaces' => true, + 'combine_consecutive_unsets' => true, + 'concat_space' => [ 'spacing' => 'one' ], + 'linebreak_after_opening_tag' => true, + 'method_argument_space' => ['ensure_fully_multiline' => false], + 'no_blank_lines_after_class_opening' => true, + 'no_blank_lines_after_phpdoc' => true, + 'no_break_comment' => false, + 'no_extra_consecutive_blank_lines' => true, + 'no_spaces_around_offset' => true, + 'no_trailing_comma_in_singleline_array' => true, + 'no_unused_imports' => true, + 'no_useless_else' => true, + 'no_useless_return' => true, + 'no_whitespace_before_comma_in_array' => true, + 'no_whitespace_in_blank_line' => true, + 'normalize_index_brace' => true, + 'PedroTroller/phpspec' => true, + 'phpdoc_indent' => true, + 'phpdoc_to_comment' => true, + 'phpdoc_trim' => true, + 'single_quote' => true, + 'ternary_to_null_coalescing' => true, + 'trailing_comma_in_multiline_array' => true, + 'trim_array_spaces' => true, + ]) + ->registerCustomFixers(new PedroTroller\CS\Fixer\Fixers()) +; diff --git a/.travis.yml b/.travis.yml index 9e966a4d7..61779cb80 100644 --- a/.travis.yml +++ b/.travis.yml @@ -41,5 +41,6 @@ install: - composer update --prefer-dist --no-progress --no-suggest --ansi script: + - php vendor/bin/php-cs-fixer fix --diff --dry-run --show-progress=none --verbose - php vendor/bin/phpspec run -fpretty --verbose - find tests/ -name "*Test.php" | vendor/bin/fastest -vvv "vendor/bin/phpunit --verbose {};" diff --git a/Makefile b/Makefile index fbef71da8..7b7a00852 100644 --- a/Makefile +++ b/Makefile @@ -19,3 +19,15 @@ tests: .PHONY: clear-deps clear-deps: rm -rf vendor/ composer.lock + +.PHONY: php-cs-compare +php-cs-compare: + docker/run-task php${PHP_VERSION} vendor/bin/php-cs-fixer fix \ + --diff \ + --dry-run \ + --show-progress=none \ + --verbose + +.PHONY: php-cs-fix +php-cs-fix: + docker/run-task php${PHP_VERSION} vendor/bin/php-cs-fixer fix diff --git a/README.md b/README.md index baa2031a5..77c81f28c 100644 --- a/README.md +++ b/README.md @@ -105,6 +105,17 @@ $ make clear-deps $ PHP_VERSION= make build install-deps ``` +5) Apply Coding Standards + +You should check for CS violations by using +```bash +$ make php-cs-compare +``` +and fix them with +```bash +$ make php-cs-fix +``` + ### Note This project does not have any stable release yet but we do not want to break BC now. diff --git a/composer.json b/composer.json index f855248dc..7c307c213 100644 --- a/composer.json +++ b/composer.json @@ -37,7 +37,8 @@ "akeneo/phpspec-skip-example-extension": "^4.0", "liuggio/fastest": "^1.6", "google/cloud-storage": "~1.0", - "php-opencloud/openstack": "~3.0.0" + "php-opencloud/openstack": "~3.0.0", + "pedrotroller/php-cs-custom-fixer": "^2.17" }, "suggest": { "knplabs/knp-gaufrette-bundle": "to use with Symfony", diff --git a/phpunit.xml.dist b/phpunit.xml.dist index eb20fd9eb..456decf12 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -10,34 +10,7 @@ stopOnFailure="false" bootstrap="vendor/autoload.php" > - - - - - - - - - - - - - - - - - + diff --git a/spec/Gaufrette/Adapter/AzureBlobStorage/BlobProxyFactory.php b/spec/Gaufrette/Adapter/AzureBlobStorage/BlobProxyFactory.php index c5d8178f5..88b9f50c9 100644 --- a/spec/Gaufrette/Adapter/AzureBlobStorage/BlobProxyFactory.php +++ b/spec/Gaufrette/Adapter/AzureBlobStorage/BlobProxyFactory.php @@ -2,19 +2,19 @@ namespace spec\Gaufrette\Adapter\AzureBlobStorage; -use PHPSpec2\ObjectBehavior; +use PhpSpec\ObjectBehavior; class BlobProxyFactory extends ObjectBehavior { /** * @param string $connectionString */ - public function let($connectionString) + function let($connectionString) { $this->beConstructedWith($connectionString); } - public function it_should_be_initializable() + function it_should_be_initializable() { $this->shouldHaveType('Gaufrette\Adapter\AzureBlobStorage\BlobProxyFactory'); $this->shouldHaveType('Gaufrette\Adapter\AzureBlobStorage\BlobProxyFactoryInterface'); diff --git a/spec/Gaufrette/Adapter/AzureBlobStorageSpec.php b/spec/Gaufrette/Adapter/AzureBlobStorageSpec.php index 2f295092d..80e0603a7 100644 --- a/spec/Gaufrette/Adapter/AzureBlobStorageSpec.php +++ b/spec/Gaufrette/Adapter/AzureBlobStorageSpec.php @@ -19,19 +19,19 @@ class AzureBlobStorageSpec extends ObjectBehavior { - public function let(BlobProxyFactoryInterface $blobFactory) + function let(BlobProxyFactoryInterface $blobFactory) { $this->beConstructedWith($blobFactory, 'containerName'); } - public function it_should_be_initializable() + function it_should_be_initializable() { $this->shouldHaveType('Gaufrette\Adapter\AzureBlobStorage'); $this->shouldHaveType('Gaufrette\Adapter'); $this->shouldHaveType('Gaufrette\Adapter\MetadataSupporter'); } - public function it_reads_file(BlobProxyFactoryInterface $blobFactory, IBlob $blob, GetBlobResult $blobContent) + function it_reads_file(BlobProxyFactoryInterface $blobFactory, IBlob $blob, GetBlobResult $blobContent) { $blobFactory->create()->willReturn($blob); @@ -39,13 +39,13 @@ public function it_reads_file(BlobProxyFactoryInterface $blobFactory, IBlob $blo $blobContent ->getContentStream() //azure blob content is handled as stream so we need to fake it - ->willReturn(fopen('data://text/plain,some content','r')) + ->willReturn(fopen('data://text/plain,some content', 'r')) ; $this->read('filename')->shouldReturn('some content'); } - public function it_throws_storage_failure_if_it_fails_to_read_file( + function it_throws_storage_failure_if_it_fails_to_read_file( BlobProxyFactoryInterface $blobFactory, IBlob $blob, ServiceException $azureException, @@ -60,7 +60,7 @@ public function it_throws_storage_failure_if_it_fails_to_read_file( $this->shouldThrow(StorageFailure::class)->duringRead('filename'); } - public function it_throws_file_not_found_if_read_file_does_not_exist( + function it_throws_file_not_found_if_read_file_does_not_exist( BlobProxyFactoryInterface $blobFactory, IBlob $blob, ServiceException $azureException, @@ -75,7 +75,7 @@ public function it_throws_file_not_found_if_read_file_does_not_exist( $this->shouldThrow(FileNotFound::class)->duringRead('filename'); } - public function it_renames_file(BlobProxyFactoryInterface $blobFactory, IBlob $blob) + function it_renames_file(BlobProxyFactoryInterface $blobFactory, IBlob $blob) { $blobFactory->create()->willReturn($blob); @@ -85,7 +85,7 @@ public function it_renames_file(BlobProxyFactoryInterface $blobFactory, IBlob $b $this->shouldNotThrow(\Exception::class)->duringRename('filename1', 'filename2'); } - public function it_throws_storage_failure_when_rename_fail( + function it_throws_storage_failure_when_rename_fail( BlobProxyFactoryInterface $blobFactory, IBlob $blob, ServiceException $azureException, @@ -103,7 +103,7 @@ public function it_throws_storage_failure_when_rename_fail( $this->shouldThrow(StorageFailure::class)->duringRename('filename1', 'filename2'); } - public function it_throws_file_not_found_when_renamed_file_does_not_exist( + function it_throws_file_not_found_when_renamed_file_does_not_exist( BlobProxyFactoryInterface $blobFactory, IBlob $blob, ServiceException $azureException, @@ -121,7 +121,7 @@ public function it_throws_file_not_found_when_renamed_file_does_not_exist( $this->shouldThrow(FileNotFound::class)->duringRename('filename1', 'filename2'); } - public function it_writes_file(BlobProxyFactoryInterface $blobFactory, IBlob $blob) + function it_writes_file(BlobProxyFactoryInterface $blobFactory, IBlob $blob) { $blobFactory->create()->willReturn($blob); @@ -133,7 +133,7 @@ public function it_writes_file(BlobProxyFactoryInterface $blobFactory, IBlob $bl $this->shouldNotThrow(StorageFailure::class)->duringWrite('filename', 'some content'); } - public function it_throws_storage_failure_when_write_fail( + function it_throws_storage_failure_when_write_fail( BlobProxyFactoryInterface $blobFactory, IBlob $blob, ServiceException $azureException, @@ -150,7 +150,7 @@ public function it_throws_storage_failure_when_write_fail( $this->shouldThrow(StorageFailure::class)->duringWrite('filename', 'some content'); } - public function it_checks_if_file_exists( + function it_checks_if_file_exists( BlobProxyFactoryInterface $blobFactory, IBlob $blob, GetBlobResult $blobContent, @@ -168,7 +168,7 @@ public function it_checks_if_file_exists( $this->exists('filename2')->shouldReturn(true); } - public function it_throws_storage_failure_when_it_fails_to_assert_if_a_file_exists( + function it_throws_storage_failure_when_it_fails_to_assert_if_a_file_exists( BlobProxyFactoryInterface $blobFactory, IBlob $blob, ServiceException $azureException, @@ -186,7 +186,7 @@ public function it_throws_storage_failure_when_it_fails_to_assert_if_a_file_exis $this->shouldThrow(StorageFailure::class)->duringExists('filename'); } - public function it_gets_file_mtime( + function it_gets_file_mtime( BlobProxyFactoryInterface $blobFactory, IBlob $blob, GetBlobPropertiesResult $blobPropertiesResult, @@ -201,7 +201,7 @@ public function it_gets_file_mtime( $this->mtime('filename')->shouldReturn(strtotime('1987-12-28 20:00:00')); } - public function it_throws_storage_failure_when_it_fails_to_get_file_mtime( + function it_throws_storage_failure_when_it_fails_to_get_file_mtime( BlobProxyFactoryInterface $blobFactory, IBlob $blob, ServiceException $azureException, @@ -216,7 +216,7 @@ public function it_throws_storage_failure_when_it_fails_to_get_file_mtime( $this->shouldThrow(StorageFailure::class)->duringMtime('filename'); } - public function it_throws_file_not_found_when_it_fails_to_get_file_mtime( + function it_throws_file_not_found_when_it_fails_to_get_file_mtime( BlobProxyFactoryInterface $blobFactory, IBlob $blob, ServiceException $azureException, @@ -231,7 +231,7 @@ public function it_throws_file_not_found_when_it_fails_to_get_file_mtime( $this->shouldThrow(FileNotFound::class)->duringMtime('filename'); } - public function it_deletes_file(BlobProxyFactoryInterface $blobFactory, IBlob $blob) + function it_deletes_file(BlobProxyFactoryInterface $blobFactory, IBlob $blob) { $blobFactory->create()->willReturn($blob); @@ -240,7 +240,7 @@ public function it_deletes_file(BlobProxyFactoryInterface $blobFactory, IBlob $b $this->shouldNotThrow(StorageFailure::class)->duringDelete('filename'); } - public function it_throws_storage_failure_when_it_fails_to_delete_file( + function it_throws_storage_failure_when_it_fails_to_delete_file( BlobProxyFactoryInterface $blobFactory, IBlob $blob, ServiceException $azureException, @@ -255,7 +255,7 @@ public function it_throws_storage_failure_when_it_fails_to_delete_file( $this->shouldThrow(StorageFailure::class)->duringDelete('filename'); } - public function it_throws_file_not_found_when_it_fails_to_delete_file( + function it_throws_file_not_found_when_it_fails_to_delete_file( BlobProxyFactoryInterface $blobFactory, IBlob $blob, ServiceException $azureException, @@ -270,7 +270,7 @@ public function it_throws_file_not_found_when_it_fails_to_delete_file( $this->shouldThrow(FileNotFound::class)->duringDelete('filename'); } - public function it_should_get_keys( + function it_should_get_keys( BlobProxyFactoryInterface $blobFactory, IBlob $blob, Blob $blobFooBar, @@ -288,7 +288,7 @@ public function it_should_get_keys( $this->keys()->shouldReturn(['foo/bar', 'baz']); } - public function it_throws_storage_failure_when_it_fails_to_get_keys( + function it_throws_storage_failure_when_it_fails_to_get_keys( BlobProxyFactoryInterface $blobFactory, IBlob $blob, ServiceException $azureException, @@ -303,7 +303,7 @@ public function it_throws_storage_failure_when_it_fails_to_get_keys( $this->shouldThrow(StorageFailure::class)->duringKeys(); } - public function it_creates_container(BlobProxyFactoryInterface $blobFactory, IBlob $blob) + function it_creates_container(BlobProxyFactoryInterface $blobFactory, IBlob $blob) { $blobFactory->create()->willReturn($blob); @@ -312,7 +312,7 @@ public function it_creates_container(BlobProxyFactoryInterface $blobFactory, IBl $this->createContainer('containerName'); } - public function it_throws_storage_failure_when_it_fails_to_create_container( + function it_throws_storage_failure_when_it_fails_to_create_container( BlobProxyFactoryInterface $blobFactory, IBlob $blob, ServiceException $azureException, diff --git a/spec/Gaufrette/Adapter/DoctrineDbalSpec.php b/spec/Gaufrette/Adapter/DoctrineDbalSpec.php index beeab5047..230f086af 100644 --- a/spec/Gaufrette/Adapter/DoctrineDbalSpec.php +++ b/spec/Gaufrette/Adapter/DoctrineDbalSpec.php @@ -36,15 +36,17 @@ function it_checks_if_file_exists(Connection $connection) { $connection ->quoteIdentifier(Argument::any()) - ->will(function ($argument) { return sprintf('"%s"', $argument[0]); }); + ->will(function ($argument) { + return sprintf('"%s"', $argument[0]); + }); $connection - ->fetchColumn('SELECT COUNT("key") FROM "someTableName" WHERE "key" = :key', array('key' => 'filename')) + ->fetchColumn('SELECT COUNT("key") FROM "someTableName" WHERE "key" = :key', ['key' => 'filename']) ->willReturn(12); $this->exists('filename')->shouldReturn(true); $connection - ->fetchColumn('SELECT COUNT("key") FROM "someTableName" WHERE "key" = :key', array('key' => 'filename')) + ->fetchColumn('SELECT COUNT("key") FROM "someTableName" WHERE "key" = :key', ['key' => 'filename']) ->willReturn(0); $this->exists('filename')->shouldReturn(false); } @@ -53,19 +55,21 @@ function it_writes_to_new_file(Connection $connection) { $connection ->quoteIdentifier(Argument::any()) - ->will(function ($argument) { return sprintf('"%s"', $argument[0]); }); + ->will(function ($argument) { + return sprintf('"%s"', $argument[0]); + }); $connection - ->fetchColumn('SELECT COUNT("key") FROM "someTableName" WHERE "key" = :key', array('key' => 'filename')) + ->fetchColumn('SELECT COUNT("key") FROM "someTableName" WHERE "key" = :key', ['key' => 'filename']) ->willReturn(false); $connection ->insert( 'someTableName', - array( - '"content"' => 'some content', - '"mtime"' => strtotime('2012-10-10 23:10:10'), + [ + '"content"' => 'some content', + '"mtime"' => strtotime('2012-10-10 23:10:10'), '"checksum"' => '9893532233caff98cd083a116b013c0b', - '"key"' => 'filename' - )) + '"key"' => 'filename', + ]) ->shouldBeCalled(); $this->write('filename', 'some content'); @@ -75,21 +79,23 @@ function it_write_file(Connection $connection) { $connection ->quoteIdentifier(Argument::any()) - ->will(function ($argument) { return sprintf('"%s"', $argument[0]); }); + ->will(function ($argument) { + return sprintf('"%s"', $argument[0]); + }); $connection - ->fetchColumn('SELECT COUNT("key") FROM "someTableName" WHERE "key" = :key', array('key' => 'filename')) + ->fetchColumn('SELECT COUNT("key") FROM "someTableName" WHERE "key" = :key', ['key' => 'filename']) ->willReturn(true); $connection ->update( 'someTableName', - array( - '"content"' => 'some content', - '"mtime"' => strtotime('2012-10-10 23:10:10'), + [ + '"content"' => 'some content', + '"mtime"' => strtotime('2012-10-10 23:10:10'), '"checksum"' => '9893532233caff98cd083a116b013c0b', - ), - array( - '"key"' => 'filename' - )) + ], + [ + '"key"' => 'filename', + ]) ->shouldBeCalled(); $this->write('filename', 'some content'); @@ -99,9 +105,11 @@ function it_reads_file(Connection $connection) { $connection ->quoteIdentifier(Argument::any()) - ->will(function ($argument) { return sprintf('"%s"', $argument[0]); }); + ->will(function ($argument) { + return sprintf('"%s"', $argument[0]); + }); $connection - ->fetchColumn('SELECT "content" FROM "someTableName" WHERE "key" = :key', array('key' => 'filename')) + ->fetchColumn('SELECT "content" FROM "someTableName" WHERE "key" = :key', ['key' => 'filename']) ->willReturn('some content'); $this->read('filename')->shouldReturn('some content'); @@ -111,9 +119,11 @@ function it_calculates_checksum(Connection $connection) { $connection ->quoteIdentifier(Argument::any()) - ->will(function ($argument) { return sprintf('"%s"', $argument[0]); }); + ->will(function ($argument) { + return sprintf('"%s"', $argument[0]); + }); $connection - ->fetchColumn('SELECT "checksum" FROM "someTableName" WHERE "key" = :key', array('key' => 'filename')) + ->fetchColumn('SELECT "checksum" FROM "someTableName" WHERE "key" = :key', ['key' => 'filename']) ->willReturn(1234); $this->checksum('filename')->shouldReturn(1234); @@ -123,9 +133,11 @@ function it_gets_mtime(Connection $connection) { $connection ->quoteIdentifier(Argument::any()) - ->will(function ($argument) { return sprintf('"%s"', $argument[0]); }); + ->will(function ($argument) { + return sprintf('"%s"', $argument[0]); + }); $connection - ->fetchColumn('SELECT "mtime" FROM "someTableName" WHERE "key" = :key', array('key' => 'filename')) + ->fetchColumn('SELECT "mtime" FROM "someTableName" WHERE "key" = :key', ['key' => 'filename']) ->willReturn(1234); $this->mtime('filename')->shouldReturn(1234); @@ -135,16 +147,18 @@ function it_renames_file(Connection $connection) { $connection ->quoteIdentifier(Argument::any()) - ->will(function ($argument) { return sprintf('"%s"', $argument[0]); }); + ->will(function ($argument) { + return sprintf('"%s"', $argument[0]); + }); $connection ->update( 'someTableName', - array( - '"key"' => 'newFile', - ), - array( - '"key"' => 'filename' - )) + [ + '"key"' => 'newFile', + ], + [ + '"key"' => 'filename', + ]) ->shouldBeCalled() ->willReturn(1); @@ -153,24 +167,28 @@ function it_renames_file(Connection $connection) function it_get_keys(Connection $connection, Statement $stmt) { - $stmt->fetchAll(\PDO::FETCH_COLUMN)->willReturn(array('filename', 'filename1', 'filename2')); + $stmt->fetchAll(\PDO::FETCH_COLUMN)->willReturn(['filename', 'filename1', 'filename2']); $connection ->quoteIdentifier(Argument::any()) - ->will(function ($argument) { return sprintf('"%s"', $argument[0]); }); + ->will(function ($argument) { + return sprintf('"%s"', $argument[0]); + }); $connection ->executeQuery('SELECT "key" FROM "someTableName"') ->willReturn($stmt); - $this->keys()->shouldReturn(array('filename', 'filename1', 'filename2')); + $this->keys()->shouldReturn(['filename', 'filename1', 'filename2']); } function it_deletes_file(Connection $connection) { $connection ->quoteIdentifier(Argument::any()) - ->will(function ($argument) { return sprintf('"%s"', $argument[0]); }); + ->will(function ($argument) { + return sprintf('"%s"', $argument[0]); + }); $connection - ->delete('someTableName', array('"key"' => 'filename')) + ->delete('someTableName', ['"key"' => 'filename']) ->shouldBeCalled() ->willReturn(1); diff --git a/spec/Gaufrette/Adapter/FlysystemSpec.php b/spec/Gaufrette/Adapter/FlysystemSpec.php index d1f12815f..1dfb87be1 100644 --- a/spec/Gaufrette/Adapter/FlysystemSpec.php +++ b/spec/Gaufrette/Adapter/FlysystemSpec.php @@ -54,7 +54,7 @@ function it_throws_storage_failure_when_the_adapter_returns_an_error_value_when_ function it_writes_file(AdapterInterface $adapter, Config $config) { - $adapter->write('filename', 'Hello.', $config)->willReturn(array()); + $adapter->write('filename', 'Hello.', $config)->willReturn([]); $this->write('filename', 'Hello.')->shouldReturn(null); } diff --git a/spec/Gaufrette/Adapter/FtpSpec.php b/spec/Gaufrette/Adapter/FtpSpec.php index 049942f34..4629d3461 100644 --- a/spec/Gaufrette/Adapter/FtpSpec.php +++ b/spec/Gaufrette/Adapter/FtpSpec.php @@ -88,49 +88,49 @@ function it_does_not_not_rename_file_when_target_file_is_invalid() function it_fetches_keys_without_directories_dots() { - $this->keys()->shouldReturn(array('filename', 'filename.exe', '.htaccess', 'aaa', 'aaa/filename')); + $this->keys()->shouldReturn(['filename', 'filename.exe', '.htaccess', 'aaa', 'aaa/filename']); } function it_fetches_keys_with_spaces_and_unicode_chars() { $this->beConstructedWith('/home/l3l2', 'localhost'); - $this->keys()->shouldReturn(array('Žľuťoučký kůň.pdf', 'a b c d -> žežulička', 'a b c d -> žežulička/do re mi.pdf')); + $this->keys()->shouldReturn(['Žľuťoučký kůň.pdf', 'a b c d -> žežulička', 'a b c d -> žežulička/do re mi.pdf']); } function it_fetches_keys_recursive() { $this->beConstructedWith('/home/l3l3', 'localhost'); - $this->keys()->shouldReturn(array('filename', 'filename.exe', '.htaccess', 'aaa', 'www', 'aaa/filename', 'www/filename', 'www/some', 'www/some/otherfilename')); + $this->keys()->shouldReturn(['filename', 'filename.exe', '.htaccess', 'aaa', 'www', 'aaa/filename', 'www/filename', 'www/some', 'www/some/otherfilename']); } function it_lists_keys() { - $this->listKeys()->shouldReturn(array( - 'keys' => array('filename', 'filename.exe', '.htaccess', 'aaa/filename'), - 'dirs' => array('aaa') - )); + $this->listKeys()->shouldReturn([ + 'keys' => ['filename', 'filename.exe', '.htaccess', 'aaa/filename'], + 'dirs' => ['aaa'], + ]); - $this->listKeys('file')->shouldReturn(array( - 'keys' => array('filename', 'filename.exe'), - 'dirs' => array() - )); + $this->listKeys('file')->shouldReturn([ + 'keys' => ['filename', 'filename.exe'], + 'dirs' => [], + ]); - $this->listKeys('name')->shouldReturn(array( - 'keys' => array(), - 'dirs' => array() - )); + $this->listKeys('name')->shouldReturn([ + 'keys' => [], + 'dirs' => [], + ]); - $this->listKeys('aaa')->shouldReturn(array( - 'keys' => array('aaa/filename'), - 'dirs' => array('aaa') - )); + $this->listKeys('aaa')->shouldReturn([ + 'keys' => ['aaa/filename'], + 'dirs' => ['aaa'], + ]); - $this->listKeys('aaa/')->shouldReturn(array( - 'keys' => array('aaa/filename'), - 'dirs' => array() - )); + $this->listKeys('aaa/')->shouldReturn([ + 'keys' => ['aaa/filename'], + 'dirs' => [], + ]); } function it_fetches_mtime() @@ -173,7 +173,7 @@ function it_fetches_keys_with_hidden_files() { $this->beConstructedWith('/home/l3l1', 'localhost'); - $this->keys()->shouldReturn(array('filename', '.htaccess')); + $this->keys()->shouldReturn(['filename', '.htaccess']); } function it_checks_if_hidden_file_exists() @@ -188,9 +188,9 @@ function it_creates_base_directory_without_warning() global $createdDirectory; $createdDirectory = ''; - $this->beConstructedWith('/home/l3l0/new', 'localhost', array('create' => true)); + $this->beConstructedWith('/home/l3l0/new', 'localhost', ['create' => true]); - $this->listDirectory()->shouldReturn(array('keys' => array(), 'dirs' => array())); + $this->listDirectory()->shouldReturn(['keys' => [], 'dirs' => []]); } function it_does_not_create_base_directory_and_should_throw_exception() @@ -198,16 +198,16 @@ function it_does_not_create_base_directory_and_should_throw_exception() global $createdDirectory; $createdDirectory = ''; - $this->beConstructedWith('/home/l3l0/new', 'localhost', array('create' => false)); + $this->beConstructedWith('/home/l3l0/new', 'localhost', ['create' => false]); - $this->shouldThrow(new \RuntimeException("The directory '/home/l3l0/new' does not exist."))->during('listDirectory', array()); + $this->shouldThrow(new \RuntimeException("The directory '/home/l3l0/new' does not exist."))->during('listDirectory', []); } function it_fetches_keys_for_windows() { $this->beConstructedWith('C:\Ftp', 'localhost'); - $this->keys()->shouldReturn(array('archive', 'file1.zip', 'file2.zip')); + $this->keys()->shouldReturn(['archive', 'file1.zip', 'file2.zip']); } function it_supports_sizecalculator() diff --git a/spec/Gaufrette/Adapter/InMemorySpec.php b/spec/Gaufrette/Adapter/InMemorySpec.php index 92ec93d24..2180e79be 100644 --- a/spec/Gaufrette/Adapter/InMemorySpec.php +++ b/spec/Gaufrette/Adapter/InMemorySpec.php @@ -9,10 +9,10 @@ class InMemorySpec extends ObjectBehavior { function let() { - $this->beConstructedWith(array( - 'filename' => array('mtime' => 12345, 'content' => 'content'), - 'filename2' => 'other content' - )); + $this->beConstructedWith([ + 'filename' => ['mtime' => 12345, 'content' => 'content'], + 'filename2' => 'other content', + ]); } function it_is_adapter() @@ -42,10 +42,10 @@ function it_writes_file() function it_renames_file() { - $this->rename('filename', 'aaa/filename2'); + $this->rename('filename', 'aaa/filename2'); - $this->exists('filename')->shouldReturn(false); - $this->exists('aaa/filename2')->shouldReturn(true); + $this->exists('filename')->shouldReturn(false); + $this->exists('aaa/filename2')->shouldReturn(true); } function it_checks_if_file_exists() @@ -56,7 +56,7 @@ function it_checks_if_file_exists() function it_fetches_keys() { - $this->keys()->shouldReturn(array('filename', 'filename2')); + $this->keys()->shouldReturn(['filename', 'filename2']); } function it_fetches_mtime() diff --git a/spec/Gaufrette/Adapter/LocalSpec.php b/spec/Gaufrette/Adapter/LocalSpec.php index 9066430c8..4a6ad54c8 100644 --- a/spec/Gaufrette/Adapter/LocalSpec.php +++ b/spec/Gaufrette/Adapter/LocalSpec.php @@ -13,8 +13,7 @@ class LocalSpec extends ObjectBehavior function let() { vfsStream::setup('test'); - vfsStream::copyFromFileSystem(__DIR__.'/MockFilesystem'); - + vfsStream::copyFromFileSystem(__DIR__ . '/MockFilesystem'); $this->beConstructedWith(vfsStream::url('test')); } @@ -66,7 +65,7 @@ function it_checks_if_file_exists() function it_fetches_keys() { - $expectedKeys = array('filename', 'dir', 'dir/file'); + $expectedKeys = ['filename', 'dir', 'dir/file']; sort($expectedKeys); $this->keys()->shouldReturn($expectedKeys); } diff --git a/spec/Gaufrette/Adapter/PhpseclibSftpSpec.php b/spec/Gaufrette/Adapter/PhpseclibSftpSpec.php index ec3a9539a..465f3ba37 100644 --- a/spec/Gaufrette/Adapter/PhpseclibSftpSpec.php +++ b/spec/Gaufrette/Adapter/PhpseclibSftpSpec.php @@ -50,21 +50,21 @@ function it_fetches_keys(SFTP $sftp) ->willReturn(true); $sftp ->rawlist('/home/l3l0/') - ->willReturn(array( - 'filename' => array('type' => NET_SFTP_TYPE_REGULAR), - 'filename1' => array('type' => NET_SFTP_TYPE_REGULAR), - 'aaa' => array('type' => NET_SFTP_TYPE_DIRECTORY) - )); + ->willReturn([ + 'filename' => ['type' => NET_SFTP_TYPE_REGULAR], + 'filename1' => ['type' => NET_SFTP_TYPE_REGULAR], + 'aaa' => ['type' => NET_SFTP_TYPE_DIRECTORY], + ]); $sftp ->file_exists('/home/l3l0/aaa') ->willReturn(true); $sftp ->rawlist('/home/l3l0/aaa') - ->willReturn(array( - 'filename' => array('type' => NET_SFTP_TYPE_REGULAR), - )); + ->willReturn([ + 'filename' => ['type' => NET_SFTP_TYPE_REGULAR], + ]); - $this->keys()->shouldReturn(array('filename', 'filename1', 'aaa', 'aaa/filename')); + $this->keys()->shouldReturn(['filename', 'filename1', 'aaa', 'aaa/filename']); } function it_reads_file(SFTP $sftp) @@ -100,9 +100,9 @@ function it_should_check_if_file_exists(SFTP $sftp) { $sftp->pwd()->willReturn('/home/l3l0'); $sftp->chdir('/home/l3l0')->willReturn(true); - $sftp->stat('/home/l3l0/filename')->willReturn(array( - 'name' => '/home/l3l0/filename' - )); + $sftp->stat('/home/l3l0/filename')->willReturn([ + 'name' => '/home/l3l0/filename', + ]); $sftp->stat('/home/l3l0/filename1')->willReturn(false); $this->exists('filename')->shouldReturn(true); @@ -122,10 +122,10 @@ function it_should_check_is_directory(SFTP $sftp) function it_should_create_file(SFTP $sftp, Filesystem $filesystem) { - $sftp->stat('/home/l3l0/filename')->willReturn(array( + $sftp->stat('/home/l3l0/filename')->willReturn([ 'name' => '/home/l3l0/filename', 'size' => '30', - )); + ]); $this->createFile('filename', $filesystem)->beAnInstanceOf('Gaufrette\File'); } diff --git a/spec/Gaufrette/Adapter/functions.php b/spec/Gaufrette/Adapter/functions.php index 4e3a464ec..d2c7e4ff4 100644 --- a/spec/Gaufrette/Adapter/functions.php +++ b/spec/Gaufrette/Adapter/functions.php @@ -49,14 +49,14 @@ function ftp_fget($connection, &$fileResource, $path, $mode) function ftp_chdir($connection, $dirname) { - if (in_array($dirname, array('/home/l3l0', '/home/l3l0/aaa', '/home/l3l0/relative', '/home/l3l0/relative/some', '/home/l3l1', '/home/l3l2', '/home/l3l2/a b c d -> žežulička', '/home/l3l3', 'C:\Ftp'))) { - return true; + if (in_array($dirname, ['/home/l3l0', '/home/l3l0/aaa', '/home/l3l0/relative', '/home/l3l0/relative/some', '/home/l3l1', '/home/l3l2', '/home/l3l2/a b c d -> žežulička', '/home/l3l3', 'C:\Ftp'])) { + return true; } global $createdDirectory; if ($createdDirectory && $createdDirectory === $dirname) { - return true; + return true; } trigger_error(sprintf('%s: No such file or directory', $dirname), E_USER_WARNING); @@ -66,7 +66,7 @@ function ftp_chdir($connection, $dirname) function ftp_mkdir($connection, $dirname) { - if (in_array($dirname, array('/home/l3l0/new'))) { + if (in_array($dirname, ['/home/l3l0/new'])) { global $createdDirectory; $createdDirectory = $dirname; @@ -93,124 +93,113 @@ function ftp_close($connection) function ftp_rawlist($connection, $directory, $recursive = false) { $arguments = explode(' ', $directory, 2); - if ('/home/l3l0' === end($arguments)) - { - return array( - "drwxr-x--- 15 vincent vincent 4096 Nov 3 21:31 .", - "drwxr-x--- 15 vincent vincent 4096 Nov 3 21:31 ..", - "drwxr-x--- 15 vincent vincent 4096 Nov 3 21:31 aaa", - "-rwxr-x--- 15 vincent vincent 4096 Nov 3 21:31 filename", - "-rwxr-x--- 15 vincent vincent 4096 Nov 3 21:31 filename.exe", - "-rwxr-x--- 15 vincent vincent 4096 Nov 3 21:31 .htaccess", - "lrwxrwxrwx 1 vincent vincent 11 Jul 12 12:16 www -> aaa", - "lrwxrwxrwx 1 vincent vincent 11 Jul 12 12:16 vendor -> bbb", - ); + if ('/home/l3l0' === end($arguments)) { + return [ + 'drwxr-x--- 15 vincent vincent 4096 Nov 3 21:31 .', + 'drwxr-x--- 15 vincent vincent 4096 Nov 3 21:31 ..', + 'drwxr-x--- 15 vincent vincent 4096 Nov 3 21:31 aaa', + '-rwxr-x--- 15 vincent vincent 4096 Nov 3 21:31 filename', + '-rwxr-x--- 15 vincent vincent 4096 Nov 3 21:31 filename.exe', + '-rwxr-x--- 15 vincent vincent 4096 Nov 3 21:31 .htaccess', + 'lrwxrwxrwx 1 vincent vincent 11 Jul 12 12:16 www -> aaa', + 'lrwxrwxrwx 1 vincent vincent 11 Jul 12 12:16 vendor -> bbb', + ]; } - if ('/home/l3l0/aaa' === end($arguments)) - { - return array( - "-rwxr-x--- 15 vincent vincent 4096 Nov 3 21:31 filename", - ); + if ('/home/l3l0/aaa' === end($arguments)) { + return [ + '-rwxr-x--- 15 vincent vincent 4096 Nov 3 21:31 filename', + ]; } - if ('/home/l3l0/relative' === end($arguments)) - { - return array( - "-rwxr-x--- 15 vincent vincent 4096 Nov 3 21:31 filename", - "-rwxr-x--- 15 vincent vincent 4096 Nov 3 21:31 some", - ); + if ('/home/l3l0/relative' === end($arguments)) { + return [ + '-rwxr-x--- 15 vincent vincent 4096 Nov 3 21:31 filename', + '-rwxr-x--- 15 vincent vincent 4096 Nov 3 21:31 some', + ]; } - if ('/home/l3l0/relative/some' === end($arguments)) - { - return array( - "-rwxr-x--- 15 vincent vincent 4096 Nov 3 21:31 otherfilename", - ); + if ('/home/l3l0/relative/some' === end($arguments)) { + return [ + '-rwxr-x--- 15 vincent vincent 4096 Nov 3 21:31 otherfilename', + ]; } - if ('/home/l3l1' === end($arguments) && 0 === strpos(reset($arguments), '-al')) - { - return array( - "drwxr-x--- 15 vincent vincent 4096 Nov 3 21:31 .", - "drwxr-x--- 15 vincent vincent 4096 Nov 3 21:31 ..", - "-rwxr-x--- 15 vincent vincent 4096 Nov 3 21:31 filename", - "-rwxr-x--- 15 vincent vincent 4096 Nov 3 21:31 .htaccess", - ); + if ('/home/l3l1' === end($arguments) && 0 === strpos(reset($arguments), '-al')) { + return [ + 'drwxr-x--- 15 vincent vincent 4096 Nov 3 21:31 .', + 'drwxr-x--- 15 vincent vincent 4096 Nov 3 21:31 ..', + '-rwxr-x--- 15 vincent vincent 4096 Nov 3 21:31 filename', + '-rwxr-x--- 15 vincent vincent 4096 Nov 3 21:31 .htaccess', + ]; } - if ('/home/l3l1' === end($arguments) && false === strpos(reset($arguments), '-al')) - { - return array( - "drwxr-x--- 15 vincent vincent 4096 Nov 3 21:31 .", - "drwxr-x--- 15 vincent vincent 4096 Nov 3 21:31 ..", - "-rwxr-x--- 15 vincent vincent 4096 Nov 3 21:31 filename", - ); + if ('/home/l3l1' === end($arguments) && false === strpos(reset($arguments), '-al')) { + return [ + 'drwxr-x--- 15 vincent vincent 4096 Nov 3 21:31 .', + 'drwxr-x--- 15 vincent vincent 4096 Nov 3 21:31 ..', + '-rwxr-x--- 15 vincent vincent 4096 Nov 3 21:31 filename', + ]; } - if ('/home/l3l2' === end($arguments)) - { - return array( - "drwxr-x--- 15 vincent vincent 4096 Nov 3 21:31 .", - "drwxr-x--- 15 vincent vincent 4096 Nov 3 21:31 ..", - "drwxr-x--- 15 vincent vincent 4096 Nov 3 21:31 a b c d -> žežulička", - "-rwxr-x--- 15 vincent vincent 4096 Nov 3 21:31 Žľuťoučký kůň.pdf", - ); + if ('/home/l3l2' === end($arguments)) { + return [ + 'drwxr-x--- 15 vincent vincent 4096 Nov 3 21:31 .', + 'drwxr-x--- 15 vincent vincent 4096 Nov 3 21:31 ..', + 'drwxr-x--- 15 vincent vincent 4096 Nov 3 21:31 a b c d -> žežulička', + '-rwxr-x--- 15 vincent vincent 4096 Nov 3 21:31 Žľuťoučký kůň.pdf', + ]; } - if ('/home/l3l2/a b c d -> žežulička' === end($arguments)) - { - return array( - "drwxr-x--- 15 vincent vincent 4096 Nov 3 21:31 .", - "drwxr-x--- 15 vincent vincent 4096 Nov 3 21:31 ..", - "-rwxr-x--- 15 vincent vincent 4096 Nov 3 21:31 do re mi.pdf", - ); + if ('/home/l3l2/a b c d -> žežulička' === end($arguments)) { + return [ + 'drwxr-x--- 15 vincent vincent 4096 Nov 3 21:31 .', + 'drwxr-x--- 15 vincent vincent 4096 Nov 3 21:31 ..', + '-rwxr-x--- 15 vincent vincent 4096 Nov 3 21:31 do re mi.pdf', + ]; } - if ('/home/l3l3' === end($arguments) && '-alR' === reset($arguments)) - { - return array( - "/home/l3l3:", - "total: 12", - "drwxr-x--- 15 vincent vincent 4096 Nov 3 21:31 .", - "drwxr-x--- 15 vincent vincent 4096 Nov 3 21:31 ..", - "drwxr-x--- 15 vincent vincent 4096 Nov 3 21:31 aaa", - "-rwxr-x--- 15 vincent vincent 4096 Nov 3 21:31 filename", - "-rwxr-x--- 15 vincent vincent 4096 Nov 3 21:31 filename.exe", - "-rwxr-x--- 15 vincent vincent 4096 Nov 3 21:31 .htaccess", - "drwxrwxrwx 1 vincent vincent 11 Jul 12 12:16 www", - "lrwxrwxrwx 1 vincent vincent 11 Jul 12 12:16 vendor -> bbb", - "", - "/home/l3l3/aaa:", - "total: 8", - "-rwxr-x--- 15 vincent vincent 4096 Nov 3 21:31 filename", - "", - "/home/l3l3/www:", - "drwxr-x--- 15 vincent vincent 4096 Nov 3 21:31 .", - "drwxr-x--- 15 vincent vincent 4096 Nov 3 21:31 ..", - "-rwxr-x--- 15 vincent vincent 4096 Nov 3 21:31 filename", - "drwxr-x--- 15 vincent vincent 4096 Nov 3 21:31 some", - "", - "/home/l3l3/www/some:", - "total 5", - "drwxr-x--- 15 vincent vincent 4096 Nov 3 21:31 .", - "drwxr-x--- 15 vincent vincent 4096 Nov 3 21:31 ..", - "-rwxr-x--- 15 vincent vincent 4096 Nov 3 21:31 otherfilename", - ); + if ('/home/l3l3' === end($arguments) && '-alR' === reset($arguments)) { + return [ + '/home/l3l3:', + 'total: 12', + 'drwxr-x--- 15 vincent vincent 4096 Nov 3 21:31 .', + 'drwxr-x--- 15 vincent vincent 4096 Nov 3 21:31 ..', + 'drwxr-x--- 15 vincent vincent 4096 Nov 3 21:31 aaa', + '-rwxr-x--- 15 vincent vincent 4096 Nov 3 21:31 filename', + '-rwxr-x--- 15 vincent vincent 4096 Nov 3 21:31 filename.exe', + '-rwxr-x--- 15 vincent vincent 4096 Nov 3 21:31 .htaccess', + 'drwxrwxrwx 1 vincent vincent 11 Jul 12 12:16 www', + 'lrwxrwxrwx 1 vincent vincent 11 Jul 12 12:16 vendor -> bbb', + '', + '/home/l3l3/aaa:', + 'total: 8', + '-rwxr-x--- 15 vincent vincent 4096 Nov 3 21:31 filename', + '', + '/home/l3l3/www:', + 'drwxr-x--- 15 vincent vincent 4096 Nov 3 21:31 .', + 'drwxr-x--- 15 vincent vincent 4096 Nov 3 21:31 ..', + '-rwxr-x--- 15 vincent vincent 4096 Nov 3 21:31 filename', + 'drwxr-x--- 15 vincent vincent 4096 Nov 3 21:31 some', + '', + '/home/l3l3/www/some:', + 'total 5', + 'drwxr-x--- 15 vincent vincent 4096 Nov 3 21:31 .', + 'drwxr-x--- 15 vincent vincent 4096 Nov 3 21:31 ..', + '-rwxr-x--- 15 vincent vincent 4096 Nov 3 21:31 otherfilename', + ]; } - // https://github.com/KnpLabs/Gaufrette/issues/147 - if ('C:\Ftp' === end($arguments)) - { - return array( - "05-26-12 08:03PM archive", - "12-04-12 06:57PM 16142 file1.zip", - "12-05-12 04:01PM 16142 file2.zip", - ); + if ('C:\Ftp' === end($arguments)) { + return [ + '05-26-12 08:03PM archive', + '12-04-12 06:57PM 16142 file1.zip', + '12-05-12 04:01PM 16142 file2.zip', + ]; } - return array(); + return []; } function ftp_login($connection, $username, $password) @@ -231,7 +220,7 @@ function file_exists($path) { //fake it for ssh+ssl: protocol for SFTP testing, otherwise delegate to global if (strpos($path, 'ssh+ssl:') === 0) { - return in_array($path, array('/home/l3l0/filename', '/home/somedir/filename', 'ssh+ssl://localhost/home/l3l0/filename')) ? true : false; + return in_array($path, ['/home/l3l0/filename', '/home/somedir/filename', 'ssh+ssl://localhost/home/l3l0/filename']) ? true : false; } return \file_exists($path); diff --git a/spec/Gaufrette/FileSpec.php b/spec/Gaufrette/FileSpec.php index cfe5680f5..762b4d5ba 100644 --- a/spec/Gaufrette/FileSpec.php +++ b/spec/Gaufrette/FileSpec.php @@ -7,7 +7,8 @@ interface MetadataAdapter extends \Gaufrette\Adapter, \Gaufrette\Adapter\MetadataSupporter -{} +{ +} class FileSpec extends ObjectBehavior { @@ -42,7 +43,7 @@ function it_gets_mtime(Filesystem $filesystem) function it_pass_metadata_when_write_content(Filesystem $filesystem, MetadataAdapter $adapter) { - $metadata = array('id' => '123'); + $metadata = ['id' => '123']; $adapter->setMetadata('filename', $metadata)->shouldBeCalled(); $filesystem->write('filename', 'some content', true)->willReturn(12); $filesystem->getAdapter()->willReturn($adapter); @@ -52,7 +53,7 @@ function it_pass_metadata_when_write_content(Filesystem $filesystem, MetadataAda function it_pass_metadata_when_read_content(Filesystem $filesystem, MetadataAdapter $adapter) { - $metadata = array('id' => '123'); + $metadata = ['id' => '123']; $adapter->setMetadata('filename', $metadata)->shouldBeCalled(); $filesystem->read('filename')->willReturn('some content'); $filesystem->getAdapter()->willReturn($adapter); @@ -62,7 +63,7 @@ function it_pass_metadata_when_read_content(Filesystem $filesystem, MetadataAdap function it_pass_metadata_when_delete_content(Filesystem $filesystem, MetadataAdapter $adapter) { - $metadata = array('id' => '123'); + $metadata = ['id' => '123']; $adapter->setMetadata('filename', $metadata)->shouldBeCalled(); $filesystem->delete('filename')->willReturn(true); $filesystem->getAdapter()->willReturn($adapter); @@ -72,7 +73,7 @@ function it_pass_metadata_when_delete_content(Filesystem $filesystem, MetadataAd function it_sets_content_of_file(Filesystem $filesystem, MetadataAdapter $adapter) { - $adapter->setMetadata('filename', array())->shouldNotBeCalled(); + $adapter->setMetadata('filename', [])->shouldNotBeCalled(); $filesystem->getAdapter()->willReturn($adapter); $filesystem->write('filename', 'some content', true)->shouldBeCalled()->willReturn(21); diff --git a/spec/Gaufrette/FilesystemMapSpec.php b/spec/Gaufrette/FilesystemMapSpec.php index 59282180b..026f8f3b0 100644 --- a/spec/Gaufrette/FilesystemMapSpec.php +++ b/spec/Gaufrette/FilesystemMapSpec.php @@ -57,6 +57,6 @@ function it_removes_all_filesystems(FilesystemInterface $filesystem) $this->has('some')->shouldReturn(false); $this->has('other')->shouldReturn(false); - $this->all()->shouldReturn(array()); + $this->all()->shouldReturn([]); } } diff --git a/spec/Gaufrette/FilesystemSpec.php b/spec/Gaufrette/FilesystemSpec.php index caa861c4d..2bb4199f5 100644 --- a/spec/Gaufrette/FilesystemSpec.php +++ b/spec/Gaufrette/FilesystemSpec.php @@ -14,7 +14,8 @@ interface ExtendedAdapter extends \Gaufrette\Adapter, \Gaufrette\Adapter\ChecksumCalculator, \Gaufrette\Adapter\MetadataSupporter, \Gaufrette\Adapter\MimeTypeProvider -{} +{ +} class FilesystemSpec extends ObjectBehavior { @@ -214,7 +215,7 @@ function it_fails_when_delete_is_not_successful(Adapter $adapter) function it_should_get_all_keys(Adapter $adapter) { - $keys = array('filename', 'filename1', 'filename2'); + $keys = ['filename', 'filename1', 'filename2']; $adapter->keys()->willReturn($keys); $this->keys()->shouldReturn($keys); @@ -222,34 +223,34 @@ function it_should_get_all_keys(Adapter $adapter) function it_match_listed_keys_using_specified_pattern(Adapter $adapter) { - $keys = array('filename', 'filename1', 'filename2', 'testKey', 'KeyTest', 'testkey'); + $keys = ['filename', 'filename1', 'filename2', 'testKey', 'KeyTest', 'testkey']; $adapter->keys()->willReturn($keys); $adapter->isDirectory(Argument::any())->willReturn(false); $this->listKeys()->shouldReturn( - array( - 'keys' => array('filename', 'filename1', 'filename2', 'testKey', 'KeyTest', 'testkey'), - 'dirs' => array() - ) + [ + 'keys' => ['filename', 'filename1', 'filename2', 'testKey', 'KeyTest', 'testkey'], + 'dirs' => [], + ] ); $this->listKeys('filename')->shouldReturn( - array( - 'keys' => array('filename', 'filename1', 'filename2'), - 'dirs' => array() - ) + [ + 'keys' => ['filename', 'filename1', 'filename2'], + 'dirs' => [], + ] ); $this->listKeys('Key')->shouldReturn( - array( - 'keys' => array('KeyTest'), - 'dirs' => array() - ) + [ + 'keys' => ['KeyTest'], + 'dirs' => [], + ] ); } function it_listing_directories_using_adapter_is_directory_method(Adapter $adapter) { - $keys = array('filename', 'filename1', 'filename2', 'testKey', 'KeyTest', 'testkey'); + $keys = ['filename', 'filename1', 'filename2', 'testKey', 'KeyTest', 'testkey']; $adapter->keys()->willReturn($keys); $adapter->isDirectory('filename')->willReturn(false); @@ -261,22 +262,22 @@ function it_listing_directories_using_adapter_is_directory_method(Adapter $adapt $adapter->isDirectory('testKey')->willReturn(true); $this->listKeys()->shouldReturn( - array( - 'keys' => array('filename', 'filename2', 'KeyTest', 'testkey'), - 'dirs' => array('filename1', 'testKey') - ) + [ + 'keys' => ['filename', 'filename2', 'KeyTest', 'testkey'], + 'dirs' => ['filename1', 'testKey'], + ] ); $this->listKeys('filename')->shouldReturn( - array( - 'keys' => array('filename', 'filename2'), - 'dirs' => array('filename1') - ) + [ + 'keys' => ['filename', 'filename2'], + 'dirs' => ['filename1'], + ] ); $this->listKeys('Key')->shouldReturn( - array( - 'keys' => array('KeyTest'), - 'dirs' => array() - ) + [ + 'keys' => ['KeyTest'], + 'dirs' => [], + ] ); } diff --git a/spec/Gaufrette/StreamWrapperSpec.php b/spec/Gaufrette/StreamWrapperSpec.php index 273161454..613d2b4b8 100644 --- a/spec/Gaufrette/StreamWrapperSpec.php +++ b/spec/Gaufrette/StreamWrapperSpec.php @@ -153,21 +153,21 @@ function it_does_not_get_stat_when_is_not_open() function it_stats_file(Stream $stream) { - $stat = array( - 'dev' => 1, - 'ino' => 12, - 'mode' => 0777, + $stat = [ + 'dev' => 1, + 'ino' => 12, + 'mode' => 0777, 'nlink' => 0, - 'uid' => 123, - 'gid' => 1, - 'rdev' => 0, - 'size' => 666, + 'uid' => 123, + 'gid' => 1, + 'rdev' => 0, + 'size' => 666, 'atime' => 1348030800, 'mtime' => 1348030800, 'ctime' => 1348030800, 'blksize' => 5, - 'blocks' => 1, - ); + 'blocks' => 1, + ]; $stream->open(Argument::any())->willReturn(true); $stream->stat()->willReturn($stat); @@ -177,21 +177,21 @@ function it_stats_file(Stream $stream) function it_should_stat_from_url(Stream $stream) { - $stat = array( - 'dev' => 1, - 'ino' => 12, - 'mode' => 0777, + $stat = [ + 'dev' => 1, + 'ino' => 12, + 'mode' => 0777, 'nlink' => 0, - 'uid' => 123, - 'gid' => 1, - 'rdev' => 0, - 'size' => 666, + 'uid' => 123, + 'gid' => 1, + 'rdev' => 0, + 'size' => 666, 'atime' => 1348030800, 'mtime' => 1348030800, 'ctime' => 1348030800, 'blksize' => 5, - 'blocks' => 1, - ); + 'blocks' => 1, + ]; $stream->open(Argument::any())->willReturn(true); $stream->stat()->willReturn($stat); @@ -202,8 +202,8 @@ function it_stats_even_if_it_cannot_be_open(Filesystem $filesystem, Stream $stre { $filesystem->createStream('dir/')->willReturn($stream); $stream->open(Argument::any())->willThrow(new \RuntimeException); - $stream->stat(Argument::any())->willReturn(array('mode' => 16893)); - $this->url_stat('gaufrette://some/dir/', STREAM_URL_STAT_LINK)->shouldReturn(array('mode' => 16893)); + $stream->stat(Argument::any())->willReturn(['mode' => 16893]); + $this->url_stat('gaufrette://some/dir/', STREAM_URL_STAT_LINK)->shouldReturn(['mode' => 16893]); } function it_does_not_unlink_when_cannot_open(Stream $stream) diff --git a/spec/Gaufrette/Util/ChecksumSpec.php b/spec/Gaufrette/Util/ChecksumSpec.php index 24bae68ce..dc4546a13 100644 --- a/spec/Gaufrette/Util/ChecksumSpec.php +++ b/spec/Gaufrette/Util/ChecksumSpec.php @@ -8,24 +8,30 @@ class ChecksumSpec extends ObjectBehavior { function let() { - $path = __DIR__.DIRECTORY_SEPARATOR.'testFile'; - file_put_contents($path, 'some other content'); + file_put_contents($this->getTestFilePath(), 'some other content'); + } + + function letGo() + { + @unlink($this->getTestFilePath()); } function it_calculates_checksum_from_content() { - $this->fromContent('some content')->shouldReturn(md5('some content')); + $this->fromContent('some content') + ->shouldReturn(md5('some content')) + ; } function it_calculates_checksum_from_filepath() { - $path = __DIR__.DIRECTORY_SEPARATOR.'testFile'; - $this->fromFile($path)->shouldReturn(md5('some other content')); + $this->fromFile($this->getTestFilePath()) + ->shouldReturn(md5('some other content')) + ; } - function letgo() + private function getTestFilePath(): string { - $path = __DIR__.DIRECTORY_SEPARATOR.'testFile'; - @unlink(__DIR__.DIRECTORY_SEPARATOR.'testFile'); + return __DIR__ . DIRECTORY_SEPARATOR . 'testFile'; } } diff --git a/src/Gaufrette/Adapter/AwsS3.php b/src/Gaufrette/Adapter/AwsS3.php index de4ccb6ab..0a3bed7f4 100644 --- a/src/Gaufrette/Adapter/AwsS3.php +++ b/src/Gaufrette/Adapter/AwsS3.php @@ -7,18 +7,13 @@ use Aws\S3\S3Client; use Gaufrette\Exception\FileNotFound; use Gaufrette\Exception\StorageFailure; -use Gaufrette\Util; /** * Amazon S3 adapter using the AWS SDK for PHP v2.x. * * @author Michael Dowling */ -class AwsS3 implements Adapter, - MetadataSupporter, - ListKeysAware, - SizeCalculator, - MimeTypeProvider +class AwsS3 implements Adapter, MetadataSupporter, ListKeysAware, SizeCalculator, MimeTypeProvider { /** @var S3Client */ protected $service; @@ -116,7 +111,7 @@ public function rename($sourceKey, $targetKey) $this->ensureBucketExists(); $options = $this->getOptions( $targetKey, - ['CopySource' => $this->bucket.'/'.$this->computePath($sourceKey)] + ['CopySource' => $this->bucket . '/' . $this->computePath($sourceKey)] ); try { @@ -270,7 +265,7 @@ public function isDirectory($key) { $result = $this->service->listObjects([ 'Bucket' => $this->bucket, - 'Prefix' => rtrim($this->computePath($key), '/').'/', + 'Prefix' => rtrim($this->computePath($key), '/') . '/', 'MaxKeys' => 1, ]); if (isset($result['Contents'])) { @@ -310,7 +305,7 @@ protected function ensureBucketExists() $this->service->createBucket([ 'Bucket' => $this->bucket, - 'LocationConstraint' => $this->service->getRegion() + 'LocationConstraint' => $this->service->getRegion(), ]); $this->bucketExists = true; @@ -373,6 +368,7 @@ public function mimeType($key) { try { $result = $this->service->headObject($this->getOptions($key)); + return ($result['ContentType']); } catch (\Exception $e) { if ($e instanceof S3Exception && $e->getResponse()->getStatusCode() === 404) { diff --git a/src/Gaufrette/Adapter/AzureBlobStorage.php b/src/Gaufrette/Adapter/AzureBlobStorage.php index eb4f9534a..4506c463a 100644 --- a/src/Gaufrette/Adapter/AzureBlobStorage.php +++ b/src/Gaufrette/Adapter/AzureBlobStorage.php @@ -18,11 +18,7 @@ * @author Luciano Mammino * @author Paweł Czyżewski */ -class AzureBlobStorage implements Adapter, - MetadataSupporter, - SizeCalculator, - ChecksumCalculator - +class AzureBlobStorage implements Adapter, MetadataSupporter, SizeCalculator, ChecksumCalculator { /** * Error constants. @@ -358,7 +354,6 @@ public function size($key) 'key' => $key, ], $e); } - } /** @@ -568,11 +563,12 @@ private function fetchBlobs($containerName, $prefix = null) { $blobList = $this->blobProxy->listBlobs($containerName); - return array_map(function (Blob $blob) use ($prefix) { + return array_map( + function (Blob $blob) use ($prefix) { $name = $blob->getName(); if (null !== $prefix) { - $name = $prefix .'/'. $name; + $name = $prefix . '/' . $name; } return $name; diff --git a/src/Gaufrette/Adapter/DoctrineDbal.php b/src/Gaufrette/Adapter/DoctrineDbal.php index 2c59af3a2..59093623c 100644 --- a/src/Gaufrette/Adapter/DoctrineDbal.php +++ b/src/Gaufrette/Adapter/DoctrineDbal.php @@ -15,25 +15,23 @@ * @author Antoine Hérault * @author Leszek Prabucki */ -class DoctrineDbal implements Adapter, - ChecksumCalculator, - ListKeysAware +class DoctrineDbal implements Adapter, ChecksumCalculator, ListKeysAware { protected $connection; protected $table; - protected $columns = array( + protected $columns = [ 'key' => 'key', 'content' => 'content', 'mtime' => 'mtime', 'checksum' => 'checksum', - ); + ]; /** * @param Connection $connection The DBAL connection * @param string $table The files table * @param array $columns The column names */ - public function __construct(Connection $connection, $table, array $columns = array()) + public function __construct(Connection $connection, $table, array $columns = []) { $this->connection = $connection; $this->table = $table; @@ -66,8 +64,8 @@ public function rename($sourceKey, $targetKey) try { $updated = $this->connection->update( $this->table, - array($this->getQuotedColumn('key') => $targetKey), - array($this->getQuotedColumn('key') => $sourceKey) + [$this->getQuotedColumn('key') => $targetKey], + [$this->getQuotedColumn('key') => $sourceKey] ); } catch (\Exception $e) { throw StorageFailure::unexpectedFailure('rename', [ @@ -130,7 +128,7 @@ public function exists($key) $this->getQuotedTable(), $this->getQuotedColumn('key') ), - array('key' => $key) + ['key' => $key] ); } catch (\Exception $e) { throw StorageFailure::unexpectedFailure('exists', ['key' => $key], $e); @@ -163,7 +161,7 @@ public function delete($key) try { $deleted = $this->connection->delete( $this->table, - array($this->getQuotedColumn('key') => $key) + [$this->getQuotedColumn('key') => $key] ); } catch (\Exception $e) { throw StorageFailure::unexpectedFailure('delete', ['key' => $key], $e); @@ -179,11 +177,11 @@ public function delete($key) */ public function write($key, $content) { - $values = array( + $values = [ $this->getQuotedColumn('content') => $content, $this->getQuotedColumn('mtime') => time(), $this->getQuotedColumn('checksum') => Util\Checksum::fromContent($content), - ); + ]; try { $this->upsert($key, $values); @@ -202,7 +200,7 @@ private function upsert($key, array $values) $this->connection->update( $this->table, $values, - array($this->getQuotedColumn('key') => $key) + [$this->getQuotedColumn('key') => $key] ); } else { $values[$this->getQuotedColumn('key')] = $key; @@ -229,7 +227,7 @@ private function getColumnValue($key, $column) $this->getQuotedTable(), $this->getQuotedColumn('key') ), - array('key' => $key) + ['key' => $key] ); return $value; @@ -249,16 +247,16 @@ public function listKeys($prefix = '') $this->getQuotedTable(), $this->getQuotedColumn('key') ), - array('pattern' => sprintf('%s%%', $prefix)) + ['pattern' => sprintf('%s%%', $prefix)] ); - return array( - 'dirs' => array(), + return [ + 'dirs' => [], 'keys' => array_map(function ($value) { - return $value['_key']; - }, + return $value['_key']; + }, $keys), - ); + ]; } private function getQuotedTable() diff --git a/src/Gaufrette/Adapter/Ftp.php b/src/Gaufrette/Adapter/Ftp.php index 0a314fc6e..5f4dc145b 100644 --- a/src/Gaufrette/Adapter/Ftp.php +++ b/src/Gaufrette/Adapter/Ftp.php @@ -12,10 +12,7 @@ * * @author Antoine Hérault */ -class Ftp implements Adapter, - FileFactory, - ListKeysAware, - SizeCalculator +class Ftp implements Adapter, FileFactory, ListKeysAware, SizeCalculator { protected $connection = null; protected $directory; @@ -28,7 +25,7 @@ class Ftp implements Adapter, protected $mode; protected $ssl; protected $timeout; - protected $fileData = array(); + protected $fileData = []; protected $utf8; /** @@ -36,7 +33,7 @@ class Ftp implements Adapter, * @param string $host The host of the ftp server * @param array $options The options like port, username, password, passive, create, mode */ - public function __construct($directory, $host, $options = array()) + public function __construct($directory, $host, $options = []) { if (!extension_loaded('ftp')) { throw new \RuntimeException('Unable to use Gaufrette\Adapter\Ftp as the FTP extension is not available.'); @@ -44,15 +41,15 @@ public function __construct($directory, $host, $options = array()) $this->directory = (string) $directory; $this->host = $host; - $this->port = isset($options['port']) ? $options['port'] : 21; - $this->username = isset($options['username']) ? $options['username'] : null; - $this->password = isset($options['password']) ? $options['password'] : null; - $this->passive = isset($options['passive']) ? $options['passive'] : false; - $this->create = isset($options['create']) ? $options['create'] : false; - $this->mode = isset($options['mode']) ? $options['mode'] : FTP_BINARY; - $this->ssl = isset($options['ssl']) ? $options['ssl'] : false; - $this->timeout = isset($options['timeout']) ? $options['timeout'] : 90; - $this->utf8 = isset($options['utf8']) ? $options['utf8'] : false; + $this->port = $options['port'] ?? 21; + $this->username = $options['username'] ?? null; + $this->password = $options['password'] ?? null; + $this->passive = $options['passive'] ?? false; + $this->create = $options['create'] ?? false; + $this->mode = $options['mode'] ?? FTP_BINARY; + $this->ssl = $options['ssl'] ?? false; + $this->timeout = $options['timeout'] ?? 90; + $this->utf8 = $options['utf8'] ?? false; } /** @@ -93,6 +90,7 @@ public function write($key, $content) if (!ftp_fput($this->getConnection(), $path, $temp, $this->mode)) { fclose($temp); + throw StorageFailure::unexpectedFailure('write', ['key' => $this->computePath($key)]); } @@ -126,14 +124,14 @@ public function exists($key) { $this->ensureDirectoryExists($this->directory, $this->create); - $file = $this->computePath($key); + $file = $this->computePath($key); $lines = ftp_rawlist($this->getConnection(), '-al ' . \Gaufrette\Util\Path::dirname($file)); if (false === $lines) { return false; } - $pattern = '{(?) '.preg_quote(basename($file)).'( -> |$)}m'; + $pattern = '{(?) ' . preg_quote(basename($file)) . '( -> |$)}m'; foreach ($lines as $line) { if (preg_match($pattern, $line)) { return true; @@ -171,9 +169,9 @@ public function listKeys($prefix = '') return $keys; } - $filteredKeys = array(); - foreach (array('keys', 'dirs') as $hash) { - $filteredKeys[$hash] = array(); + $filteredKeys = []; + foreach (['keys', 'dirs'] as $hash) { + $filteredKeys[$hash] = []; foreach ($keys[$hash] as $key) { if (0 === strpos($key, $prefix)) { $filteredKeys[$hash][] = $key; @@ -247,21 +245,21 @@ public function listDirectory($directory = '') $directory = preg_replace('/^[\/]*([^\/].*)$/', '/$1', $directory); $items = $this->parseRawlist( - ftp_rawlist($this->getConnection(), '-al '.$this->directory.$directory) ?: array() + ftp_rawlist($this->getConnection(), '-al ' . $this->directory . $directory) ?: [] ); - $fileData = $dirs = array(); + $fileData = $dirs = []; foreach ($items as $itemData) { if ('..' === $itemData['name'] || '.' === $itemData['name']) { continue; } - $item = array( + $item = [ 'name' => $itemData['name'], - 'path' => trim(($directory ? $directory.'/' : '').$itemData['name'], '/'), + 'path' => trim(($directory ? $directory . '/' : '') . $itemData['name'], '/'), 'time' => $itemData['time'], 'size' => $itemData['size'], - ); + ]; if ('-' === substr($itemData['perms'], 0, 1)) { $fileData[$item['path']] = $item; @@ -272,10 +270,10 @@ public function listDirectory($directory = '') $this->fileData = array_merge($fileData, $this->fileData); - return array( + return [ 'keys' => array_keys($fileData), 'dirs' => $dirs, - ); + ]; } /** @@ -392,28 +390,28 @@ private function fetchKeys($directory = '', $onlyKeys = true) { $directory = preg_replace('/^[\/]*([^\/].*)$/', '/$1', $directory); - $lines = ftp_rawlist($this->getConnection(), '-alR '.$this->directory.$directory); + $lines = ftp_rawlist($this->getConnection(), '-alR ' . $this->directory . $directory); if (false === $lines) { - return array('keys' => array(), 'dirs' => array()); + return ['keys' => [], 'dirs' => []]; } - $regexDir = '/'.preg_quote($this->directory.$directory, '/').'\/?(.+):$/u'; + $regexDir = '/' . preg_quote($this->directory . $directory, '/') . '\/?(.+):$/u'; $regexItem = '/^(?:([d\-\d])\S+)\s+\S+(?:(?:\s+\S+){5})?\s+(\S+)\s+(.+?)$/'; $prevLine = null; - $directories = array(); - $keys = array('keys' => array(), 'dirs' => array()); + $directories = []; + $keys = ['keys' => [], 'dirs' => []]; foreach ((array) $lines as $line) { if ('' === $prevLine && preg_match($regexDir, $line, $match)) { $directory = $match[1]; unset($directories[$directory]); if ($onlyKeys) { - $keys = array( + $keys = [ 'keys' => array_merge($keys['keys'], $keys['dirs']), - 'dirs' => array(), - ); + 'dirs' => [], + ]; } } elseif (preg_match($regexItem, $line, $tokens)) { $name = $tokens[3]; @@ -422,7 +420,7 @@ private function fetchKeys($directory = '', $onlyKeys = true) continue; } - $path = ltrim($directory.'/'.$name, '/'); + $path = ltrim($directory . '/' . $name, '/'); if ('d' === $tokens[1] || '' === $tokens[2]) { $keys['dirs'][] = $path; @@ -435,10 +433,10 @@ private function fetchKeys($directory = '', $onlyKeys = true) } if ($onlyKeys) { - $keys = array( + $keys = [ 'keys' => array_merge($keys['keys'], $keys['dirs']), - 'dirs' => array(), - ); + 'dirs' => [], + ]; } foreach (array_keys($directories) as $directory) { @@ -457,30 +455,30 @@ private function fetchKeys($directory = '', $onlyKeys = true) */ private function parseRawlist(array $rawlist) { - $parsed = array(); + $parsed = []; foreach ($rawlist as $line) { $infos = preg_split("/[\s]+/", $line, 9); if ($this->isLinuxListing($infos)) { - $infos[7] = (strrpos($infos[7], ':') != 2) ? ($infos[7].' 00:00') : (date('Y').' '.$infos[7]); + $infos[7] = (strrpos($infos[7], ':') != 2) ? ($infos[7] . ' 00:00') : (date('Y') . ' ' . $infos[7]); if ('total' !== $infos[0]) { - $parsed[] = array( + $parsed[] = [ 'perms' => $infos[0], 'num' => $infos[1], 'size' => $infos[4], - 'time' => strtotime($infos[5].' '.$infos[6].'. '.$infos[7]), + 'time' => strtotime($infos[5] . ' ' . $infos[6] . '. ' . $infos[7]), 'name' => $infos[8], - ); + ]; } } elseif (count($infos) >= 4) { $isDir = (boolean) ('' === $infos[2]); - $parsed[] = array( + $parsed[] = [ 'perms' => $isDir ? 'd' : '-', 'num' => '', 'size' => $isDir ? '' : $infos[2], - 'time' => strtotime($infos[0].' '.$infos[1]), + 'time' => strtotime($infos[0] . ' ' . $infos[1]), 'name' => $infos[3], - ); + ]; } } @@ -494,7 +492,7 @@ private function parseRawlist(array $rawlist) */ private function computePath($key) { - return rtrim($this->directory, '/').'/'.$key; + return rtrim($this->directory, '/') . '/' . $key; } /** @@ -556,18 +554,20 @@ private function connect() // login ftp user if (!@ftp_login($this->connection, $username, $password)) { $this->close(); + throw new \RuntimeException(sprintf('Could not login as %s.', $username)); } // switch to passive mode if needed if ($this->passive && !ftp_pasv($this->connection, true)) { $this->close(); + throw new \RuntimeException('Could not turn passive mode on.'); } // enable utf8 mode if configured - if($this->utf8 == true) { - ftp_raw($this->connection, "OPTS UTF8 ON"); + if ($this->utf8 == true) { + ftp_raw($this->connection, 'OPTS UTF8 ON'); } // ensure the adapter's directory exists @@ -576,12 +576,14 @@ private function connect() $this->ensureDirectoryExists($this->directory, $this->create); } catch (\RuntimeException $e) { $this->close(); + throw $e; } // change the current directory for the adapter's directory if (!ftp_chdir($this->connection, $this->directory)) { $this->close(); + throw new \RuntimeException(sprintf('Could not change current directory for the \'%s\' directory.', $this->directory)); } } diff --git a/src/Gaufrette/Adapter/GoogleCloudStorage.php b/src/Gaufrette/Adapter/GoogleCloudStorage.php index aad4ca6f7..3476d95c1 100644 --- a/src/Gaufrette/Adapter/GoogleCloudStorage.php +++ b/src/Gaufrette/Adapter/GoogleCloudStorage.php @@ -2,8 +2,6 @@ namespace Gaufrette\Adapter; use Gaufrette\Adapter; -use Gaufrette\Adapter\MetadataSupporter; -use Gaufrette\Adapter\ListKeysAware; use Gaufrette\Exception\FileNotFound; use Gaufrette\Exception\StorageFailure; use Google\Cloud\Exception\NotFoundException; @@ -29,23 +27,23 @@ final class GoogleCloudStorage implements Adapter, MetadataSupporter, ListKeysAw * @var Bucket */ private $bucket; - private $options = array(); - private $metadata = array(); + private $options = []; + private $metadata = []; /** * @param StorageClient $service Authenticated storage client class * @param string $bucketName Name of the bucket * @param array $options Options are: "directory" and "acl" (see https://cloud.google.com/storage/docs/access-control/lists) */ - public function __construct(StorageClient $storageClient, string $bucketName, $options = array()) + public function __construct(StorageClient $storageClient, string $bucketName, $options = []) { $this->storageClient = $storageClient; $this->initBucket($bucketName); $this->options = array_replace_recursive( - array( + [ 'directory' => '', - 'acl' => array(), - ), + 'acl' => [], + ], $options ); $this->options['directory'] = rtrim($this->options['directory'], '/'); @@ -102,10 +100,10 @@ public function read($key) */ public function write($key, $content) { - $options = array( - 'resumable' => true, - 'name' => $this->computePath($key), - ); + $options = [ + 'resumable' => true, + 'name' => $this->computePath($key), + ]; try { $object = $this->bucket->upload( @@ -132,7 +130,7 @@ public function exists($key) */ public function isDirectory($key) { - return $this->exists($this->computePath(rtrim($key, '/')).'/'); + return $this->exists($this->computePath(rtrim($key, '/')) . '/'); } /** @@ -263,7 +261,7 @@ public function setMetadata($key, $metadata) private function computePath($key = null) { if (strlen($this->options['directory'])) { - return $this->options['directory'].'/'.$key; + return $this->options['directory'] . '/' . $key; } return $key; diff --git a/src/Gaufrette/Adapter/GridFS.php b/src/Gaufrette/Adapter/GridFS.php index 2ba149489..e2de72a52 100644 --- a/src/Gaufrette/Adapter/GridFS.php +++ b/src/Gaufrette/Adapter/GridFS.php @@ -16,11 +16,7 @@ * @author Antoine Hérault * @author Leszek Prabucki */ -class GridFS implements Adapter, - ChecksumCalculator, - MetadataSupporter, - ListKeysAware, - SizeCalculator +class GridFS implements Adapter, ChecksumCalculator, MetadataSupporter, ListKeysAware, SizeCalculator { /** @var array */ private $metadata = []; @@ -176,7 +172,6 @@ public function checksum($key) */ public function delete($key) { - try { $file = $this->bucket->findOne(['filename' => $key], ['projection' => ['_id' => 1]]); } catch (\Exception $e) { @@ -209,17 +204,16 @@ public function getMetadata($key) { if (isset($this->metadata[$key])) { return $this->metadata[$key]; - } else { - $meta = $this->bucket->findOne(['filename' => $key], ['projection' => ['metadata' => 1,'_id' => 0]]); + } + $meta = $this->bucket->findOne(['filename' => $key], ['projection' => ['metadata' => 1,'_id' => 0]]); - if ($meta === null || !isset($meta['metadata'])) { - return array(); - } + if ($meta === null || !isset($meta['metadata'])) { + return []; + } - $this->metadata[$key] = iterator_to_array($meta['metadata']); + $this->metadata[$key] = iterator_to_array($meta['metadata']); - return $this->metadata[$key]; - } + return $this->metadata[$key]; } /** @@ -273,5 +267,4 @@ public function size($key) return $size['length']; } - } diff --git a/src/Gaufrette/Adapter/InMemory.php b/src/Gaufrette/Adapter/InMemory.php index f27185799..2c08f0f0e 100644 --- a/src/Gaufrette/Adapter/InMemory.php +++ b/src/Gaufrette/Adapter/InMemory.php @@ -4,7 +4,6 @@ use Gaufrette\Adapter; use Gaufrette\Exception\FileNotFound; -use Gaufrette\Util; /** * In memory adapter. @@ -13,15 +12,14 @@ * * @author Antoine Hérault */ -class InMemory implements Adapter, - MimeTypeProvider +class InMemory implements Adapter, MimeTypeProvider { - protected $files = array(); + protected $files = []; /** * @param array $files An array of files */ - public function __construct(array $files = array()) + public function __construct(array $files = []) { $this->setFiles($files); } @@ -33,16 +31,16 @@ public function __construct(array $files = array()) */ public function setFiles(array $files) { - $this->files = array(); + $this->files = []; foreach ($files as $key => $file) { if (!is_array($file)) { - $file = array('content' => $file); + $file = ['content' => $file]; } - $file = array_merge(array( + $file = array_merge([ 'content' => null, 'mtime' => null, - ), $file); + ], $file); $this->setFile($key, $file['content'], $file['mtime']); } @@ -61,10 +59,10 @@ public function setFile($key, $content = null, $mtime = null) $mtime = time(); } - $this->files[$key] = array( + $this->files[$key] = [ 'content' => (string) $content, 'mtime' => (integer) $mtime, - ); + ]; } /** diff --git a/src/Gaufrette/Adapter/Local.php b/src/Gaufrette/Adapter/Local.php index eb30227d1..c48a21dec 100644 --- a/src/Gaufrette/Adapter/Local.php +++ b/src/Gaufrette/Adapter/Local.php @@ -9,18 +9,13 @@ use Gaufrette\Adapter; use Gaufrette\Stream; - /** * Adapter for the local filesystem. * * @author Antoine Hérault * @author Leszek Prabucki */ -class Local implements Adapter, - StreamFactory, - ChecksumCalculator, - SizeCalculator, - MimeTypeProvider +class Local implements Adapter, StreamFactory, ChecksumCalculator, SizeCalculator, MimeTypeProvider { protected $directory; private $create; @@ -29,7 +24,6 @@ class Local implements Adapter, /** * @param string $directory Directory where the filesystem is located * @param int $mode Mode of directory created by the adapter. - * */ public function __construct($directory, $mode = 0777) { @@ -265,7 +259,7 @@ public function computeKey($path) */ protected function computePath($key) { - return $this->normalizePath($this->directory.'/'.$key); + return $this->normalizePath($this->directory . '/' . $key); } /** diff --git a/src/Gaufrette/Adapter/OpenStack.php b/src/Gaufrette/Adapter/OpenStack.php index 2b6c321f9..e6d43d4e7 100644 --- a/src/Gaufrette/Adapter/OpenStack.php +++ b/src/Gaufrette/Adapter/OpenStack.php @@ -6,7 +6,6 @@ use Gaufrette\Exception\FileAlreadyExists; use Gaufrette\Exception\FileNotFound; use Gaufrette\Exception\StorageFailure; -use Gaufrette\Util; use OpenStack\Common\Error\BadResponseError; use OpenStack\ObjectStore\v1\Models\Container; use OpenStack\ObjectStore\v1\Models\StorageObject; @@ -22,12 +21,7 @@ * @see http://docs.os.php-opencloud.com/en/latest/services/object-store/v1/objects.html * @see http://refdocs.os.php-opencloud.com/OpenStack/OpenStack.html */ -final class OpenStack implements Adapter, - ChecksumCalculator, - ListKeysAware, - MetadataSupporter, - MimeTypeProvider, - SizeCalculator +final class OpenStack implements Adapter, ChecksumCalculator, ListKeysAware, MetadataSupporter, MimeTypeProvider, SizeCalculator { /** * @var Service @@ -88,7 +82,7 @@ private function getContainer() public function read($key) { try { - /** @var \Psr\Http\Message\StreamInterface $stream */ + /* @var \Psr\Http\Message\StreamInterface $stream */ // @WARNING: This could attempt to load a large amount of data into memory. return (string) $this->getObject($key)->download(); } catch (BadResponseError $e) { @@ -140,7 +134,7 @@ public function keys() return array_map(function (StorageObject $object) { return $object->name; }, iterator_to_array($this->getContainer()->listObjects())); - } catch (BadResponseError $e ) { + } catch (BadResponseError $e) { throw StorageFailure::unexpectedFailure('keys', [], $e); } } @@ -200,7 +194,7 @@ public function rename($sourceKey, $targetKey) throw new FileNotFound($sourceKey); } - if($this->exists($targetKey)) { + if ($this->exists($targetKey)) { throw new FileAlreadyExists($targetKey); } diff --git a/src/Gaufrette/Adapter/PhpseclibSftp.php b/src/Gaufrette/Adapter/PhpseclibSftp.php index fdd41e3ab..d2948edf6 100644 --- a/src/Gaufrette/Adapter/PhpseclibSftp.php +++ b/src/Gaufrette/Adapter/PhpseclibSftp.php @@ -9,9 +9,7 @@ use Gaufrette\FilesystemInterface; use phpseclib\Net\SFTP as SecLibSFTP; -class PhpseclibSftp implements Adapter, - FileFactory, - ListKeysAware +class PhpseclibSftp implements Adapter, FileFactory, ListKeysAware { protected $sftp; protected $directory; @@ -129,9 +127,9 @@ public function listKeys($prefix = '') return $keys; } - $filteredKeys = array(); - foreach (array('keys', 'dirs') as $hash) { - $filteredKeys[$hash] = array(); + $filteredKeys = []; + foreach (['keys', 'dirs'] as $hash) { + $filteredKeys[$hash] = []; foreach ($keys[$hash] as $key) { if (0 === strpos($key, $prefix)) { $filteredKeys[$hash][] = $key; @@ -216,12 +214,12 @@ protected function ensureDirectoryExists($directory, $create) protected function computePath($key) { - return $this->directory.'/'.ltrim($key, '/'); + return $this->directory . '/' . ltrim($key, '/'); } protected function fetchKeys($directory = '', $onlyKeys = true) { - $keys = array('keys' => array(), 'dirs' => array()); + $keys = ['keys' => [], 'dirs' => []]; $computedPath = $this->computePath($directory); if (!$this->sftp->file_exists($computedPath)) { @@ -234,7 +232,7 @@ protected function fetchKeys($directory = '', $onlyKeys = true) continue; } - $path = ltrim($directory.'/'.$filename, '/'); + $path = ltrim($directory . '/' . $filename, '/'); if (isset($stat['type']) && $stat['type'] === NET_SFTP_TYPE_DIRECTORY) { $keys['dirs'][] = $path; } else { @@ -246,7 +244,7 @@ protected function fetchKeys($directory = '', $onlyKeys = true) if ($onlyKeys && !empty($dirs)) { $keys['keys'] = array_merge($keys['keys'], $dirs); - $keys['dirs'] = array(); + $keys['dirs'] = []; } foreach ($dirs as $dir) { diff --git a/src/Gaufrette/Adapter/Zip.php b/src/Gaufrette/Adapter/Zip.php index d6db65a94..e75b62291 100644 --- a/src/Gaufrette/Adapter/Zip.php +++ b/src/Gaufrette/Adapter/Zip.php @@ -6,7 +6,6 @@ use Gaufrette\Exception\StorageFailure; use ZipArchive; use Gaufrette\Adapter; -use Gaufrette\Util; /** * ZIP Archive adapter. @@ -78,7 +77,7 @@ public function exists($key) */ public function keys() { - $keys = array(); + $keys = []; for ($i = 0; $i < $this->zipArchive->numFiles; ++$i) { $keys[$i] = $this->zipArchive->getNameIndex($i); @@ -154,7 +153,7 @@ public function getStat($key) { $stat = $this->zipArchive->statName($key); if (false === $stat) { - return array(); + return []; } return $stat; @@ -179,33 +178,43 @@ protected function reinitZipArchive() switch ($resultCode) { case ZipArchive::ER_EXISTS: $errMsg = 'File already exists.'; + break; case ZipArchive::ER_INCONS: $errMsg = 'Zip archive inconsistent.'; + break; case ZipArchive::ER_INVAL: $errMsg = 'Invalid argument.'; + break; case ZipArchive::ER_MEMORY: $errMsg = 'Malloc failure.'; + break; case ZipArchive::ER_NOENT: $errMsg = 'Invalid argument.'; + break; case ZipArchive::ER_NOZIP: $errMsg = 'Not a zip archive.'; + break; case ZipArchive::ER_OPEN: $errMsg = 'Can\'t open file.'; + break; case ZipArchive::ER_READ: $errMsg = 'Read error.'; + break; - case ZipArchive::ER_SEEK; + case ZipArchive::ER_SEEK: $errMsg = 'Seek error.'; + break; default: $errMsg = 'Unknown error.'; + break; } diff --git a/src/Gaufrette/File.php b/src/Gaufrette/File.php index 856b86457..164c2c40a 100644 --- a/src/Gaufrette/File.php +++ b/src/Gaufrette/File.php @@ -78,7 +78,7 @@ public function getKey() * * @return string */ - public function getContent($metadata = array()) + public function getContent($metadata = []) { if (isset($this->content)) { return $this->content; @@ -140,7 +140,7 @@ public function setSize($size) * @return int The number of bytes that were written into the file, or * FALSE on failure */ - public function setContent($content, $metadata = array()) + public function setContent($content, $metadata = []) { $this->content = $content; $this->setMetadata($metadata); @@ -176,7 +176,7 @@ public function exists() * * @return bool TRUE on success */ - public function delete($metadata = array()) + public function delete($metadata = []) { $this->setMetadata($metadata); diff --git a/src/Gaufrette/Filesystem.php b/src/Gaufrette/Filesystem.php index 89c5f3233..560c53cb6 100644 --- a/src/Gaufrette/Filesystem.php +++ b/src/Gaufrette/Filesystem.php @@ -20,7 +20,7 @@ class Filesystem implements FilesystemInterface * * @var array */ - protected $fileRegister = array(); + protected $fileRegister = []; /** * @param Adapter $adapter A configured Adapter instance @@ -159,8 +159,8 @@ public function listKeys($prefix = '') return $this->adapter->listKeys($prefix); } - $dirs = array(); - $keys = array(); + $dirs = []; + $keys = []; foreach ($this->keys() as $key) { if (empty($prefix) || 0 === strpos($key, $prefix)) { @@ -172,10 +172,10 @@ public function listKeys($prefix = '') } } - return array( + return [ 'keys' => $keys, 'dirs' => $dirs, - ); + ]; } /** @@ -303,7 +303,7 @@ private function isFileInRegister($key) */ public function clearFileRegister() { - $this->fileRegister = array(); + $this->fileRegister = []; } /** diff --git a/src/Gaufrette/FilesystemInterface.php b/src/Gaufrette/FilesystemInterface.php index d5ea23282..4b3efc919 100644 --- a/src/Gaufrette/FilesystemInterface.php +++ b/src/Gaufrette/FilesystemInterface.php @@ -35,7 +35,6 @@ public function has($key); */ public function rename($sourceKey, $targetKey); - /** * Returns the file matching the specified key. * diff --git a/src/Gaufrette/FilesystemMap.php b/src/Gaufrette/FilesystemMap.php index 425337e87..c353494e7 100644 --- a/src/Gaufrette/FilesystemMap.php +++ b/src/Gaufrette/FilesystemMap.php @@ -9,7 +9,7 @@ */ class FilesystemMap implements FilesystemMapInterface { - private $filesystems = array(); + private $filesystems = []; /** * Returns an array of all the registered filesystems where the key is the @@ -88,6 +88,6 @@ public function remove($name) */ public function clear() { - $this->filesystems = array(); + $this->filesystems = []; } } diff --git a/src/Gaufrette/Stream/InMemoryBuffer.php b/src/Gaufrette/Stream/InMemoryBuffer.php index b345caffa..332ae79fe 100644 --- a/src/Gaufrette/Stream/InMemoryBuffer.php +++ b/src/Gaufrette/Stream/InMemoryBuffer.php @@ -89,7 +89,7 @@ public function write($data) } else { $before = substr($this->content, 0, $this->position); $after = $newNumBytes > $newPosition ? substr($this->content, $newPosition) : ''; - $this->content = $before.$data.$after; + $this->content = $before . $data . $after; } $this->position = $newPosition; @@ -111,12 +111,15 @@ public function seek($offset, $whence = SEEK_SET) switch ($whence) { case SEEK_SET: $this->position = $offset; + break; case SEEK_CUR: $this->position += $offset; + break; case SEEK_END: $this->position = $this->numBytes + $offset; + break; default: return false; @@ -159,7 +162,7 @@ public function stat() $isDirectory = $this->filesystem->isDirectory($this->key); $time = $this->filesystem->mtime($this->key); - $stats = array( + $stats = [ 'dev' => 1, 'ino' => 0, 'mode' => $isDirectory ? 16893 : 33204, @@ -173,7 +176,7 @@ public function stat() 'ctime' => $time, 'blksize' => -1, 'blocks' => -1, - ); + ]; return array_merge(array_values($stats), $stats); } diff --git a/src/Gaufrette/Stream/Local.php b/src/Gaufrette/Stream/Local.php index 6b1c49283..306119c5e 100644 --- a/src/Gaufrette/Stream/Local.php +++ b/src/Gaufrette/Stream/Local.php @@ -36,6 +36,7 @@ public function open(StreamMode $mode) if ($mode->allowsWrite() && !is_dir($baseDirPath)) { @mkdir($baseDirPath, $this->mkdirMode, true); } + try { $fileHandle = @fopen($this->path, $mode->getMode()); } catch (\Exception $e) { diff --git a/src/Gaufrette/StreamWrapper.php b/src/Gaufrette/StreamWrapper.php index b96076683..cc8a92ca0 100644 --- a/src/Gaufrette/StreamWrapper.php +++ b/src/Gaufrette/StreamWrapper.php @@ -243,25 +243,25 @@ public function stream_cast($castAs) protected function createStream($path) { $parts = array_merge( - array( + [ 'scheme' => null, 'host' => null, 'path' => null, 'query' => null, 'fragment' => null, - ), - parse_url($path) ?: array() + ], + parse_url($path) ?: [] ); $domain = $parts['host']; $key = substr($parts['path'], 1); if (null !== $parts['query']) { - $key .= '?'.$parts['query']; + $key .= '?' . $parts['query']; } if (null !== $parts['fragment']) { - $key .= '#'.$parts['fragment']; + $key .= '#' . $parts['fragment']; } if (empty($domain) || empty($key)) { diff --git a/src/Gaufrette/Util/Path.php b/src/Gaufrette/Util/Path.php index eb7e2a0e3..4dec5c50a 100644 --- a/src/Gaufrette/Util/Path.php +++ b/src/Gaufrette/Util/Path.php @@ -22,7 +22,7 @@ public static function normalize($path) $prefix = static::getAbsolutePrefix($path); $path = substr($path, strlen($prefix)); $parts = array_filter(explode('/', $path), 'strlen'); - $tokens = array(); + $tokens = []; foreach ($parts as $part) { switch ($part) { @@ -31,6 +31,7 @@ public static function normalize($path) case '..': if (0 !== count($tokens)) { array_pop($tokens); + continue 2; } elseif (!empty($prefix)) { continue 2; @@ -40,7 +41,7 @@ public static function normalize($path) } } - return $prefix.implode('/', $tokens); + return $prefix . implode('/', $tokens); } /** diff --git a/tests/Gaufrette/Functional/Adapter/AwsS3Test.php b/tests/Gaufrette/Functional/Adapter/AwsS3Test.php index 41056c685..176ed268f 100644 --- a/tests/Gaufrette/Functional/Adapter/AwsS3Test.php +++ b/tests/Gaufrette/Functional/Adapter/AwsS3Test.php @@ -11,7 +11,7 @@ class AwsS3Test extends FunctionalTestCase use FileNotFoundTests; /** @var int */ - static private $SDK_VERSION; + private static $SDK_VERSION; /** @var string */ private $bucket; @@ -66,6 +66,7 @@ public function tearDown() if (!$result->hasKey('Contents')) { $this->client->deleteBucket(['Bucket' => $this->bucket]); + return; } diff --git a/tests/Gaufrette/Functional/Adapter/AzureBlobStorageTest.php b/tests/Gaufrette/Functional/Adapter/AzureBlobStorageTest.php index 9ec350f72..e53e669e1 100644 --- a/tests/Gaufrette/Functional/Adapter/AzureBlobStorageTest.php +++ b/tests/Gaufrette/Functional/Adapter/AzureBlobStorageTest.php @@ -30,8 +30,8 @@ public function setUp() $connection = sprintf('BlobEndpoint=http://%1$s.blob.core.windows.net/;AccountName=%1$s;AccountKey=%2$s', $account, $key); - $this->container = uniqid($containerName); - $this->adapter = new AzureBlobStorage(new BlobProxyFactory($connection), $this->container, true); + $this->container = uniqid($containerName); + $this->adapter = new AzureBlobStorage(new BlobProxyFactory($connection), $this->container, true); $this->filesystem = new Filesystem($this->adapter); } diff --git a/tests/Gaufrette/Functional/Adapter/DoctrineDbalTest.php b/tests/Gaufrette/Functional/Adapter/DoctrineDbalTest.php index abb3b9223..6f54a178e 100644 --- a/tests/Gaufrette/Functional/Adapter/DoctrineDbalTest.php +++ b/tests/Gaufrette/Functional/Adapter/DoctrineDbalTest.php @@ -21,10 +21,10 @@ public function setUp() $schema = $this->connection->getSchemaManager()->createSchema(); $table = $schema->createTable('gaufrette'); - $table->addColumn('key', 'string', array('unique' => true)); + $table->addColumn('key', 'string', ['unique' => true]); $table->addColumn('content', 'blob'); $table->addColumn('mtime', 'integer'); - $table->addColumn('checksum', 'string', array('length' => 32)); + $table->addColumn('checksum', 'string', ['length' => 32]); // Generates the SQL from the defined schema and execute each line array_map([$this->connection, 'exec'], $schema->toSql($this->connection->getDatabasePlatform())); @@ -42,8 +42,8 @@ public function tearDown() } /** - * @test - */ + * @test + */ public function shouldListKeys() { $this->filesystem->write('foo/foobar/bar.txt', 'data'); @@ -68,25 +68,25 @@ public function shouldListKeys() $keys = $this->filesystem->listKeys('foo/foob'); $this->assertEquals( - array('foo/foobar/bar.txt'), + ['foo/foobar/bar.txt'], $keys['keys'], '', 0, 10, true); $keys = $this->filesystem->listKeys('foo/'); $this->assertEquals( - array('foo/foobar/bar.txt', 'foo/bar/buzz.txt'), + ['foo/foobar/bar.txt', 'foo/bar/buzz.txt'], $keys['keys'], '', 0, 10, true); $keys = $this->filesystem->listKeys('foo'); $this->assertEquals( - array('foo/foobar/bar.txt', 'foo/bar/buzz.txt', 'foobarbuz.txt', 'foo'), + ['foo/foobar/bar.txt', 'foo/bar/buzz.txt', 'foobarbuz.txt', 'foo'], $keys['keys'], '', 0, 10, true); $keys = $this->filesystem->listKeys('fooz'); $this->assertEquals( - array(), + [], $keys['keys'], '', 0, 10, true); } diff --git a/tests/Gaufrette/Functional/Adapter/FtpTest.php b/tests/Gaufrette/Functional/Adapter/FtpTest.php index 6d51f4b62..87444835f 100644 --- a/tests/Gaufrette/Functional/Adapter/FtpTest.php +++ b/tests/Gaufrette/Functional/Adapter/FtpTest.php @@ -12,11 +12,11 @@ class FtpTest extends FunctionalTestCase public function setUp() { - $host = getenv('FTP_HOST'); - $port = getenv('FTP_PORT'); - $user = getenv('FTP_USER'); + $host = getenv('FTP_HOST'); + $port = getenv('FTP_PORT'); + $user = getenv('FTP_USER'); $password = getenv('FTP_PASSWORD'); - $baseDir = getenv('FTP_BASE_DIR'); + $baseDir = getenv('FTP_BASE_DIR'); if ($user === false || $password === false || $host === false || $baseDir === false) { $this->markTestSkipped('Either FTP_HOST, FTP_USER, FTP_PASSWORD and/or FTP_BASE_DIR env variables are not defined.'); @@ -25,11 +25,11 @@ public function setUp() $baseDir = rtrim($baseDir, '/') . DIRECTORY_SEPARATOR . uniqid(); $adapter = new Ftp($baseDir, $host, [ - 'port' => $port, + 'port' => $port, 'username' => $user, 'password' => $password, - 'passive' => true, - 'create' => true + 'passive' => true, + 'create' => true, ]); $this->filesystem = new Filesystem($adapter); } diff --git a/tests/Gaufrette/Functional/Adapter/FunctionalTestCase.php b/tests/Gaufrette/Functional/Adapter/FunctionalTestCase.php index 021de5f88..ae65dae9b 100644 --- a/tests/Gaufrette/Functional/Adapter/FunctionalTestCase.php +++ b/tests/Gaufrette/Functional/Adapter/FunctionalTestCase.php @@ -16,7 +16,7 @@ public function getAdapterName() { if (!preg_match('/\\\\(\w+)Test$/', get_class($this), $matches)) { throw new \RuntimeException(sprintf( - 'Unable to guess filesystem name from class "%s", '. + 'Unable to guess filesystem name from class "%s", ' . 'please override the ->getAdapterName() method.', get_class($this) )); @@ -127,7 +127,7 @@ public function shouldDeleteFile() */ public function shouldFetchKeys() { - $this->assertEquals(array(), $this->filesystem->keys()); + $this->assertEquals([], $this->filesystem->keys()); $this->filesystem->write('foo', 'Some content'); $this->filesystem->write('bar', 'Some content'); @@ -136,7 +136,7 @@ public function shouldFetchKeys() $actualKeys = $this->filesystem->keys(); $this->assertCount(3, $actualKeys); - foreach (array('foo', 'bar', 'baz') as $key) { + foreach (['foo', 'bar', 'baz'] as $key) { $this->assertContains($key, $actualKeys); } } diff --git a/tests/Gaufrette/Functional/Adapter/GoogleCloudStorageTest.php b/tests/Gaufrette/Functional/Adapter/GoogleCloudStorageTest.php index 07e7f07cb..555912b48 100644 --- a/tests/Gaufrette/Functional/Adapter/GoogleCloudStorageTest.php +++ b/tests/Gaufrette/Functional/Adapter/GoogleCloudStorageTest.php @@ -3,7 +3,6 @@ namespace Gaufrette\Functional\Adapter; use Gaufrette\Adapter\GoogleCloudStorage; -use Gaufrette\Exception\FileNotFound; use Gaufrette\Filesystem; use Google\Cloud\Storage\Acl; use Google\Cloud\Storage\StorageClient; @@ -16,7 +15,7 @@ */ class GoogleCloudStorageTest extends FunctionalTestCase { - private $string = 'Yeah mate. No worries, I uploaded just fine. Meow!'; + private $string = 'Yeah mate. No worries, I uploaded just fine. Meow!'; private $directory = 'tests'; private $bucketName; private $sdkOptions; @@ -24,8 +23,8 @@ class GoogleCloudStorageTest extends FunctionalTestCase public function setUp() { - $gcsProjectId = getenv('GCS_PROJECT_ID'); - $gcsBucketName = getenv('GCS_BUCKET_NAME'); + $gcsProjectId = getenv('GCS_PROJECT_ID'); + $gcsBucketName = getenv('GCS_BUCKET_NAME'); $gcsJsonKeyFile = getenv('GCS_JSON_KEY_FILE'); if (empty($gcsProjectId) || empty($gcsBucketName) || empty($gcsJsonKeyFile)) { @@ -34,9 +33,9 @@ public function setUp() $this->directory = uniqid($this->directory); $this->bucketName = $gcsBucketName; - $this->sdkOptions = array( + $this->sdkOptions = [ 'projectId' => $gcsProjectId, - ); + ]; if ($this->isJsonString($gcsJsonKeyFile)) { $this->sdkOptions['keyFile'] = json_decode($gcsJsonKeyFile, true); @@ -48,12 +47,12 @@ public function setUp() $this->sdkOptions['keyFilePath'] = $gcsJsonKeyFile; } - $this->bucketOptions = array( + $this->bucketOptions = [ 'directory' => $this->directory, - 'acl' => array( + 'acl' => [ 'allUsers' => Acl::ROLE_READER, - ), - ); + ], + ]; $storage = new StorageClient($this->sdkOptions); @@ -71,9 +70,9 @@ public function tearDown() $adapter = new GoogleCloudStorage($storage, $this->bucketName, array_merge( $this->bucketOptions, - array( + [ 'directory' => '', - ) + ] )); $this->filesystem = new Filesystem($adapter); @@ -106,10 +105,10 @@ public function shouldWriteAndReadFileMetadata() { /** @var \Gaufrette\Adapter\GoogleCloudStorage $adapter */ $adapter = $this->filesystem->getAdapter(); - $file = 'PhatCat/Cat.txt'; + $file = 'PhatCat/Cat.txt'; $this->filesystem->write($file, $this->string, true); - $adapter->setMetadata($file, array('OhMy' => 'I am a cat file!')); + $adapter->setMetadata($file, ['OhMy' => 'I am a cat file!']); $info = $adapter->getMetadata($file); $this->assertEquals($info['OhMy'], 'I am a cat file!'); @@ -124,13 +123,13 @@ public function shouldTransfertMetadataWhenRenamingAFile() { /** @var \Gaufrette\Adapter\GoogleCloudStorage $adapter */ $adapter = $this->filesystem->getAdapter(); - $file = 'Cat.txt'; + $file = 'Cat.txt'; $this->filesystem->write($file, $this->string, true); - $adapter->setMetadata($file, array('OhMy' => 'I am a cat file!')); + $adapter->setMetadata($file, ['OhMy' => 'I am a cat file!']); $adapter->rename('Cat.txt', 'Kitten.txt'); - $this->assertEquals($adapter->getMetadata('Kitten.txt'), array('OhMy' => 'I am a cat file!')); + $this->assertEquals($adapter->getMetadata('Kitten.txt'), ['OhMy' => 'I am a cat file!']); } /** @@ -142,7 +141,7 @@ public function shouldWriteAndReadPublicFile() { /** @var \Gaufrette\Adapter\GoogleCloudStorage $adapter */ $adapter = $this->filesystem->getAdapter(); - $file = 'Cat.txt'; + $file = 'Cat.txt'; $this->filesystem->write($file, $this->string, true); $publicLink = sprintf('https://storage.googleapis.com/%s/%s/Cat.txt', $adapter->getBucket()->name(), $this->directory); @@ -170,7 +169,8 @@ public function shouldListKeys() $this->assertEquals(['prefix/file.txt'], $this->filesystem->listKeys('prefix')); } - private function isJsonString($content) { + private function isJsonString($content) + { json_decode($content); return json_last_error() === JSON_ERROR_NONE; diff --git a/tests/Gaufrette/Functional/Adapter/GridFSTest.php b/tests/Gaufrette/Functional/Adapter/GridFSTest.php index 947179927..35c2b9cfd 100644 --- a/tests/Gaufrette/Functional/Adapter/GridFSTest.php +++ b/tests/Gaufrette/Functional/Adapter/GridFSTest.php @@ -58,25 +58,25 @@ public function shouldListKeys() $keys = $this->filesystem->listKeys('foo/foob'); $this->assertEquals( - array('foo/foobar/bar.txt'), + ['foo/foobar/bar.txt'], $keys['keys'], '', 0, 10, true); $keys = $this->filesystem->listKeys('foo/'); $this->assertEquals( - array('foo/foobar/bar.txt', 'foo/bar/buzz.txt'), + ['foo/foobar/bar.txt', 'foo/bar/buzz.txt'], $keys['keys'], '', 0, 10, true); $keys = $this->filesystem->listKeys('foo'); $this->assertEquals( - array('foo/foobar/bar.txt', 'foo/bar/buzz.txt', 'foobarbuz.txt', 'foo'), + ['foo/foobar/bar.txt', 'foo/bar/buzz.txt', 'foobarbuz.txt', 'foo'], $keys['keys'], '', 0, 10, true); $keys = $this->filesystem->listKeys('fooz'); $this->assertEquals( - array(), + [], $keys['keys'], '', 0, 10, true); } @@ -90,7 +90,7 @@ public function testMetadataRetrieveAfterWrite() //Create local copy of fileadapter $fileadpt = clone $this->filesystem->getAdapter(); - $this->filesystem->getAdapter()->setMetadata('metadatatest', array('testing' => true)); + $this->filesystem->getAdapter()->setMetadata('metadatatest', ['testing' => true]); $this->filesystem->write('metadatatest', 'test'); $this->assertEquals($this->filesystem->getAdapter()->getMetadata('metadatatest'), $fileadpt->getMetadata('metadatatest')); @@ -115,6 +115,6 @@ public function testRetrieveWithoutMetadata() { $this->filesystem->write('no-metadata.txt', 'content'); - $this->assertEquals(array(), $this->filesystem->getAdapter()->getMetadata('no-metadata.txt')); + $this->assertEquals([], $this->filesystem->getAdapter()->getMetadata('no-metadata.txt')); } } diff --git a/tests/Gaufrette/Functional/Adapter/PhpseclibSftpTest.php b/tests/Gaufrette/Functional/Adapter/PhpseclibSftpTest.php index 3a996da6d..0a12b67e1 100644 --- a/tests/Gaufrette/Functional/Adapter/PhpseclibSftpTest.php +++ b/tests/Gaufrette/Functional/Adapter/PhpseclibSftpTest.php @@ -16,11 +16,11 @@ class PhpseclibSftpTest extends FunctionalTestCase public function setUp() { - $host = getenv('SFTP_HOST'); - $port = getenv('SFTP_PORT') ?: 22; - $user = getenv('SFTP_USER'); + $host = getenv('SFTP_HOST'); + $port = getenv('SFTP_PORT') ?: 22; + $user = getenv('SFTP_USER'); $password = getenv('SFTP_PASSWORD'); - $baseDir = getenv('SFTP_BASE_DIR'); + $baseDir = getenv('SFTP_BASE_DIR'); if ($host === false || $user === false || $password === false || $baseDir === false) { $this->markTestSkipped('Either SFTP_HOST, SFTP_USER, SFTP_PASSWORD and/or SFTP_BASE_DIR env variables are not defined.'); diff --git a/tests/Gaufrette/Functional/FileStream/FunctionalTestCase.php b/tests/Gaufrette/Functional/FileStream/FunctionalTestCase.php index d16fd042b..7805a22c4 100644 --- a/tests/Gaufrette/Functional/FileStream/FunctionalTestCase.php +++ b/tests/Gaufrette/Functional/FileStream/FunctionalTestCase.php @@ -207,14 +207,14 @@ public function shouldCreateNewFile($mode) public static function modesProvider() { - return array( - array('w'), - array('a+'), - array('w+'), - array('ab+'), - array('wb'), - array('wb+') - ); + return [ + ['w'], + ['a+'], + ['w+'], + ['ab+'], + ['wb'], + ['wb+'], + ]; } protected function registerLocalFilesystemInStream() diff --git a/tests/Gaufrette/Functional/FileStream/InMemoryBufferTest.php b/tests/Gaufrette/Functional/FileStream/InMemoryBufferTest.php index 5f00fc36e..343f1acab 100644 --- a/tests/Gaufrette/Functional/FileStream/InMemoryBufferTest.php +++ b/tests/Gaufrette/Functional/FileStream/InMemoryBufferTest.php @@ -9,7 +9,7 @@ class InMemoryBufferTest extends FunctionalTestCase { public function setUp() { - $this->filesystem = new Filesystem(new InMemoryAdapter(array())); + $this->filesystem = new Filesystem(new InMemoryAdapter([])); $this->registerLocalFilesystemInStream(); } diff --git a/tests/Gaufrette/Functional/FileStream/LocalTest.php b/tests/Gaufrette/Functional/FileStream/LocalTest.php index 477d391b4..160e0e122 100644 --- a/tests/Gaufrette/Functional/FileStream/LocalTest.php +++ b/tests/Gaufrette/Functional/FileStream/LocalTest.php @@ -13,7 +13,7 @@ public function setUp() { $this->directory = sys_get_temp_dir() . DIRECTORY_SEPARATOR . uniqid('gaufrette-tests'); - @mkdir($this->directory.DIRECTORY_SEPARATOR.'subdir', 0777, true); + @mkdir($this->directory . DIRECTORY_SEPARATOR . 'subdir', 0777, true); umask(0002); $this->filesystem = new Filesystem(new LocalAdapter($this->directory, 0770));