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

View File

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

View File

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