[Symfony] add the other method as well

This commit is contained in:
TomasVotruba 2017-09-01 16:57:07 +02:00
parent b0d3984ae0
commit 9899eab6c5
4 changed files with 22 additions and 8 deletions

View File

@ -7,19 +7,25 @@ use PhpParser\Node\Expr\StaticCall;
final class MethodCallAnalyzer
{
public function isStaticMethodCallTypeAndMethod(Node $node, string $type, string $method): bool
/**
* @param string[] $methodNames
*/
public function isStaticMethodCallTypeAndMethods(Node $node, string $type, array $methodNames): bool
{
if (! $this->isStaticMethodCallType($node, $type)) {
return false;
}
/** @var StaticCall $node */
$methodName = (string) $node->name;
if ($methodName !== $method) {
return false;
$currentMethodName = (string) $node->name;
foreach ($methodNames as $methodName) {
if ($currentMethodName === $methodName) {
return true;
}
}
return true;
return false;
}
private function isStaticMethodCallType(Node $node, string $type): bool

View File

@ -22,7 +22,11 @@ use Rector\Rector\AbstractRector;
*/
final class VarDumperTestTraitMethodArgsRector extends AbstractRector
{
const TRAIT_NAME = 'VarDumperTestTrait';
/**
* @var string
*/
private const TRAIT_NAME = 'VarDumperTestTrait';
/**
* @var MethodCallAnalyzer
*/
@ -45,9 +49,9 @@ final class VarDumperTestTraitMethodArgsRector extends AbstractRector
public function isCandidate(Node $node): bool
{
if (! $this->methodCallAnalyzer->isStaticMethodCallTypeAndMethod($node,self::TRAIT_NAME,'assertDumpEquals')) {
if (! $this->methodCallAnalyzer->isStaticMethodCallTypeAndMethods($node,self::TRAIT_NAME, ['assertDumpEquals', 'assertDumpMatchesFormat'])) {
return false;
}
}
/** @var StaticCall $node */
if (count($node->args) <= 2) {

View File

@ -1,3 +1,5 @@
<?php declare(strict_types=1);
VarDumperTestTrait::assertDumpEquals($dump, $data, null, 'Some message');
VarDumperTestTrait::assertDumpMatchesFormat($dump, $format, null, 'Some message');

View File

@ -1,3 +1,5 @@
<?php declare(strict_types=1);
VarDumperTestTrait::assertDumpEquals($dump, $data, 'Some message');
VarDumperTestTrait::assertDumpMatchesFormat($dump, $format, 'Some message');