From 3ede84769768586afed87f9fc114a8ca526d9ce2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20H=C3=BCbner?= Date: Tue, 17 Jan 2017 11:48:21 +0100 Subject: [PATCH] Setup php-cs-fixer pre-commit hook --- .php_cs | 18 ++++ .php_cs.cache | 1 + bin/php-cs-fixer-hook.sh | 30 +++++++ composer.json | 3 +- composer.lock | 177 ++++++++++++++++++++++++++++++++++++++- 5 files changed, 227 insertions(+), 2 deletions(-) create mode 100644 .php_cs create mode 100644 .php_cs.cache create mode 100644 bin/php-cs-fixer-hook.sh diff --git a/.php_cs b/.php_cs new file mode 100644 index 0000000..744b531 --- /dev/null +++ b/.php_cs @@ -0,0 +1,18 @@ +in(__DIR__.'/src'); + +return PhpCsFixer\Config::create() + ->setRules([ + '@Symfony' => true, + 'combine_consecutive_unsets' => true, + 'linebreak_after_opening_tag' => true, + 'no_multiline_whitespace_before_semicolons' => true, + 'no_useless_else' => true, + 'no_useless_return' => true, + 'ordered_imports' => true, + 'phpdoc_order' => true, + 'array_syntax' => array('syntax' => 'short'), + ]) + ->setFinder($finder); diff --git a/.php_cs.cache b/.php_cs.cache new file mode 100644 index 0000000..282f5cf --- /dev/null +++ b/.php_cs.cache @@ -0,0 +1 @@ +{"php":"7.0.14","version":"2.0.0:v2.0.0#f3baf72eb2f58bf275b372540f5b47d25aed910f","rules":{"encoding":true,"full_opening_tag":true,"blank_line_after_namespace":true,"braces":true,"class_definition":{"singleLine":true},"elseif":true,"function_declaration":true,"indentation_type":true,"line_ending":true,"lowercase_constants":true,"lowercase_keywords":true,"method_argument_space":true,"no_closing_tag":true,"no_spaces_after_function_name":true,"no_spaces_inside_parenthesis":true,"no_trailing_whitespace":true,"no_trailing_whitespace_in_comment":true,"single_blank_line_at_eof":true,"single_class_element_per_statement":true,"single_import_per_statement":true,"single_line_after_imports":true,"switch_case_semicolon_to_colon":true,"switch_case_space":true,"visibility_required":true,"binary_operator_spaces":{"align_double_arrow":false,"align_equals":false},"blank_line_after_opening_tag":true,"blank_line_before_return":true,"cast_spaces":true,"concat_space":{"spacing":"none"},"declare_equal_normalize":true,"function_typehint_space":true,"hash_to_slash_comment":true,"heredoc_to_nowdoc":true,"include":true,"lowercase_cast":true,"method_separation":true,"native_function_casing":true,"new_with_braces":true,"no_alias_functions":true,"no_blank_lines_after_class_opening":true,"no_blank_lines_after_phpdoc":true,"no_empty_comment":true,"no_empty_phpdoc":true,"no_empty_statement":true,"no_extra_consecutive_blank_lines":["curly_brace_block","extra","parenthesis_brace_block","square_brace_block","throw","use"],"no_leading_import_slash":true,"no_leading_namespace_whitespace":true,"no_mixed_echo_print":{"use":"echo"},"no_multiline_whitespace_around_double_arrow":true,"no_short_bool_cast":true,"no_singleline_whitespace_before_semicolons":true,"no_spaces_around_offset":true,"no_trailing_comma_in_list_call":true,"no_trailing_comma_in_singleline_array":true,"no_unneeded_control_parentheses":true,"no_unreachable_default_argument_value":true,"no_unused_imports":true,"no_whitespace_before_comma_in_array":true,"no_whitespace_in_blank_line":true,"normalize_index_brace":true,"object_operator_without_whitespace":true,"php_unit_fqcn_annotation":true,"phpdoc_align":true,"phpdoc_annotation_without_dot":true,"phpdoc_indent":true,"phpdoc_inline_tag":true,"phpdoc_no_access":true,"phpdoc_no_alias_tag":true,"phpdoc_no_empty_return":true,"phpdoc_no_package":true,"phpdoc_scalar":true,"phpdoc_separation":true,"phpdoc_single_line_var_spacing":true,"phpdoc_summary":true,"phpdoc_to_comment":true,"phpdoc_trim":true,"phpdoc_types":true,"phpdoc_var_without_name":true,"pre_increment":true,"return_type_declaration":true,"self_accessor":true,"short_scalar_cast":true,"single_blank_line_before_namespace":true,"single_quote":true,"space_after_semicolon":true,"standardize_not_equals":true,"ternary_operator_spaces":true,"trailing_comma_in_multiline_array":true,"trim_array_spaces":true,"unary_operator_spaces":true,"whitespace_after_comma_in_array":true,"combine_consecutive_unsets":true,"linebreak_after_opening_tag":true,"no_multiline_whitespace_before_semicolons":true,"no_useless_else":true,"no_useless_return":true,"ordered_imports":true,"phpdoc_order":true,"array_syntax":{"syntax":"short"}},"hashes":{"AppBundle\/Api\/Client\/Brickset\/Brickset.php":162138165,"AppBundle\/Api\/Client\/Brickset\/Entity\/AdditionalImage.php":441202037,"AppBundle\/Api\/Client\/Brickset\/Entity\/Instructions.php":1002903639,"AppBundle\/Api\/Client\/Brickset\/Entity\/Review.php":4229710683,"AppBundle\/Api\/Client\/Brickset\/Entity\/Set.php":2706093804,"AppBundle\/Api\/Client\/Brickset\/Entity\/Subtheme.php":3870722411,"AppBundle\/Api\/Client\/Brickset\/Entity\/Theme.php":1884642349,"AppBundle\/Api\/Client\/Brickset\/Entity\/Year.php":1244862886,"AppBundle\/Api\/Client\/Rebrickable\/Converter\/PartPropertyNameConverter.php":2348273915,"AppBundle\/Api\/Client\/Rebrickable\/Entity\/Color.php":2488744063,"AppBundle\/Api\/Client\/Rebrickable\/Entity\/Part.php":88525676,"AppBundle\/Api\/Client\/Rebrickable\/Entity\/Set.php":2172782418,"AppBundle\/Api\/Client\/Rebrickable\/Rebrickable.php":4037859360,"AppBundle\/Api\/Manager\/BricksetManager.php":2903250791,"AppBundle\/Api\/Manager\/RebrickableManager.php":2672369346,"AppBundle\/AppBundle.php":3337940655,"AppBundle\/Command\/LoadLDrawCommand.php":2397743263,"AppBundle\/Command\/LoadRebrickableCommand.php":3396442285,"AppBundle\/Controller\/DefaultController.php":1808993837,"AppBundle\/Controller\/PartsController.php":4003925149,"AppBundle\/Controller\/SetsController.php":143594046,"AppBundle\/Entity\/BuildingKit.php":3308278633,"AppBundle\/Entity\/Category.php":124321505,"AppBundle\/Entity\/Color.php":2674087189,"AppBundle\/Entity\/Keyword.php":1280636090,"AppBundle\/Entity\/Model.php":2973229730,"AppBundle\/Entity\/Part.php":2983178643,"AppBundle\/Entity\/Part_BuildingKit.php":2128957211,"AppBundle\/Form\/FilterSetType.php":3736472246,"AppBundle\/Loader\/LDrawLoader.php":176896315,"AppBundle\/Loader\/Loader.php":628739449,"AppBundle\/Loader\/RebrickableLoader.php":2358898105,"AppBundle\/Menu\/Builder.php":3290107856,"AppBundle\/Repository\/BuildingKitRepository.php":2692042214,"AppBundle\/Repository\/CategoryRepository.php":3367406378,"AppBundle\/Repository\/ColorRepository.php":1014637369,"AppBundle\/Repository\/KeywordRepository.php":3805084377,"AppBundle\/Repository\/ModelRepository.php":761334234,"AppBundle\/Repository\/PartRepository.php":1030144656,"AppBundle\/Repository\/Part_BuildingKitRepository.php":3761143311,"AppBundle\/Service\/CollectionService.php":328311202}} \ No newline at end of file diff --git a/bin/php-cs-fixer-hook.sh b/bin/php-cs-fixer-hook.sh new file mode 100644 index 0000000..c5454d0 --- /dev/null +++ b/bin/php-cs-fixer-hook.sh @@ -0,0 +1,30 @@ +#!/bin/sh + +# To use this hook you need to install php-cs-fixer +# Copy this file to ./git/hooks/pre-commit to get it working. + +ROOT="/" + +echo "php-cs-fixer pre commit hook start" + +PHP_CS_FIXER="vendor/bin/php-cs-fixer" +HAS_PHP_CS_FIXER=false + +if [ -x vendor/bin/php-cs-fixer ]; then + HAS_PHP_CS_FIXER=true +fi + +if $HAS_PHP_CS_FIXER; then + git status --porcelain | grep -e '^[AM]\(.*\).php$' | cut -c 3- | while read line; do + $PHP_CS_FIXER fix --config-file=$ROOT/.php_cs --verbose "$line"; + git add "$line"; + done +else + echo "" + echo "Please install php-cs-fixer, e.g.:" + echo "" + echo " composer require --dev friendsofphp/php-cs-fixer" + echo "" +fi + +echo "php-cs-fixer pre commit hook finish" \ No newline at end of file diff --git a/composer.json b/composer.json index 03662cb..4346b66 100644 --- a/composer.json +++ b/composer.json @@ -28,7 +28,8 @@ }, "require-dev": { "sensio/generator-bundle": "^3.0", - "symfony/phpunit-bridge": "^3.0" + "symfony/phpunit-bridge": "^3.0", + "friendsofphp/php-cs-fixer": "^2.0" }, "scripts": { "symfony-scripts": [ diff --git a/composer.lock b/composer.lock index 87a600a..fccd0a0 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "content-hash": "a13e1582c61b7faed478722b500ee8a9", + "content-hash": "54b7bfc7ee85ba1c5bb4cd9f7d9cfa60", "packages": [ { "name": "doctrine/annotations", @@ -2478,6 +2478,123 @@ } ], "packages-dev": [ + { + "name": "friendsofphp/php-cs-fixer", + "version": "v2.0.0", + "source": { + "type": "git", + "url": "https://github.com/FriendsOfPHP/PHP-CS-Fixer.git", + "reference": "f3baf72eb2f58bf275b372540f5b47d25aed910f" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/FriendsOfPHP/PHP-CS-Fixer/zipball/f3baf72eb2f58bf275b372540f5b47d25aed910f", + "reference": "f3baf72eb2f58bf275b372540f5b47d25aed910f", + "shasum": "" + }, + "require": { + "ext-tokenizer": "*", + "php": "^5.3.6 || >=7.0 <7.2", + "sebastian/diff": "^1.1", + "symfony/console": "^2.3 || ^3.0", + "symfony/event-dispatcher": "^2.1 || ^3.0", + "symfony/filesystem": "^2.4 || ^3.0", + "symfony/finder": "^2.2 || ^3.0", + "symfony/polyfill-php54": "^1.0", + "symfony/process": "^2.3 || ^3.0", + "symfony/stopwatch": "^2.5 || ^3.0" + }, + "conflict": { + "hhvm": "<3.9" + }, + "require-dev": { + "gecko-packages/gecko-php-unit": "^2.0", + "phpunit/phpunit": "^4.5|^5", + "satooshi/php-coveralls": "^1.0" + }, + "bin": [ + "php-cs-fixer" + ], + "type": "application", + "extra": { + "branch-alias": { + "dev-master": "2.0-dev" + } + }, + "autoload": { + "psr-4": { + "PhpCsFixer\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Dariusz RumiƄski", + "email": "dariusz.ruminski@gmail.com" + }, + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + } + ], + "description": "A tool to automatically fix PHP code style", + "time": "2016-12-01T06:18:06+00:00" + }, + { + "name": "sebastian/diff", + "version": "1.4.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/diff.git", + "reference": "13edfd8706462032c2f52b4b862974dd46b71c9e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/13edfd8706462032c2f52b4b862974dd46b71c9e", + "reference": "13edfd8706462032c2f52b4b862974dd46b71c9e", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "require-dev": { + "phpunit/phpunit": "~4.8" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.4-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Kore Nordmann", + "email": "mail@kore-nordmann.de" + }, + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Diff implementation", + "homepage": "https://github.com/sebastianbergmann/diff", + "keywords": [ + "diff" + ], + "time": "2015-12-08T07:14:41+00:00" + }, { "name": "sensio/generator-bundle", "version": "v3.1.2", @@ -2587,6 +2704,64 @@ "description": "Symfony PHPUnit Bridge", "homepage": "https://symfony.com", "time": "2016-12-12T13:31:08+00:00" + }, + { + "name": "symfony/polyfill-php54", + "version": "v1.3.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-php54.git", + "reference": "90e085822963fdcc9d1c5b73deb3d2e5783b16a0" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-php54/zipball/90e085822963fdcc9d1c5b73deb3d2e5783b16a0", + "reference": "90e085822963fdcc9d1c5b73deb3d2e5783b16a0", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.3-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Polyfill\\Php54\\": "" + }, + "files": [ + "bootstrap.php" + ], + "classmap": [ + "Resources/stubs" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony polyfill backporting some PHP 5.4+ features to lower PHP versions", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "polyfill", + "portable", + "shim" + ], + "time": "2016-11-14T01:06:16+00:00" } ], "aliases": [],