From db98db8ae90511b609f7f2339eda98a73c370c92 Mon Sep 17 00:00:00 2001 From: Feyyaz Esatoglu Date: Fri, 18 Oct 2019 11:33:04 +0200 Subject: [PATCH 1/7] APM-541 cs fixer should be regular dependency. --- composer.json | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/composer.json b/composer.json index 09a9444..3d194ee 100644 --- a/composer.json +++ b/composer.json @@ -16,9 +16,7 @@ }, "minimum-stability": "stable", "require": { - "php": "^7.1.3" - }, - "require-dev": { + "php": "^7.1.3", "friendsofphp/php-cs-fixer": "^2.15" }, "bin": [ From 285c64f4552d776bd8a82116788f8e22442af6d2 Mon Sep 17 00:00:00 2001 From: Feyyaz Esatoglu Date: Fri, 18 Oct 2019 13:17:19 +0200 Subject: [PATCH 2/7] APM-541 Installation and Usage information added to Readme.md. --- README.md | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/README.md b/README.md index a4a2b20..74055ba 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,69 @@ # Mollie PHP Coding Standards Contains PHP coding standards like rules for PHP-CS-Fixer that serves for purpose of standardization. + +## Usage + +Place a file named `.php_cs.dist` that has following content in your project's root directory. + +```php +use PhpCsFixer\Config; +use PhpCsFixer\Finder; + +$finder = Finder::create() + ->name('.php_cs.dist') // Fix this file as well + ->in(__DIR__); + +return Config::create() + ->setFinder($finder) + ->setRiskyAllowed(true) + ->setRules(Rules::getForPhp71()); +``` +### Manual Triggering +Run following command in your project directory, that will run fixer for every `.php` file. +```bash +vendor/bin/php-cs-fixer fix . +``` + +### Use via PHPStorm file watcher +Please follow [official PHPStorm documentation](https://www.jetbrains.com/help/phpstorm/using-php-cs-fixer.html#f21a70ca) + +### Use via pre-commit, pre-push etc. git hook + +Place a file with the content of the following bash script into `.git/hooks` directory called pre-commit or pre-push +and make it executable +you can find more details about git hooks on [official git manual](https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks). + +```bash +#!/usr/bin/env bash + +EXCLUDE_DIRECTORIES_REGEX='^(directory_one/(sub_directory_one|sub_directory_two)|directory_two)/.*' +git diff --diff-filter=ACMRTUXB --name-only --staged | grep -E '\.php(_cs\.dist)?$' | grep -vE $EXCLUDE_DIRECTORIES_REGEX | while read FILE; do + STATUS="$(git status --porcelain ${FILE} | cut -c 1-2)" + vendor/bin/php-cs-fixer fix --using-cache=no --quiet --dry-run ${FILE} + + # Not 0 means php-cs-fixer either errored or wanted to make changes + if [ $? != 0 ] + then + # MM = staged & non-staged modification in same file + if [ ${STATUS} = "MM" ] + then + echo -e "\033[31m┌────────────────────────────────────────────────────────────────────────────────┐" + echo -e "│ Failure:\033[39m Codestyle violation(s) in file with both staged and unstaged changes. \033[31m│" + echo -e "├────────────────────────────────────────────────────────────────────────────────┘" + echo -e "└\033[33m File:\033[39m $FILE" + exit 1 + fi + + vendor/bin/php-cs-fixer fix --using-cache=no --quiet ${FILE} + git add ${FILE} + fi +done +``` + +## Installation +[Get Composer](https://getcomposer.org/doc/faqs/how-to-install-composer-programmatically.md) + +```bash +composer require --dev mollie/php-coding-standards:v1.0 +``` From 9b2ce09c75333debccac3b4f14644d715d59d7ee Mon Sep 17 00:00:00 2001 From: Feyyaz Esatoglu Date: Fri, 18 Oct 2019 13:39:34 +0200 Subject: [PATCH 3/7] APM-541 .php_cs.dist fixed. --- .php_cs.dist | 1 + README.md | 2 ++ src/PhpCsFixer/Rules.php | 4 ++-- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/.php_cs.dist b/.php_cs.dist index b537623..254edaf 100644 --- a/.php_cs.dist +++ b/.php_cs.dist @@ -2,6 +2,7 @@ use PhpCsFixer\Config; use PhpCsFixer\Finder; +use Mollie\PhpCodingStandards\PhpCsFixer\Rules; $finder = Finder::create() ->name('.php_cs.dist') // Fix this file as well diff --git a/README.md b/README.md index 74055ba..24b47f2 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,7 @@ Place a file named `.php_cs.dist` that has following content in your project's r ```php use PhpCsFixer\Config; use PhpCsFixer\Finder; +use Mollie\PhpCodingStandards\PhpCsFixer\Rules; $finder = Finder::create() ->name('.php_cs.dist') // Fix this file as well @@ -18,6 +19,7 @@ return Config::create() ->setFinder($finder) ->setRiskyAllowed(true) ->setRules(Rules::getForPhp71()); + ``` ### Manual Triggering Run following command in your project directory, that will run fixer for every `.php` file. diff --git a/src/PhpCsFixer/Rules.php b/src/PhpCsFixer/Rules.php index 77aebd8..f8daeb3 100644 --- a/src/PhpCsFixer/Rules.php +++ b/src/PhpCsFixer/Rules.php @@ -14,7 +14,7 @@ public static function getForPhp71(array $overriddenRules = []): array return array_merge(self::getBaseRules(), $overriddenRules); } - public static function getForPhp72(array $overriddenRules = []) : array + public static function getForPhp72(array $overriddenRules = []): array { $specific72Rules = [ // At the moment there are no specific 7.2 rules or configurations @@ -23,7 +23,7 @@ public static function getForPhp72(array $overriddenRules = []) : array return array_merge(self::getForPhp71($specific72Rules), $overriddenRules); } - public static function getForPhp73(array $overriddenRules = []) : array + public static function getForPhp73(array $overriddenRules = []): array { $specific73Rules = [ 'heredoc_indentation' => true, From 502803382bd592afbfd9fa58f99911e77bf8da55 Mon Sep 17 00:00:00 2001 From: Feyyaz Esatoglu Date: Fri, 18 Oct 2019 13:54:42 +0200 Subject: [PATCH 4/7] APM-541 suggestions from @dmvdbrugge reflected. --- .php_cs.dist | 2 +- README.md | 28 ++++++++++++++++++---------- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/.php_cs.dist b/.php_cs.dist index 254edaf..72983ea 100644 --- a/.php_cs.dist +++ b/.php_cs.dist @@ -1,8 +1,8 @@ name('.php_cs.dist') // Fix this file as well diff --git a/README.md b/README.md index 24b47f2..c1cbd16 100644 --- a/README.md +++ b/README.md @@ -7,9 +7,9 @@ Contains PHP coding standards like rules for PHP-CS-Fixer that serves for purpos Place a file named `.php_cs.dist` that has following content in your project's root directory. ```php +use Mollie\PhpCodingStandards\PhpCsFixer\Rules; use PhpCsFixer\Config; use PhpCsFixer\Finder; -use Mollie\PhpCodingStandards\PhpCsFixer\Rules; $finder = Finder::create() ->name('.php_cs.dist') // Fix this file as well @@ -18,22 +18,21 @@ $finder = Finder::create() return Config::create() ->setFinder($finder) ->setRiskyAllowed(true) - ->setRules(Rules::getForPhp71()); + ->setRules(Rules::getForPhp71()); // use specific rules for your php version e.g.: getForPhp71, getForPhp72, getForPhp73 ``` ### Manual Triggering Run following command in your project directory, that will run fixer for every `.php` file. ```bash -vendor/bin/php-cs-fixer fix . +vendor/bin/php-cs-fixer fix ``` -### Use via PHPStorm file watcher -Please follow [official PHPStorm documentation](https://www.jetbrains.com/help/phpstorm/using-php-cs-fixer.html#f21a70ca) +### Use via PhpStorm file watcher +Please follow [official PhpStorm documentation](https://www.jetbrains.com/help/phpstorm/using-php-cs-fixer.html#f21a70ca) -### Use via pre-commit, pre-push etc. git hook +### Use via pre-commit git hook -Place a file with the content of the following bash script into `.git/hooks` directory called pre-commit or pre-push -and make it executable +Place a file with the content of the following bash script into `.git/hooks` directory called pre-commit and make it executable you can find more details about git hooks on [official git manual](https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks). ```bash @@ -64,8 +63,17 @@ done ``` ## Installation -[Get Composer](https://getcomposer.org/doc/faqs/how-to-install-composer-programmatically.md) ```bash -composer require --dev mollie/php-coding-standards:v1.0 +composer require --dev mollie/php-coding-standards: ^1.0 ``` + +## Working at Mollie + +Mollie is always looking for new talent to join our teams. We’re looking for inquisitive minds with good ideas and +strong opinions, and, most importantly, who know how to ship great products. Want to join the future of payments? +[Check out our vacancies](https://jobs.mollie.com). + +## License +[BSD (Berkeley Software Distribution) License](https://opensource.org/licenses/bsd-license.php). +Copyright (c) 2013-2019, Mollie B.V. From 01643d68be23abb82a376962806bdf92130eda13 Mon Sep 17 00:00:00 2001 From: Feyyaz Esatoglu Date: Fri, 18 Oct 2019 14:14:10 +0200 Subject: [PATCH 5/7] APM-541 lines fixed --- README.md | 5 ----- 1 file changed, 5 deletions(-) diff --git a/README.md b/README.md index c1cbd16..c064888 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,7 @@ # Mollie PHP Coding Standards - Contains PHP coding standards like rules for PHP-CS-Fixer that serves for purpose of standardization. ## Usage - Place a file named `.php_cs.dist` that has following content in your project's root directory. ```php @@ -31,7 +29,6 @@ vendor/bin/php-cs-fixer fix Please follow [official PhpStorm documentation](https://www.jetbrains.com/help/phpstorm/using-php-cs-fixer.html#f21a70ca) ### Use via pre-commit git hook - Place a file with the content of the following bash script into `.git/hooks` directory called pre-commit and make it executable you can find more details about git hooks on [official git manual](https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks). @@ -63,13 +60,11 @@ done ``` ## Installation - ```bash composer require --dev mollie/php-coding-standards: ^1.0 ``` ## Working at Mollie - Mollie is always looking for new talent to join our teams. We’re looking for inquisitive minds with good ideas and strong opinions, and, most importantly, who know how to ship great products. Want to join the future of payments? [Check out our vacancies](https://jobs.mollie.com). From 4e832275579b3c752ba4336b4c9be323f59b5f66 Mon Sep 17 00:00:00 2001 From: Feyyaz Esatoglu Date: Fri, 18 Oct 2019 14:21:32 +0200 Subject: [PATCH 6/7] APM-541 fixes requested by @dmvdbrugge --- README.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index c064888..780d79a 100644 --- a/README.md +++ b/README.md @@ -10,13 +10,14 @@ use PhpCsFixer\Config; use PhpCsFixer\Finder; $finder = Finder::create() - ->name('.php_cs.dist') // Fix this file as well + ->name('.php_cs.dist') // Fix this file as well ->in(__DIR__); return Config::create() ->setFinder($finder) ->setRiskyAllowed(true) - ->setRules(Rules::getForPhp71()); // use specific rules for your php version e.g.: getForPhp71, getForPhp72, getForPhp73 + // use specific rules for your php version e.g.: getForPhp71, getForPhp72, getForPhp73 + ->setRules(Rules::getForPhp71()); ``` ### Manual Triggering @@ -61,7 +62,7 @@ done ## Installation ```bash -composer require --dev mollie/php-coding-standards: ^1.0 +composer require --dev mollie/php-coding-standards ``` ## Working at Mollie From a6335f414faa726eb17e18f8dbc60f3af9929189 Mon Sep 17 00:00:00 2001 From: Feyyaz Esatoglu Date: Fri, 18 Oct 2019 15:03:47 +0200 Subject: [PATCH 7/7] APM-541 fixes requested by @dmvdbrugge --- README.md | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 780d79a..72bb5bc 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,23 @@ Contains PHP coding standards like rules for PHP-CS-Fixer that serves for purpose of standardization. ## Usage +This package makes use of PHP-CS-Fixer. + +### Already familiar with PHP-CS-Fixer + +This package provides default rules to be used with PHP-CS-Fixer. + +You can find them in `Mollie\PhpCodingStandards\PhpCsFixer\Rules` which has methods specific to php version, +which you can directly use in the `->setRules()` part of your config. For example, assuming PHP version 7.3: + +```php +use Mollie\PhpCodingStandards\PhpCsFixer\Rules; + +$config->setRules(Rules::getForPhp73()); +``` + +### New to PHP-CS-Fixer + Place a file named `.php_cs.dist` that has following content in your project's root directory. ```php @@ -18,8 +35,8 @@ return Config::create() ->setRiskyAllowed(true) // use specific rules for your php version e.g.: getForPhp71, getForPhp72, getForPhp73 ->setRules(Rules::getForPhp71()); - ``` + ### Manual Triggering Run following command in your project directory, that will run fixer for every `.php` file. ```bash