From b72957ddbcc3816fc02b642fc8f0768a145924a6 Mon Sep 17 00:00:00 2001 From: Pierre PLAZANET Date: Wed, 26 Feb 2020 11:49:20 +0100 Subject: [PATCH] feat: deprecate php 7.1 --- .circleci/config.yml | 58 +++++++++---------- .php_cs.dist | 2 +- .releaserc | 4 +- composer.json | 8 +-- rector.yaml | 19 +++--- .../LineBreakBetweenStatementsFixer.php | 8 +-- .../Fixer/Comment/SingleLineCommentFixer.php | 8 +-- .../CS/Fixer/DoctrineMigrationsFixer.php | 17 +++--- src/PedroTroller/CS/Fixer/Priority.php | 4 +- src/PedroTroller/CS/Fixer/RuleSetFactory.php | 2 - src/PedroTroller/CS/Fixer/TokensAnalyzer.php | 6 +- 11 files changed, 70 insertions(+), 66 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 4454edd..b1c304b 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -26,73 +26,73 @@ tests_with_future_mode: &tests_with_future_mode composer run php-cs-fixer || (echo "Coding standards are not respected. Run 'composer run php-cs-fixer'" && exit 1) jobs: - php 7.1: + php 7.2: docker: - - image: circleci/php:7.1 + - image: circleci/php:7.2 steps: - checkout - <<: *composer - <<: *tests - php 7.1 with future mode: + php 7.2 with future mode: docker: - - image: circleci/php:7.1 + - image: circleci/php:7.2 steps: - checkout - <<: *composer - <<: *tests_with_future_mode - php 7.1 with lowest dependencies: + php 7.2 with lowest dependencies: docker: - - image: circleci/php:7.1 + - image: circleci/php:7.2 steps: - checkout - <<: *composer_with_lowest_dependencies - <<: *tests - php 7.2: + php 7.3: docker: - - image: circleci/php:7.2 + - image: circleci/php:7.3 steps: - checkout - <<: *composer - <<: *tests - php 7.2 with future mode: + php 7.3 with future mode: docker: - - image: circleci/php:7.2 + - image: circleci/php:7.3 steps: - checkout - <<: *composer - <<: *tests_with_future_mode - php 7.2 with lowest dependencies: + php 7.3 with lowest dependencies: docker: - - image: circleci/php:7.2 + - image: circleci/php:7.3 steps: - checkout - <<: *composer_with_lowest_dependencies - <<: *tests - php 7.3: + php 7.4: docker: - - image: circleci/php:7.3 + - image: circleci/php:7.4 steps: - checkout - <<: *composer - <<: *tests - php 7.3 with future mode: + php 7.4 with future mode: docker: - - image: circleci/php:7.3 + - image: circleci/php:7.4 steps: - checkout - <<: *composer - <<: *tests_with_future_mode - php 7.3 with lowest dependencies: + php 7.4 with lowest dependencies: docker: - - image: circleci/php:7.3 + - image: circleci/php:7.4 steps: - checkout - <<: *composer_with_lowest_dependencies @@ -100,7 +100,7 @@ jobs: documentation is up to date: docker: - - image: circleci/php:7.3 + - image: circleci/php:7.4 steps: - checkout - <<: *composer @@ -120,13 +120,6 @@ workflows: PR: jobs: - documentation is up to date - - php 7.1 - - php 7.1 with future mode: - requires: - - php 7.1 - - php 7.1 with lowest dependencies: - requires: - - php 7.1 - php 7.2 - php 7.2 with future mode: requires: @@ -141,18 +134,25 @@ workflows: - php 7.3 with lowest dependencies: requires: - php 7.3 + - php 7.4 + - php 7.4 with future mode: + requires: + - php 7.4 + - php 7.4 with lowest dependencies: + requires: + - php 7.4 - release: requires: - documentation is up to date - - php 7.1 - - php 7.1 with future mode - - php 7.1 with lowest dependencies - php 7.2 - php 7.2 with future mode - php 7.2 with lowest dependencies - php 7.3 - php 7.3 with future mode - php 7.3 with lowest dependencies + - php 7.4 + - php 7.4 with future mode + - php 7.4 with lowest dependencies filters: branches: only: diff --git a/.php_cs.dist b/.php_cs.dist index 3a419a5..35353f3 100644 --- a/.php_cs.dist +++ b/.php_cs.dist @@ -10,7 +10,7 @@ return PhpCsFixer\Config::create() ->setRules( RuleSetFactory::create() ->phpCsFixer(true) - ->php(7.1, true) + ->php(7.2, true) ->pedrotroller(true) ->enable('ordered_imports') ->enable('ordered_interfaces') diff --git a/.releaserc b/.releaserc index b2468d9..5fb5abd 100644 --- a/.releaserc +++ b/.releaserc @@ -10,9 +10,9 @@ plugins: release: minor - type: fix scope: deps-dev - release: patch + release: false - type: refactor - release: patch + release: false - scope: chore release: false - '@semantic-release/release-notes-generator' diff --git a/composer.json b/composer.json index 8e5f5ec..76cf26c 100644 --- a/composer.json +++ b/composer.json @@ -3,12 +3,12 @@ "description": "PHP-CS-FIXER : my custom fixers", "license": "MIT", "require": { - "php": ">=7.1", - "friendsofphp/php-cs-fixer": "^2.15.0" + "php": ">=7.2", + "friendsofphp/php-cs-fixer": "^2.16.1" }, "require-dev": { - "phpspec/phpspec": "^5.1.0", - "rector/rector": "^0.5.19", + "phpspec/phpspec": "^6.1", + "rector/rector": "^0.7.1", "twig/twig": "^2.11.3", "webmozart/assert": "^1.3.0" }, diff --git a/rector.yaml b/rector.yaml index ec34ee5..0028795 100644 --- a/rector.yaml +++ b/rector.yaml @@ -1,13 +1,16 @@ --- parameters: auto_import_names: true - exclude_rectors: - Rector\CodeQuality\Rector\Identical\SimplifyBoolIdenticalTrueRector - -imports: - - resource: vendor/rector/rector/config/set/code-quality/* - - resource: vendor/rector/rector/config/set/php/php71.yaml - - resource: vendor/rector/rector/config/set/phpspec/* - - resource: vendor/rector/rector/config/set/psr-4/* - - resource: vendor/rector/rector/config/set/solid/* + paths: + - src + - tests + - spec + sets: + - code-quality + - php71 + - php72 + - phpspec + - psr-4 + - solid diff --git a/src/PedroTroller/CS/Fixer/CodingStyle/LineBreakBetweenStatementsFixer.php b/src/PedroTroller/CS/Fixer/CodingStyle/LineBreakBetweenStatementsFixer.php index c26e64d..9053056 100644 --- a/src/PedroTroller/CS/Fixer/CodingStyle/LineBreakBetweenStatementsFixer.php +++ b/src/PedroTroller/CS/Fixer/CodingStyle/LineBreakBetweenStatementsFixer.php @@ -14,7 +14,7 @@ final class LineBreakBetweenStatementsFixer extends AbstractFixer /** * @var array */ - private $handlers = [ + private const HANDLERS = [ T_DO => 'do', T_FOR => 'common', T_FOREACH => 'common', @@ -68,8 +68,8 @@ public function getDocumentation() protected function applyFix(SplFileInfo $file, Tokens $tokens): void { - foreach ($tokens->findGivenKind(array_keys($this->handlers)) as $kind => $matchedTokens) { - $this->{'handle'.ucfirst($this->handlers[$kind])}($matchedTokens, $tokens); + foreach ($tokens->findGivenKind(array_keys(self::HANDLERS)) as $kind => $matchedTokens) { + $this->{'handle'.ucfirst(self::HANDLERS[$kind])}($matchedTokens, $tokens); } } @@ -127,7 +127,7 @@ private function fixSpaces($index, Tokens $tokens): void return; } - if (false === \array_key_exists($tokens[$nextMeaningful]->getId(), $this->handlers)) { + if (false === \array_key_exists($tokens[$nextMeaningful]->getId(), self::HANDLERS)) { return; } diff --git a/src/PedroTroller/CS/Fixer/Comment/SingleLineCommentFixer.php b/src/PedroTroller/CS/Fixer/Comment/SingleLineCommentFixer.php index 0e4cdc3..cac7bb7 100644 --- a/src/PedroTroller/CS/Fixer/Comment/SingleLineCommentFixer.php +++ b/src/PedroTroller/CS/Fixer/Comment/SingleLineCommentFixer.php @@ -18,12 +18,12 @@ final class SingleLineCommentFixer extends AbstractFixer implements Configuratio /** * @var string */ - private $collapseRegex = '/( *)\/[*]{1,2}\n( *)[*]{1,2} %s (.+)\n( *)\*\//'; + private const COLLAPSE_REGEX = '/( *)\/[*]{1,2}\n( *)[*]{1,2} %s (.+)\n( *)\*\//'; /** * @var string */ - private $expandRegex = '/( *)\/[*]{1,2} %s (.+) \*\//'; + private const EXPAND_REGEX = '/( *)\/[*]{1,2} %s (.+) \*\//'; /** * {@inheritdoc} @@ -129,7 +129,7 @@ private function expandedComment(Tokens $tokens): void } foreach ($this->configuration['types'] as $variable) { - $regex = sprintf($this->expandRegex, $variable); + $regex = sprintf(self::EXPAND_REGEX, $variable); $replace = sprintf("/**\n%s * %s $2\n%s */", $space, $variable, $space); $comment = preg_replace($regex, $replace, $token->getContent()); $tokens[$index] = new Token([T_COMMENT, $comment]); @@ -141,7 +141,7 @@ private function collapsedComment(Tokens $tokens): void { foreach ($this->getComments($tokens) as $index => $token) { foreach ($this->configuration['types'] as $variable) { - $regex = sprintf($this->collapseRegex, $variable); + $regex = sprintf(self::COLLAPSE_REGEX, $variable); $replace = sprintf('$1/** %s $3 */', $variable); $comment = preg_replace($regex, $replace, $token->getContent()); $tokens[$index] = new Token([T_COMMENT, $comment]); diff --git a/src/PedroTroller/CS/Fixer/DoctrineMigrationsFixer.php b/src/PedroTroller/CS/Fixer/DoctrineMigrationsFixer.php index 55d5242..9bcdc93 100644 --- a/src/PedroTroller/CS/Fixer/DoctrineMigrationsFixer.php +++ b/src/PedroTroller/CS/Fixer/DoctrineMigrationsFixer.php @@ -16,6 +16,15 @@ final class DoctrineMigrationsFixer extends AbstractFixer implements ConfigurationDefinitionFixerInterface { + /** + * @var string[] + */ + private const BLACKLIST = [ + 'Auto-generated Migration: Please modify to your needs!', + 'this up() migration is auto-generated, please modify it to your needs', + 'this down() migration is auto-generated, please modify it to your needs', + ]; + public function getSampleConfigurations() { return [ @@ -161,18 +170,12 @@ private function removeUselessComments(Tokens $tokens): void { $comments = $this->getComments($tokens); - $blackList = [ - 'Auto-generated Migration: Please modify to your needs!', - 'this up() migration is auto-generated, please modify it to your needs', - 'this down() migration is auto-generated, please modify it to your needs', - ]; - foreach ($comments as $position => $comment) { $lines = explode("\n", $comment->getContent()); $changed = false; foreach ($lines as $index => $line) { - if (\in_array(trim($line, '/* '), $blackList, true)) { + if (\in_array(trim($line, '/* '), self::BLACKLIST, true)) { unset($lines[$index]); $changed = true; } diff --git a/src/PedroTroller/CS/Fixer/Priority.php b/src/PedroTroller/CS/Fixer/Priority.php index 4cd2b12..d6c160b 100644 --- a/src/PedroTroller/CS/Fixer/Priority.php +++ b/src/PedroTroller/CS/Fixer/Priority.php @@ -11,7 +11,7 @@ private function __construct() } /** - * @param array $classes + * @param array $classes * * @return int */ @@ -28,7 +28,7 @@ function ($class) { } /** - * @param array $classes + * @param array $classes * * @return int */ diff --git a/src/PedroTroller/CS/Fixer/RuleSetFactory.php b/src/PedroTroller/CS/Fixer/RuleSetFactory.php index 1f33513..fc2a496 100644 --- a/src/PedroTroller/CS/Fixer/RuleSetFactory.php +++ b/src/PedroTroller/CS/Fixer/RuleSetFactory.php @@ -233,8 +233,6 @@ private function migration($package, $version, $risky) $rules = array_combine($rules, $rules); $rules = array_map(function ($name) { - $matches = []; - preg_match('/^@([A-Za-z]+)(\d+)Migration(:risky|)$/', $name, $matches); return $matches; diff --git a/src/PedroTroller/CS/Fixer/TokensAnalyzer.php b/src/PedroTroller/CS/Fixer/TokensAnalyzer.php index d12f062..fff15cb 100644 --- a/src/PedroTroller/CS/Fixer/TokensAnalyzer.php +++ b/src/PedroTroller/CS/Fixer/TokensAnalyzer.php @@ -311,7 +311,7 @@ public function endOfTheStatement($index) /** * @param int $index * - * @return int | null + * @return null|int */ public function getClosingParenthesis($index) { @@ -339,7 +339,7 @@ public function getClosingParenthesis($index) /** * @param int $index * - * @return int | null + * @return null|int */ public function getClosingBracket($index) { @@ -367,7 +367,7 @@ public function getClosingBracket($index) /** * @param int $index * - * @return int | null + * @return null|int */ public function getClosingCurlyBracket($index) {