mirror of
https://github.com/rectorphp/rector.git
synced 2025-02-24 03:35:01 +01:00
Make easier to add new assertions to SpecificMethodCountRector
This commit is contained in:
parent
aa50903b38
commit
afb27b1900
@ -33,16 +33,21 @@ use Rector\Rector\AbstractRector;
|
||||
*/
|
||||
final class SpecificMethodCountRector extends AbstractRector
|
||||
{
|
||||
/**
|
||||
* @var string[]
|
||||
*/
|
||||
private $renameMethodsMap = [
|
||||
'assertSame' => 'assertCount',
|
||||
'assertNotSame' => 'assertNotCount',
|
||||
'assertEquals' => 'assertCount',
|
||||
'assertNotEquals' => 'assertNotCount',
|
||||
];
|
||||
|
||||
/**
|
||||
* @var MethodCallAnalyzer
|
||||
*/
|
||||
private $methodCallAnalyzer;
|
||||
|
||||
/**
|
||||
* @var string|null
|
||||
*/
|
||||
private $activeFuncCallName;
|
||||
|
||||
public function __construct(MethodCallAnalyzer $methodCallAnalyzer)
|
||||
{
|
||||
$this->methodCallAnalyzer = $methodCallAnalyzer;
|
||||
@ -50,8 +55,6 @@ final class SpecificMethodCountRector extends AbstractRector
|
||||
|
||||
public function isCandidate(Node $node): bool
|
||||
{
|
||||
$this->activeFuncCallName = null;
|
||||
|
||||
if (! $this->methodCallAnalyzer->isTypesAndMethods(
|
||||
$node,
|
||||
['PHPUnit\Framework\TestCase', 'PHPUnit_Framework_TestCase'],
|
||||
@ -76,7 +79,9 @@ final class SpecificMethodCountRector extends AbstractRector
|
||||
|
||||
$coutableMethod = $secondArgumentValue->name->toString();
|
||||
|
||||
return $coutableMethod === 'count' || $coutableMethod === 'sizeof';
|
||||
return in_array($coutableMethod, [
|
||||
'count', 'sizeof',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -86,13 +91,7 @@ final class SpecificMethodCountRector extends AbstractRector
|
||||
{
|
||||
$oldMethodName = $methodCallNode->name->toString();
|
||||
|
||||
if ($oldMethodName === 'assertEquals' || $oldMethodName === 'assertSame') {
|
||||
/** @var string $trueMethodName */
|
||||
$methodCallNode->name = new Identifier('assertCount');
|
||||
} elseif ($oldMethodName === 'assertNotEquals' || $oldMethodName === 'assertNotSame') {
|
||||
/** @var string $falseMethodName */
|
||||
$methodCallNode->name = new Identifier('assertNotCount');
|
||||
}
|
||||
$methodCallNode->name = new Identifier($this->renameMethodsMap[$oldMethodName]);
|
||||
|
||||
/** @var FuncCall $secondArgument */
|
||||
$secondArgument = $methodCallNode->args[1]->value;
|
||||
|
Loading…
x
Reference in New Issue
Block a user