Skip to content
This repository has been archived by the owner on May 26, 2022. It is now read-only.

Commit

Permalink
Setup PHP CS fixer
Browse files Browse the repository at this point in the history
- Add PHP CS Fixer as a dev dependencies.
- Add PHP CS Fixer cache file to gitignore/gitattributes
- Add custom code style config
- Update TravisCI config to check code style
  • Loading branch information
adrilo committed Sep 5, 2017
1 parent 668c10a commit 554ebf9
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 16 deletions.
4 changes: 2 additions & 2 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Ignore all test and documentation for archive
# Ignore all test, documentation and dot files for archive
/tests export-ignore
/.editorconfig export-ignore
/.gitattributes export-ignore
/.gitignore export-ignore
/.php_cs.dist export-ignore
/.scrutinizer.yml export-ignore
/.travis.yml export-ignore
/composer.lock export-ignore
/CONTRIBUTING.md export-ignore
/logo.png export-ignore
/phpunit.xml export-ignore
8 changes: 5 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/.idea
*.iml

/tests/resources/generated
/tests/coverage
/vendor
/.idea
*.iml
composer.lock
/composer.lock
/.php_cs.cache
58 changes: 58 additions & 0 deletions .php_cs.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

$config = PhpCsFixer\Config::create()
->setRiskyAllowed(true)
->setRules([
'@Symfony' => true,
'align_multiline_comment' => false,
'array_syntax' => ['syntax' => 'short'],
'binary_operator_spaces' => ['align_double_arrow' => true, 'align_equals' => null],
'blank_line_before_statement' => ['statements' => ['return']],
'combine_consecutive_unsets' => true,
'concat_space' => ['spacing' => 'one'],
'declare_equal_normalize' => ['space' => 'single'],
'heredoc_to_nowdoc' => true,
'is_null' => ['use_yoda_style' => false],
'method_argument_space' => ['ensure_fully_multiline' => true],
'modernize_types_casting' => true,
'no_break_comment' => ['comment_text' => 'do nothing'],
'no_empty_phpdoc' => false,
'no_null_property_initialization' => true,
'no_short_echo_tag' => true,
'no_superfluous_elseif' => true,
'no_unneeded_control_parentheses' => ['statements' => ['break', 'clone', 'continue', 'echo_print', 'switch_case', 'yield']],
'no_unneeded_curly_braces' => true,
'no_unneeded_final_method' => true,
'no_useless_else' => false,
'no_useless_return' => true,
'ordered_imports' => true,
'phpdoc_add_missing_param_annotation' => true,
'phpdoc_align' => false,
'phpdoc_annotation_without_dot' => false,
'phpdoc_no_empty_return' => false,
'phpdoc_order' => true,
'phpdoc_summary' => false,
'phpdoc_types_order' => ['null_adjustment' => 'always_last', 'sort_algorithm' => 'none'],
'phpdoc_separation' => false,
'pre_increment' => false,
'protected_to_private' => true,
'psr4' => true,
'return_type_declaration' => ['space_before' => 'one'],
'semicolon_after_instruction' => true,
'simplified_null_return' => false,
'single_line_comment_style' => ['comment_types' => ['hash']],
'strict_comparison' => true,
'void_return' => true,
]);

$config->setFinder(
PhpCsFixer\Finder::create()
->exclude('vendor')
->in(__DIR__)
->name('*.php')
);

$cacheDir = getenv('TRAVIS') ? getenv('HOME') . '/.php-cs-fixer' : __DIR__;
$config->setCacheFile($cacheDir . '/.php_cs.cache');

return $config;
53 changes: 43 additions & 10 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,27 +1,60 @@
language: php

dist: trusty
sudo: false

language: php

php:
- 5.6
- 7.0
- 7.1
- hhvm-3.6
matrix:
include:
- php: 5.6
env: WITH_PHPUNIT=true
- php: 5.6
env: WITH_CS=true
- php: 7.0
env: WITH_PHPUNIT=true
- php: 7.1
env: WITH_PHPUNIT=true WITH_COVERAGE=true
- php: hhvm-3.6
env: WITH_PHPUNIT=true

cache:
directories:
- $HOME/.composer/cache
- $HOME/.php-cs-fixer

before_install:
- |
if [[ "$WITH_COVERAGE" != "true" ]]; then
phpenv config-rm xdebug.ini
fi
if [[ "$WITH_CS" != "true" ]]; then
composer remove friendsofphp/php-cs-fixer --dev --no-update
fi
- composer validate

install:
- composer install --no-interaction --prefer-source

script:
before_script:
- mkdir -p "$HOME/.php-cs-fixer"
- mkdir -p build/logs
- php vendor/bin/phpunit --coverage-clover=build/logs/coverage.clover

script:
- |
if [[ "$WITH_CS" == "true" ]]; then
vendor/bin/php-cs-fixer fix --config=.php_cs.dist --verbose --diff --dry-run
fi
- |
if [[ "$WITH_PHPUNIT" == "true" ]]; then
if [[ "$WITH_COVERAGE" == "true" ]]; then
vendor/bin/phpunit --coverage-clover=build/logs/coverage.clover
else
vendor/bin/phpunit --no-coverage
fi
fi
after_script:
- |
if [[ "$TRAVIS_PHP_VERSION" = '7.1' ]]; then
if [[ "$WITH_COVERAGE" == "true" ]]; then
wget https://scrutinizer-ci.com/ocular.phar
php ocular.phar code-coverage:upload --format=php-clover build/logs/coverage.clover
fi
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
"ext-xmlreader" : "*"
},
"require-dev": {
"phpunit/phpunit": "^5.7.0"
"phpunit/phpunit": "^5.7.0",
"friendsofphp/php-cs-fixer": "^2.5.0"
},
"suggest": {
"ext-iconv": "To handle non UTF-8 CSV files (if \"php-intl\" is not already installed or is too limited)",
Expand Down

0 comments on commit 554ebf9

Please sign in to comment.