From b943ba59cf49d15df901f61f45c0c03a4dc6cfb2 Mon Sep 17 00:00:00 2001 From: zingimmick Date: Tue, 28 Jul 2020 00:19:38 +0800 Subject: [PATCH] Update doctrine/inflector requirement from ^1.3 to ^1.4|^2.0 --- composer.json | 2 +- config/services.php | 7 +++++++ .../src/Rector/For_/ForToForeachRector.php | 12 +++++++++--- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/composer.json b/composer.json index 22bb3092cef..299f30c3c22 100644 --- a/composer.json +++ b/composer.json @@ -14,7 +14,7 @@ "ext-json": "*", "composer/xdebug-handler": "^1.4", "doctrine/annotations": "^1.10.2", - "doctrine/inflector": "^1.3", + "doctrine/inflector": "^1.4|^2.0", "jean85/pretty-package-versions": "^1.2", "nette/robot-loader": "^3.2", "nette/utils": "^3.1", diff --git a/config/services.php b/config/services.php index 4a5072b67fd..2302e63c093 100644 --- a/config/services.php +++ b/config/services.php @@ -2,6 +2,8 @@ declare(strict_types=1); +use Doctrine\Inflector\Inflector; +use Doctrine\Inflector\Rules\English\InflectorFactory; use OndraM\CiDetector\CiDetector; use PhpParser\BuilderFactory; use PhpParser\Lexer; @@ -99,4 +101,9 @@ return static function (ContainerConfigurator $containerConfigurator): void { $services->set(SymfonyStyle::class) ->factory([ref(SymfonyStyleFactory::class), 'create']); + + $services->set(InflectorFactory::class); + + $services->set(Inflector::class) + ->factory([ref(InflectorFactory::class), 'build']); }; diff --git a/rules/code-quality/src/Rector/For_/ForToForeachRector.php b/rules/code-quality/src/Rector/For_/ForToForeachRector.php index 525b53e4cc9..5eba5a1e460 100644 --- a/rules/code-quality/src/Rector/For_/ForToForeachRector.php +++ b/rules/code-quality/src/Rector/For_/ForToForeachRector.php @@ -4,7 +4,7 @@ declare(strict_types=1); namespace Rector\CodeQuality\Rector\For_; -use Doctrine\Common\Inflector\Inflector; +use Doctrine\Inflector\Inflector; use PhpParser\Node; use PhpParser\Node\Expr; use PhpParser\Node\Expr\ArrayDimFetch; @@ -50,9 +50,15 @@ final class ForToForeachRector extends AbstractRector */ private $assignManipulator; - public function __construct(AssignManipulator $assignManipulator) + /** + * @var Inflector + */ + private $inflector; + + public function __construct(AssignManipulator $assignManipulator, Inflector $inflector) { $this->assignManipulator = $assignManipulator; + $this->inflector = $inflector; } public function getDefinition(): RectorDefinition @@ -132,7 +138,7 @@ PHP return null; } - $iteratedVariableSingle = Inflector::singularize($iteratedVariable); + $iteratedVariableSingle = $this->inflector->singularize($iteratedVariable); $foreach = $this->createForeach($node, $iteratedVariableSingle); $this->useForeachVariableInStmts($foreach->expr, $foreach->valueVar, $foreach->stmts);