Setup PHP CS fixer
- 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
This commit is contained in:
parent
668c10a30d
commit
554ebf987b
4
.gitattributes
vendored
4
.gitattributes
vendored
@ -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
.gitignore
vendored
8
.gitignore
vendored
@ -1,6 +1,8 @@
|
||||
/.idea
|
||||
*.iml
|
||||
|
||||
/tests/resources/generated
|
||||
/tests/coverage
|
||||
/vendor
|
||||
/.idea
|
||||
*.iml
|
||||
composer.lock
|
||||
/composer.lock
|
||||
/.php_cs.cache
|
||||
|
58
.php_cs.dist
Normal file
58
.php_cs.dist
Normal file
@ -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
.travis.yml
53
.travis.yml
@ -1,27 +1,60 @@
|
||||
dist: trusty
|
||||
sudo: false
|
||||
|
||||
language: php
|
||||
|
||||
dist: trusty
|
||||
|
||||
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
|
||||
|
@ -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)",
|
||||
|
Loading…
x
Reference in New Issue
Block a user