-
-
Notifications
You must be signed in to change notification settings - Fork 687
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated Rector to commit 6bff51172cf396da8abc062d96f0406fd86ef349
rectorphp/rector-src@6bff511 [e2e] Add e2e for polyfill in composer require provided (#5392)
- Loading branch information
1 parent
24ab723
commit a8c5484
Showing
8 changed files
with
111 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
...or-doctrine/rules/Dbal211/Rector/MethodCall/ExtractArrayArgOnQueryBuilderSelectRector.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
<?php | ||
|
||
declare (strict_types=1); | ||
namespace Rector\Doctrine\Dbal211\Rector\MethodCall; | ||
|
||
use PhpParser\Node; | ||
use PhpParser\Node\Arg; | ||
use PhpParser\Node\Expr\Array_; | ||
use PhpParser\Node\Expr\ArrayItem; | ||
use PhpParser\Node\Expr\MethodCall; | ||
use PHPStan\Type\ObjectType; | ||
use Rector\Core\Rector\AbstractRector; | ||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; | ||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; | ||
/** | ||
* @changelog https://github.com/doctrine/dbal/pull/3853 | ||
* @changelog https://github.com/doctrine/dbal/issues/3837 | ||
* | ||
* @see \Rector\Doctrine\Tests\Dbal211\Rector\MethodCall\ExtractArrayArgOnQueryBuilderSelectRector\ExtractArrayArgOnQueryBuilderSelectRectorTest | ||
*/ | ||
final class ExtractArrayArgOnQueryBuilderSelectRector extends AbstractRector | ||
{ | ||
/** | ||
* @return array<class-string<Node>> | ||
*/ | ||
public function getNodeTypes() : array | ||
{ | ||
return [MethodCall::class]; | ||
} | ||
public function getRuleDefinition() : RuleDefinition | ||
{ | ||
return new RuleDefinition('Extract array arg on QueryBuilder select, addSelect, groupBy, addGroupBy', [new CodeSample(<<<'CODE_SAMPLE' | ||
function query(\Doctrine\DBAL\Query\QueryBuilder $queryBuilder) | ||
{ | ||
$query = $queryBuilder->select(['u.id', 'p.id']); | ||
} | ||
CODE_SAMPLE | ||
, <<<'CODE_SAMPLE' | ||
function query(\Doctrine\DBAL\Query\QueryBuilder $queryBuilder) | ||
{ | ||
$query = $queryBuilder->select('u.id', 'p.id'); | ||
} | ||
CODE_SAMPLE | ||
)]); | ||
} | ||
/** | ||
* @param MethodCall $node | ||
*/ | ||
public function refactor(Node $node) : ?MethodCall | ||
{ | ||
$varType = $this->nodeTypeResolver->getType($node->var); | ||
if (!$varType instanceof ObjectType) { | ||
return null; | ||
} | ||
if (!$varType->isInstanceOf('Doctrine\\DBAL\\Query\\QueryBuilder')->yes()) { | ||
return null; | ||
} | ||
if (!$this->isNames($node->name, ['select', 'addSelect', 'groupBy', 'addGroupBy'])) { | ||
return null; | ||
} | ||
if ($node->isFirstClassCallable()) { | ||
return null; | ||
} | ||
$args = $node->getArgs(); | ||
if (\count($args) !== 1) { | ||
return null; | ||
} | ||
$currentArg = $args[0]->value; | ||
if (!$currentArg instanceof Array_) { | ||
return null; | ||
} | ||
$newArgs = []; | ||
foreach ($currentArg->items as $value) { | ||
if (!$value instanceof ArrayItem) { | ||
return null; | ||
} | ||
$newArgs[] = new Arg($value); | ||
} | ||
$node->args = $newArgs; | ||
return $node; | ||
} | ||
} |