mirror of
https://github.com/rectorphp/rector.git
synced 2025-02-21 09:42:45 +01:00
Use array_map to simplify some code
This commit is contained in:
parent
34c909dbc5
commit
71c0a2b049
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace Rector\BetterReflection\Reflector;
|
namespace Rector\BetterReflection\Reflector;
|
||||||
|
|
||||||
|
use PhpParser\Node\Name;
|
||||||
use PhpParser\Node\Stmt\Class_;
|
use PhpParser\Node\Stmt\Class_;
|
||||||
use PhpParser\Node\Stmt\ClassLike;
|
use PhpParser\Node\Stmt\ClassLike;
|
||||||
use PhpParser\Node\Stmt\Interface_;
|
use PhpParser\Node\Stmt\Interface_;
|
||||||
@ -105,12 +106,9 @@ final class SmartClassReflector
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($classLikeNode instanceof Interface_) {
|
if ($classLikeNode instanceof Interface_) {
|
||||||
$types = [];
|
return array_map(function (Name $interface): string {
|
||||||
foreach ($classLikeNode->extends as $interface) {
|
return $interface->toString();
|
||||||
$types[] = $interface->toString();
|
}, $classLikeNode->extends);
|
||||||
}
|
|
||||||
|
|
||||||
return $types;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -106,14 +106,9 @@ final class ClassLikeAnalyzer
|
|||||||
*/
|
*/
|
||||||
private function resolveImplementsTypes(Class_ $classNode): array
|
private function resolveImplementsTypes(Class_ $classNode): array
|
||||||
{
|
{
|
||||||
$types = [];
|
return array_map(function (Name $interface): string {
|
||||||
|
|
||||||
$interfaces = $classNode->implements;
|
|
||||||
foreach ($interfaces as $interface) {
|
|
||||||
/** @var FullyQualified $interface */
|
/** @var FullyQualified $interface */
|
||||||
$types[] = $interface->toString();
|
return $interface->toString();
|
||||||
}
|
}, $classNode->implements);
|
||||||
|
|
||||||
return $types;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -77,11 +77,9 @@ final class ExceptionAnnotationRector extends AbstractRector
|
|||||||
/** @var Generic[] $tags */
|
/** @var Generic[] $tags */
|
||||||
$tags = $this->docBlockAnalyzer->getTagsByName($classMethodNode, $annotation);
|
$tags = $this->docBlockAnalyzer->getTagsByName($classMethodNode, $annotation);
|
||||||
|
|
||||||
$methodCallExpressions = [];
|
$methodCallExpressions = array_map(function (Generic $tag) use ($method): Expression {
|
||||||
|
return $this->createMethodCallExpressionFromTag($tag, $method);
|
||||||
foreach ($tags as $tag) {
|
}, $tags);
|
||||||
$methodCallExpressions[] = $this->createMethodCallExpressionFromTag($tag, $method);
|
|
||||||
}
|
|
||||||
|
|
||||||
$classMethodNode->stmts = array_merge($methodCallExpressions, $classMethodNode->stmts);
|
$classMethodNode->stmts = array_merge($methodCallExpressions, $classMethodNode->stmts);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user