mirror of
https://github.com/rectorphp/rector.git
synced 2025-01-19 06:18:07 +01:00
7d36c3b0b9
a80cf5292d
revert to working scoper 0.14
45 lines
1.3 KiB
PHP
45 lines
1.3 KiB
PHP
<?php
|
|
|
|
declare (strict_types=1);
|
|
namespace Rector\PhpSpecToPHPUnit;
|
|
|
|
use PhpParser\Node\Expr\Array_;
|
|
use PhpParser\Node\Scalar\String_;
|
|
use PhpParser\Node\Stmt\Class_;
|
|
use PhpParser\Node\Stmt\ClassMethod;
|
|
use PhpParser\Node\Stmt\Return_;
|
|
final class MatchersManipulator
|
|
{
|
|
/**
|
|
* @return string[]
|
|
*/
|
|
public function resolveMatcherNamesFromClass(\PhpParser\Node\Stmt\Class_ $class) : array
|
|
{
|
|
$classMethod = $class->getMethod('getMatchers');
|
|
if (!$classMethod instanceof \PhpParser\Node\Stmt\ClassMethod) {
|
|
return [];
|
|
}
|
|
if (!isset($classMethod->stmts[0])) {
|
|
return [];
|
|
}
|
|
if (!$classMethod->stmts[0] instanceof \PhpParser\Node\Stmt\Return_) {
|
|
return [];
|
|
}
|
|
/** @var Return_ $return */
|
|
$return = $classMethod->stmts[0];
|
|
if (!$return->expr instanceof \PhpParser\Node\Expr\Array_) {
|
|
return [];
|
|
}
|
|
$keys = [];
|
|
foreach ($return->expr->items as $arrayItem) {
|
|
if ($arrayItem === null) {
|
|
continue;
|
|
}
|
|
if ($arrayItem->key instanceof \PhpParser\Node\Scalar\String_) {
|
|
$keys[] = $arrayItem->key->value;
|
|
}
|
|
}
|
|
return $keys;
|
|
}
|
|
}
|