Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RFR] Add PHP Coding Standard check step on CI. #617

Merged
merged 2 commits into from
Jun 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@ trim_trailing_whitespace = false

[*.yml]
indent_size = 2

[Makefile]
indent_style = tab
7 changes: 4 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
bin/*
!bin/tests
!bin/tests-all
composer.lock
doc/.couscous
.env
.php_cs.cache
phpunit.xml
tests/adapters/*
!tests/adapters/*.dist
vendor/
.env
composer.lock
phpunit.xml
41 changes: 41 additions & 0 deletions .php_cs.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

return PhpCsFixer\Config::create()
->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())
;
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
- php vendor/bin/phpunit --verbose
12 changes: 12 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,17 @@ $ make clear-deps
$ PHP_VERSION=<the_version_you_want_to_use> 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.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
"league/flysystem": "~1.0",
"mongodb/mongodb": "^1.1",
"microsoft/azure-storage-blob": "^1.0",
"akeneo/phpspec-skip-example-extension": "^4.0"
"akeneo/phpspec-skip-example-extension": "^4.0",
"pedrotroller/php-cs-custom-fixer": "^2.17"
},
"suggest": {
"knplabs/knp-gaufrette-bundle": "to use with Symfony2",
Expand Down
32 changes: 16 additions & 16 deletions spec/Gaufrette/Adapter/AclAwareAmazonS3Spec.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ function it_delegates_rename_and_update_acl(Adapter $adapter, AmazonS3 $service)
$service
->set_object_acl('bucketName', 'filename2', \AmazonS3::ACL_PRIVATE)
->shouldBeCalled()
->willReturn(new \CFResponse(array(), '', 200))
->willReturn(new \CFResponse([], '', 200))
;
$adapter
->rename('filename', 'filename2')
Expand All @@ -72,7 +72,7 @@ function it_does_not_rename_when_cannot_update_acl(Adapter $adapter, AmazonS3 $s
$service
->set_object_acl('bucketName', 'filename2', \AmazonS3::ACL_PRIVATE)
->shouldBeCalled()
->willReturn(new \CFResponse(array(), '', 500));
->willReturn(new \CFResponse([], '', 500));
$adapter
->rename('filename', 'filename2')
->shouldBeCalled()
Expand All @@ -91,16 +91,16 @@ function it_does_not_rename_when_cannot_update_acl(Adapter $adapter, AmazonS3 $s
function it_updates_acl_with_users_array_when_rename(Adapter $adapter, AmazonS3 $service)
{
$service
->set_object_acl('bucketName', 'filename2', array(array('id' => 'someId', 'permission' => \AmazonS3::GRANT_READ)))
->set_object_acl('bucketName', 'filename2', [['id' => 'someId', 'permission' => \AmazonS3::GRANT_READ]])
->shouldBeCalled()
->willReturn(new \CFResponse(array(), '', 200))
->willReturn(new \CFResponse([], '', 200))
;
$adapter
->rename('filename', 'filename2')
->willReturn(true)
;

$this->setUsers(array(array('id' => 'someId', 'permission' => 'read')));
$this->setUsers([['id' => 'someId', 'permission' => 'read']]);
$this->rename('filename', 'filename2')->shouldReturn(true);
}

Expand All @@ -113,7 +113,7 @@ function it_delegates_write_and_update_acl(Adapter $adapter, AmazonS3 $service)
$service
->set_object_acl('bucketName', 'filename', \AmazonS3::ACL_PRIVATE)
->shouldBeCalled()
->willReturn(new \CFResponse(array(), '', 200))
->willReturn(new \CFResponse([], '', 200))
;
$adapter
->write('filename', 'some content')
Expand All @@ -137,7 +137,7 @@ function it_does_not_write_when_cannot_update_acl(Adapter $adapter, AmazonS3 $se
$service
->set_object_acl('bucketName', 'filename', \AmazonS3::ACL_PRIVATE)
->shouldBeCalled()
->willReturn(new \CFResponse(array(), '', 500))
->willReturn(new \CFResponse([], '', 500))
;
$adapter
->write('filename', 'some content')
Expand All @@ -159,16 +159,16 @@ function it_does_not_write_when_cannot_update_acl(Adapter $adapter, AmazonS3 $se
function it_updates_acl_with_users_array_when_write(Adapter $adapter, AmazonS3 $service)
{
$service
->set_object_acl('bucketName', 'filename', array(array('id' => 'someId', 'permission' => \AmazonS3::GRANT_READ)))
->set_object_acl('bucketName', 'filename', [['id' => 'someId', 'permission' => \AmazonS3::GRANT_READ]])
->shouldBeCalled()
->willReturn(new \CFResponse(array(), '', 200))
->willReturn(new \CFResponse([], '', 200))
;
$adapter
->write('filename', 'some content')
->willReturn(12)
;

$this->setUsers(array(array('id' => 'someId', 'permission' => 'read')));
$this->setUsers([['id' => 'someId', 'permission' => 'read']]);
$this->write('filename', 'some content')->shouldReturn(12);
}

Expand Down Expand Up @@ -213,9 +213,9 @@ function it_delegates_directory_check(Adapter $adapter)
*/
function it_delegates_keys(Adapter $adapter)
{
$adapter->keys()->willReturn(array('filename', 'filename2'));
$adapter->keys()->willReturn(['filename', 'filename2']);

$this->keys()->shouldReturn(array('filename', 'filename2'));
$this->keys()->shouldReturn(['filename', 'filename2']);
}

/**
Expand All @@ -226,11 +226,11 @@ function it_delegates_metadata_handling(TestDelegateAdapter $extendedAdapter, Am
{
$this->beConstructedWith($extendedAdapter, $service, 'bucketName');

$extendedAdapter->setMetadata('filename', array('some'))->shouldBeCalled();
$extendedAdapter->getMetadata('filename')->shouldBeCalled()->willReturn(array('some2'));
$extendedAdapter->setMetadata('filename', ['some'])->shouldBeCalled();
$extendedAdapter->getMetadata('filename')->shouldBeCalled()->willReturn(['some2']);

$this->setMetadata('filename', array('some'));
$this->getMetadata('filename')->shouldReturn(array('some2'));
$this->setMetadata('filename', ['some']);
$this->getMetadata('filename')->shouldReturn(['some2']);
}
}

Expand Down
Loading