Use array_map to simplify some code

This commit is contained in:
Gabriel Caruso 2018-01-03 06:00:29 -02:00
parent 34c909dbc5
commit 71c0a2b049
3 changed files with 10 additions and 19 deletions

View File

@ -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;
} }
} }

View File

@ -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;
} }
} }

View File

@ -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);