From 05fe5378baa0ffdc0c0f88c68188b0fb4ea56799 Mon Sep 17 00:00:00 2001 From: Ivan Lutokhin Date: Tue, 18 Aug 2020 17:36:06 +0300 Subject: [PATCH] Added php code style fixer --- .gitignore | 2 ++ .php_cs | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++ .travis.yml | 18 +++++++++++++++++ composer.json | 5 +++-- 4 files changed, 79 insertions(+), 2 deletions(-) create mode 100644 .php_cs create mode 100644 .travis.yml diff --git a/.gitignore b/.gitignore index 3afc852..e1eb31c 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,8 @@ composer.phar vendor +.php_cs.cache + # IntelliJ project files *.iml *.iws diff --git a/.php_cs b/.php_cs new file mode 100644 index 0000000..d8ddd61 --- /dev/null +++ b/.php_cs @@ -0,0 +1,56 @@ +files() + ->name('*.php') + ->in(__DIR__) + ->exclude([ + 'vendor', + ]) + ->ignoreDotFiles(true) + ->ignoreVCS(true) +; + +return PhpCsFixer\Config::create() + ->setRiskyAllowed(true) + ->setRules([ + '@Symfony' => true, + '@Symfony:risky' => true, + + // exceptions + 'single_line_throw' => false, + + // php file + 'concat_space' => ['spacing' => 'one'], + + // namespace and imports + 'ordered_imports' => true, + 'global_namespace_import' => [ + 'import_classes' => false, + 'import_constants' => false, + 'import_functions' => false, + ], + + // standard functions and operators + 'native_constant_invocation' => false, + 'native_function_invocation' => false, + 'modernize_types_casting' => true, + 'is_null' => true, + + // arrays + 'array_syntax' => [ + 'syntax' => 'short', + ], + + // phpdoc + 'phpdoc_annotation_without_dot' => false, + 'phpdoc_summary' => false, + + // logical operators + 'logical_operators' => true, + ]) + ->setFinder($finder) + ->setCacheFile(__DIR__ . '.php_cs.cache') +; diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..2cff9d1 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,18 @@ +language: php + +cache: + directories: + - $HOME/.composer/cache + +php: + - '7.3' + +before_script: + - flags="-o" + - composer install $flags + +script: + - php vendor/bin/php-cs-fixer fix --diff --dry-run --using-cache no --config .php_cs + +after_success: + - bash <(curl -s https://codecov.io/bash) \ No newline at end of file diff --git a/composer.json b/composer.json index 80d4d99..77b9f3a 100644 --- a/composer.json +++ b/composer.json @@ -28,6 +28,7 @@ "symfony/validator": "^5.1" }, "require-dev": { - "doctrine/doctrine-fixtures-bundle": "^3.3" + "doctrine/doctrine-fixtures-bundle": "^3.3", + "friendsofphp/php-cs-fixer": "^2.0" } -} \ No newline at end of file +}