mirror of
https://github.com/rectorphp/rector.git
synced 2025-02-19 15:45:43 +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;
|
||||
|
||||
use PhpParser\Node\Name;
|
||||
use PhpParser\Node\Stmt\Class_;
|
||||
use PhpParser\Node\Stmt\ClassLike;
|
||||
use PhpParser\Node\Stmt\Interface_;
|
||||
@ -105,12 +106,9 @@ final class SmartClassReflector
|
||||
}
|
||||
|
||||
if ($classLikeNode instanceof Interface_) {
|
||||
$types = [];
|
||||
foreach ($classLikeNode->extends as $interface) {
|
||||
$types[] = $interface->toString();
|
||||
}
|
||||
|
||||
return $types;
|
||||
return array_map(function (Name $interface): string {
|
||||
return $interface->toString();
|
||||
}, $classLikeNode->extends);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -106,14 +106,9 @@ final class ClassLikeAnalyzer
|
||||
*/
|
||||
private function resolveImplementsTypes(Class_ $classNode): array
|
||||
{
|
||||
$types = [];
|
||||
|
||||
$interfaces = $classNode->implements;
|
||||
foreach ($interfaces as $interface) {
|
||||
return array_map(function (Name $interface): string {
|
||||
/** @var FullyQualified $interface */
|
||||
$types[] = $interface->toString();
|
||||
}
|
||||
|
||||
return $types;
|
||||
return $interface->toString();
|
||||
}, $classNode->implements);
|
||||
}
|
||||
}
|
||||
|
@ -77,11 +77,9 @@ final class ExceptionAnnotationRector extends AbstractRector
|
||||
/** @var Generic[] $tags */
|
||||
$tags = $this->docBlockAnalyzer->getTagsByName($classMethodNode, $annotation);
|
||||
|
||||
$methodCallExpressions = [];
|
||||
|
||||
foreach ($tags as $tag) {
|
||||
$methodCallExpressions[] = $this->createMethodCallExpressionFromTag($tag, $method);
|
||||
}
|
||||
$methodCallExpressions = array_map(function (Generic $tag) use ($method): Expression {
|
||||
return $this->createMethodCallExpressionFromTag($tag, $method);
|
||||
}, $tags);
|
||||
|
||||
$classMethodNode->stmts = array_merge($methodCallExpressions, $classMethodNode->stmts);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user