diff --git a/phpcs.xml.dist b/phpcs.xml.dist
index 1a7b86bed..1bb47d7b2 100644
--- a/phpcs.xml.dist
+++ b/phpcs.xml.dist
@@ -19,6 +19,16 @@
+
+
+
+
+
+
+
+
+
+
diff --git a/src/BetterReflection.php b/src/BetterReflection.php
index 93c20c666..fae1d1309 100644
--- a/src/BetterReflection.php
+++ b/src/BetterReflection.php
@@ -86,9 +86,7 @@ public function phpParser(): Parser
public function astLocator(): AstLocator
{
return $this->astLocator
- ?? $this->astLocator = new AstLocator($this->phpParser(), function (): FunctionReflector {
- return $this->functionReflector();
- });
+ ?? $this->astLocator = new AstLocator($this->phpParser(), fn (): FunctionReflector => $this->functionReflector());
}
public function findReflectionsOnLine(): FindReflectionOnLine
diff --git a/src/Reflection/Adapter/ReflectionClass.php b/src/Reflection/Adapter/ReflectionClass.php
index fb220da80..931531748 100644
--- a/src/Reflection/Adapter/ReflectionClass.php
+++ b/src/Reflection/Adapter/ReflectionClass.php
@@ -166,9 +166,7 @@ public function getMethod($name)
*/
public function getMethods($filter = null)
{
- return array_map(static function (BetterReflectionMethod $method): ReflectionMethod {
- return new ReflectionMethod($method);
- }, $this->betterReflectionClass->getMethods($filter));
+ return array_map(static fn (BetterReflectionMethod $method): ReflectionMethod => new ReflectionMethod($method), $this->betterReflectionClass->getMethods($filter));
}
/**
@@ -198,9 +196,7 @@ public function getProperty($name)
*/
public function getProperties($filter = null)
{
- return array_values(array_map(static function (BetterReflectionProperty $property): ReflectionProperty {
- return new ReflectionProperty($property);
- }, $this->betterReflectionClass->getProperties($filter)));
+ return array_values(array_map(static fn (BetterReflectionProperty $property): ReflectionProperty => new ReflectionProperty($property), $this->betterReflectionClass->getProperties($filter)));
}
/**
@@ -216,9 +212,7 @@ public function hasConstant($name)
*/
public function getConstants(?int $filter = null)
{
- return array_map(static function (BetterReflectionClassConstant $betterConstant) {
- return $betterConstant->getValue();
- }, $this->filterBetterReflectionClassConstants($filter));
+ return array_map(static fn (BetterReflectionClassConstant $betterConstant) => $betterConstant->getValue(), $this->filterBetterReflectionClassConstants($filter));
}
/**
@@ -247,9 +241,7 @@ public function getReflectionConstant($name)
*/
public function getReflectionConstants(?int $filter = null)
{
- return array_values(array_map(static function (BetterReflectionClassConstant $betterConstant): ReflectionClassConstant {
- return new ReflectionClassConstant($betterConstant);
- }, $this->filterBetterReflectionClassConstants($filter)));
+ return array_values(array_map(static fn (BetterReflectionClassConstant $betterConstant): ReflectionClassConstant => new ReflectionClassConstant($betterConstant), $this->filterBetterReflectionClassConstants($filter)));
}
/**
@@ -262,9 +254,7 @@ private function filterBetterReflectionClassConstants(?int $filter): array
if ($filter !== null) {
$reflectionConstants = array_filter(
$this->betterReflectionClass->getReflectionConstants(),
- static function (BetterReflectionClassConstant $betterConstant) use ($filter): bool {
- return (bool) ($betterConstant->getModifiers() & $filter);
- },
+ static fn (BetterReflectionClassConstant $betterConstant): bool => (bool) ($betterConstant->getModifiers() & $filter),
);
}
@@ -310,15 +300,11 @@ public function getTraits()
$traits = $this->betterReflectionClass->getTraits();
/** @var array $traitNames */
- $traitNames = array_map(static function (BetterReflectionClass $trait): string {
- return $trait->getName();
- }, $traits);
+ $traitNames = array_map(static fn (BetterReflectionClass $trait): string => $trait->getName(), $traits);
return array_combine(
$traitNames,
- array_map(static function (BetterReflectionClass $trait): self {
- return new self($trait);
- }, $traits),
+ array_map(static fn (BetterReflectionClass $trait): self => new self($trait), $traits),
);
}
@@ -431,9 +417,7 @@ public function isSubclassOf($class)
{
$realParentClassNames = $this->betterReflectionClass->getParentClassNames();
- $parentClassNames = array_combine(array_map(static function (string $parentClassName): string {
- return strtolower($parentClassName);
- }, $realParentClassNames), $realParentClassNames);
+ $parentClassNames = array_combine(array_map(static fn (string $parentClassName): string => strtolower($parentClassName), $realParentClassNames), $realParentClassNames);
$lowercasedClass = strtolower($class);
@@ -525,9 +509,7 @@ public function implementsInterface($interface)
{
$realInterfaceNames = $this->betterReflectionClass->getInterfaceNames();
- $interfaceNames = array_combine(array_map(static function (string $interfaceName): string {
- return strtolower($interfaceName);
- }, $realInterfaceNames), $realInterfaceNames);
+ $interfaceNames = array_combine(array_map(static fn (string $interfaceName): string => strtolower($interfaceName), $realInterfaceNames), $realInterfaceNames);
$realInterfaceName = $interfaceNames[strtolower($interface)] ?? $interface;
diff --git a/src/Reflection/Adapter/ReflectionObject.php b/src/Reflection/Adapter/ReflectionObject.php
index fa4550c5e..555a3f51a 100644
--- a/src/Reflection/Adapter/ReflectionObject.php
+++ b/src/Reflection/Adapter/ReflectionObject.php
@@ -136,13 +136,9 @@ public function getMethod($name)
private function getMethodRealName(string $name): string
{
- $realMethodNames = array_map(static function (BetterReflectionMethod $method): string {
- return $method->getName();
- }, $this->betterReflectionObject->getMethods());
+ $realMethodNames = array_map(static fn (BetterReflectionMethod $method): string => $method->getName(), $this->betterReflectionObject->getMethods());
- $methodNames = array_combine(array_map(static function (string $methodName): string {
- return strtolower($methodName);
- }, $realMethodNames), $realMethodNames);
+ $methodNames = array_combine(array_map(static fn (string $methodName): string => strtolower($methodName), $realMethodNames), $realMethodNames);
return $methodNames[strtolower($name)] ?? $name;
}
@@ -189,9 +185,7 @@ public function getProperty($name)
*/
public function getProperties($filter = null)
{
- return array_values(array_map(static function (BetterReflectionProperty $property): ReflectionProperty {
- return new ReflectionProperty($property);
- }, $this->betterReflectionObject->getProperties()));
+ return array_values(array_map(static fn (BetterReflectionProperty $property): ReflectionProperty => new ReflectionProperty($property), $this->betterReflectionObject->getProperties()));
}
/**
@@ -212,16 +206,12 @@ public function getConstants(?int $filter = null)
if ($filter !== null) {
$reflectionConstants = array_filter(
$reflectionConstants,
- static function (BetterReflectionClassConstant $betterConstant) use ($filter): bool {
- return (bool) ($betterConstant->getModifiers() & $filter);
- },
+ static fn (BetterReflectionClassConstant $betterConstant): bool => (bool) ($betterConstant->getModifiers() & $filter),
);
}
return array_map(
- static function (BetterReflectionClassConstant $betterConstant) {
- return $betterConstant->getValue();
- },
+ static fn (BetterReflectionClassConstant $betterConstant) => $betterConstant->getValue(),
$reflectionConstants,
);
}
@@ -254,9 +244,7 @@ public function getReflectionConstant($name)
public function getReflectionConstants(?int $filter = null)
{
return array_values(array_map(
- static function (BetterReflectionClassConstant $betterConstant): ReflectionClassConstant {
- return new ReflectionClassConstant($betterConstant);
- },
+ static fn (BetterReflectionClassConstant $betterConstant): ReflectionClassConstant => new ReflectionClassConstant($betterConstant),
$this->betterReflectionObject->getReflectionConstants(),
));
}
@@ -300,15 +288,11 @@ public function getTraits()
$traits = $this->betterReflectionObject->getTraits();
/** @var array $traitNames */
- $traitNames = array_map(static function (BetterReflectionClass $trait): string {
- return $trait->getName();
- }, $traits);
+ $traitNames = array_map(static fn (BetterReflectionClass $trait): string => $trait->getName(), $traits);
return array_combine(
$traitNames,
- array_map(static function (BetterReflectionClass $trait): ReflectionClass {
- return new ReflectionClass($trait);
- }, $traits),
+ array_map(static fn (BetterReflectionClass $trait): ReflectionClass => new ReflectionClass($trait), $traits),
);
}
@@ -421,9 +405,7 @@ public function isSubclassOf($class)
{
$realParentClassNames = $this->betterReflectionObject->getParentClassNames();
- $parentClassNames = array_combine(array_map(static function (string $parentClassName): string {
- return strtolower($parentClassName);
- }, $realParentClassNames), $realParentClassNames);
+ $parentClassNames = array_combine(array_map(static fn (string $parentClassName): string => strtolower($parentClassName), $realParentClassNames), $realParentClassNames);
$lowercasedClass = strtolower($class);
@@ -515,9 +497,7 @@ public function implementsInterface($interface)
{
$realInterfaceNames = $this->betterReflectionObject->getInterfaceNames();
- $interfaceNames = array_combine(array_map(static function (string $interfaceName): string {
- return strtolower($interfaceName);
- }, $realInterfaceNames), $realInterfaceNames);
+ $interfaceNames = array_combine(array_map(static fn (string $interfaceName): string => strtolower($interfaceName), $realInterfaceNames), $realInterfaceNames);
$realInterfaceName = $interfaceNames[strtolower($interface)] ?? $interface;
diff --git a/src/Reflection/Adapter/ReflectionUnionType.php b/src/Reflection/Adapter/ReflectionUnionType.php
index c5990f0b9..0fe7efad4 100644
--- a/src/Reflection/Adapter/ReflectionUnionType.php
+++ b/src/Reflection/Adapter/ReflectionUnionType.php
@@ -21,9 +21,7 @@ public function __construct(private BetterReflectionUnionType $betterReflectionT
*/
public function getTypes(): array
{
- return array_map(static function (BetterReflectionType $type) {
- return ReflectionType::fromTypeOrNull($type);
- }, $this->betterReflectionType->getTypes());
+ return array_map(static fn (BetterReflectionType $type) => ReflectionType::fromTypeOrNull($type), $this->betterReflectionType->getTypes());
}
public function __toString(): string
diff --git a/src/Reflection/ReflectionClass.php b/src/Reflection/ReflectionClass.php
index b292116c4..1fccffbc2 100644
--- a/src/Reflection/ReflectionClass.php
+++ b/src/Reflection/ReflectionClass.php
@@ -241,16 +241,14 @@ private function createMethodsFromTrait(ReflectionMethod $method): array
assert($methodAst instanceof ClassMethod);
$methodHash = $this->methodHash($method->getImplementingClass()->getName(), $method->getName());
- $createMethod = function (?string $aliasMethodName) use ($method, $methodAst): ReflectionMethod {
- return ReflectionMethod::createFromNode(
- $this->reflector,
- $methodAst,
- $method->getDeclaringClass()->getDeclaringNamespaceAst(),
- $method->getDeclaringClass(),
- $this,
- $aliasMethodName,
- );
- };
+ $createMethod = fn (?string $aliasMethodName): ReflectionMethod => ReflectionMethod::createFromNode(
+ $this->reflector,
+ $methodAst,
+ $method->getDeclaringClass()->getDeclaringNamespaceAst(),
+ $method->getDeclaringClass(),
+ $this,
+ $aliasMethodName,
+ );
$methods = [];
foreach ($traitAliases as $aliasMethodName => $traitAliasDefinition) {
@@ -276,9 +274,7 @@ private function getParentMethods(): array
return array_merge(
[],
...array_map(
- static function (ReflectionClass $ancestor): array {
- return $ancestor->getMethods();
- },
+ static fn (ReflectionClass $ancestor): array => $ancestor->getMethods(),
array_filter([$this->getParentClass()]),
),
);
@@ -296,9 +292,7 @@ function (ReflectionClass $trait): array {
return array_merge(
[],
...array_map(
- function (ReflectionMethod $method): array {
- return $this->createMethodsFromTrait($method);
- },
+ fn (ReflectionMethod $method): array => $this->createMethodsFromTrait($method),
$trait->getMethods(),
),
);
@@ -316,9 +310,7 @@ private function getMethodsFromInterfaces(): array
return array_merge(
[],
...array_map(
- static function (ReflectionClass $ancestor): array {
- return $ancestor->getMethods();
- },
+ static fn (ReflectionClass $ancestor): array => $ancestor->getMethods(),
array_values($this->getInterfaces()),
),
);
@@ -420,9 +412,7 @@ public function getMethods(?int $filter = null): array
return array_values(
array_filter(
$this->getMethodsIndexedByName(),
- static function (ReflectionMethod $method) use ($filter): bool {
- return (bool) ($filter & $method->getModifiers());
- },
+ static fn (ReflectionMethod $method): bool => (bool) ($filter & $method->getModifiers()),
),
);
}
@@ -439,15 +429,13 @@ public function getImmediateMethods(?int $filter = null): array
{
/** @var ReflectionMethod[] $methods */
$methods = array_map(
- function (ClassMethod $methodNode): ReflectionMethod {
- return ReflectionMethod::createFromNode(
- $this->reflector,
- $methodNode,
- $this->declaringNamespace,
- $this,
- $this,
- );
- },
+ fn (ClassMethod $methodNode): ReflectionMethod => ReflectionMethod::createFromNode(
+ $this->reflector,
+ $methodNode,
+ $this->declaringNamespace,
+ $this,
+ $this,
+ ),
$this->node->getMethods(),
);
@@ -503,9 +491,7 @@ public function hasMethod(string $methodName): bool
*/
public function getImmediateConstants(): array
{
- return array_map(static function (ReflectionClassConstant $classConstant) {
- return $classConstant->getValue();
- }, $this->getImmediateReflectionConstants());
+ return array_map(static fn (ReflectionClassConstant $classConstant) => $classConstant->getValue(), $this->getImmediateReflectionConstants());
}
/**
@@ -516,9 +502,7 @@ public function getImmediateConstants(): array
*/
public function getConstants(): array
{
- return array_map(static function (ReflectionClassConstant $classConstant) {
- return $classConstant->getValue();
- }, $this->getReflectionConstants());
+ return array_map(static fn (ReflectionClassConstant $classConstant) => $classConstant->getValue(), $this->getReflectionConstants());
}
/**
@@ -583,18 +567,14 @@ function (ConstNode $constNode): array {
},
array_filter(
$this->node->stmts,
- static function (Node\Stmt $stmt): bool {
- return $stmt instanceof ConstNode;
- },
+ static fn (Node\Stmt $stmt): bool => $stmt instanceof ConstNode,
),
),
);
return $this->cachedReflectionConstants = array_combine(
array_map(
- static function (ReflectionClassConstant $constant): string {
- return $constant->getName();
- },
+ static fn (ReflectionClassConstant $constant): string => $constant->getName(),
$constants,
),
$constants,
@@ -618,17 +598,13 @@ public function getReflectionConstants(): array
static function (ReflectionClass $ancestor): array {
return array_filter(
array_values($ancestor->getReflectionConstants()),
- static function (ReflectionClassConstant $classConstant): bool {
- return ! $classConstant->isPrivate();
- },
+ static fn (ReflectionClassConstant $classConstant): bool => ! $classConstant->isPrivate(),
);
},
array_filter([$this->getParentClass()]),
),
...array_map(
- static function (ReflectionClass $interface): array {
- return array_values($interface->getReflectionConstants());
- },
+ static fn (ReflectionClass $interface): array => array_values($interface->getReflectionConstants()),
array_values($this->getInterfaces()),
),
);
@@ -655,9 +631,7 @@ static function (ReflectionClass $interface): array {
*/
public function getConstructor(): ReflectionMethod
{
- $constructors = array_values(array_filter($this->getMethods(), static function (ReflectionMethod $method): bool {
- return $method->isConstructor();
- }));
+ $constructors = array_values(array_filter($this->getMethods(), static fn (ReflectionMethod $method): bool => $method->isConstructor()));
if (! isset($constructors[0])) {
throw new OutOfBoundsException('Could not find method: __construct');
@@ -705,9 +679,7 @@ public function getImmediateProperties(?int $filter = null): array
return array_filter(
$this->cachedImmediateProperties,
- static function (ReflectionProperty $property) use ($filter): bool {
- return (bool) ($filter & $property->getModifiers());
- },
+ static fn (ReflectionProperty $property): bool => (bool) ($filter & $property->getModifiers()),
);
}
@@ -736,25 +708,21 @@ public function getProperties(?int $filter = null): array
static function (ReflectionClass $ancestor) use ($filter): array {
return array_filter(
$ancestor->getProperties($filter),
- static function (ReflectionProperty $property): bool {
- return ! $property->isPrivate();
- },
+ static fn (ReflectionProperty $property): bool => ! $property->isPrivate(),
);
},
array_filter([$this->getParentClass()]),
),
...array_map(
function (ReflectionClass $trait) use ($filter) {
- return array_map(function (ReflectionProperty $property) use ($trait): ReflectionProperty {
- return ReflectionProperty::createFromNode(
- $this->reflector,
- $property->getAst(),
- $property->getPositionInAst(),
- $trait->declaringNamespace,
- $property->getDeclaringClass(),
- $this,
- );
- }, $trait->getProperties($filter));
+ return array_map(fn (ReflectionProperty $property): ReflectionProperty => ReflectionProperty::createFromNode(
+ $this->reflector,
+ $property->getAst(),
+ $property->getPositionInAst(),
+ $trait->declaringNamespace,
+ $property->getDeclaringClass(),
+ $this,
+ ), $trait->getProperties($filter));
},
$this->getTraits(),
),
@@ -769,9 +737,7 @@ function (ReflectionClass $trait) use ($filter) {
return array_filter(
$this->cachedProperties,
- static function (ReflectionProperty $property) use ($filter): bool {
- return (bool) ($filter & $property->getModifiers());
- },
+ static fn (ReflectionProperty $property): bool => (bool) ($filter & $property->getModifiers()),
);
}
@@ -805,12 +771,8 @@ public function hasProperty(string $name): bool
public function getDefaultProperties(): array
{
return array_map(
- static function (ReflectionProperty $property) {
- return $property->getDefaultValue();
- },
- array_filter($this->getProperties(), static function (ReflectionProperty $property): bool {
- return $property->isDefault();
- }),
+ static fn (ReflectionProperty $property) => $property->getDefaultValue(),
+ array_filter($this->getProperties(), static fn (ReflectionProperty $property): bool => $property->isDefault()),
);
}
@@ -883,9 +845,7 @@ public function getParentClass(): ?ReflectionClass
*/
public function getParentClassNames(): array
{
- return array_map(static function (self $parentClass): string {
- return $parentClass->getName();
- }, array_slice(array_reverse($this->getInheritanceClassHierarchy()), 1));
+ return array_map(static fn (self $parentClass): string => $parentClass->getName(), array_slice(array_reverse($this->getInheritanceClassHierarchy()), 1));
}
public function getDocComment(): string
@@ -968,18 +928,12 @@ public function isInterface(): bool
public function getTraits(): array
{
return array_map(
- function (Node\Name $importedTrait): ReflectionClass {
- return $this->reflectClassForNamedNode($importedTrait);
- },
+ fn (Node\Name $importedTrait): ReflectionClass => $this->reflectClassForNamedNode($importedTrait),
array_merge(
[],
...array_map(
- static function (TraitUse $traitUse): array {
- return $traitUse->traits;
- },
- array_filter($this->node->stmts, static function (Node $node): bool {
- return $node instanceof TraitUse;
- }),
+ static fn (TraitUse $traitUse): array => $traitUse->traits,
+ array_filter($this->node->stmts, static fn (Node $node): bool => $node instanceof TraitUse),
),
),
);
@@ -1006,9 +960,7 @@ private function reflectClassForNamedNode(Node\Name $node): self
public function getTraitNames(): array
{
return array_map(
- static function (ReflectionClass $trait): string {
- return $trait->getName();
- },
+ static fn (ReflectionClass $trait): string => $trait->getName(),
$this->getTraits(),
);
}
@@ -1074,9 +1026,7 @@ private function parseTraitUsages(): void
}
/** @var Node\Stmt\TraitUse[] $traitUsages */
- $traitUsages = array_filter($this->node->stmts, static function (Node $node): bool {
- return $node instanceof TraitUse;
- });
+ $traitUsages = array_filter($this->node->stmts, static fn (Node $node): bool => $node instanceof TraitUse);
$this->cachedTraitAliases = [];
$this->cachedTraitPrecedences = [];
@@ -1133,9 +1083,7 @@ private function methodHash(string $className, string $methodName): string
public function getInterfaces(): array
{
return array_merge(...array_map(
- static function (self $reflectionClass): array {
- return $reflectionClass->getCurrentClassImplementedInterfacesIndexedByName();
- },
+ static fn (self $reflectionClass): array => $reflectionClass->getCurrentClassImplementedInterfacesIndexedByName(),
$this->getInheritanceClassHierarchy(),
));
}
@@ -1158,15 +1106,11 @@ public function getImmediateInterfaces(): array
return array_combine(
array_map(
- static function (Node\Name $interfaceName): string {
- return $interfaceName->toString();
- },
+ static fn (Node\Name $interfaceName): string => $interfaceName->toString(),
$nodes,
),
array_map(
- function (Node\Name $interfaceName): ReflectionClass {
- return $this->reflectClassForNamedNode($interfaceName);
- },
+ fn (Node\Name $interfaceName): ReflectionClass => $this->reflectClassForNamedNode($interfaceName),
$nodes,
),
);
@@ -1182,9 +1126,7 @@ function (Node\Name $interfaceName): ReflectionClass {
public function getInterfaceNames(): array
{
return array_values(array_map(
- static function (self $interface): string {
- return $interface->getName();
- },
+ static fn (self $interface): string => $interface->getName(),
$this->getInterfaces(),
));
}
@@ -1213,9 +1155,7 @@ public function isSubclassOf(string $className): bool
return in_array(
ltrim($className, '\\'),
array_map(
- static function (self $reflectionClass): string {
- return $reflectionClass->getName();
- },
+ static fn (self $reflectionClass): string => $reflectionClass->getName(),
array_slice(array_reverse($this->getInheritanceClassHierarchy()), 1),
),
true,
@@ -1299,11 +1239,9 @@ private function getCurrentClassImplementedInterfacesIndexedByName(): array
return array_merge(
[],
...array_map(
- function (Node\Name $interfaceName): array {
- return $this
+ fn (Node\Name $interfaceName): array => $this
->reflectClassForNamedNode($interfaceName)
- ->getInterfacesHierarchy();
- },
+ ->getInterfacesHierarchy(),
$node->implements,
),
);
@@ -1346,11 +1284,9 @@ private function getInterfacesHierarchy(): array
return array_merge(
[$this->getName() => $this],
...array_map(
- function (Node\Name $interfaceName): array {
- return $this
+ fn (Node\Name $interfaceName): array => $this
->reflectClassForNamedNode($interfaceName)
- ->getInterfacesHierarchy();
- },
+ ->getInterfacesHierarchy(),
$node->extends,
),
);
@@ -1529,9 +1465,7 @@ public function removeProperty(string $propertyName): bool
continue;
}
- $propertyNames = array_map(static function (Node\Stmt\PropertyProperty $propertyProperty): string {
- return $propertyProperty->name->toLowerString();
- }, $stmt->props);
+ $propertyNames = array_map(static fn (Node\Stmt\PropertyProperty $propertyProperty): string => $propertyProperty->name->toLowerString(), $stmt->props);
if (in_array($lowerName, $propertyNames, true)) {
$this->cachedProperties = null;
diff --git a/src/Reflection/ReflectionFunction.php b/src/Reflection/ReflectionFunction.php
index ccfd0c401..4d0f7238f 100644
--- a/src/Reflection/ReflectionFunction.php
+++ b/src/Reflection/ReflectionFunction.php
@@ -95,9 +95,7 @@ public function getClosure(): Closure
$this->assertFunctionExist($functionName);
- return static function (...$args) use ($functionName) {
- return $functionName(...$args);
- };
+ return static fn (...$args) => $functionName(...$args);
}
/**
diff --git a/src/Reflection/ReflectionFunctionAbstract.php b/src/Reflection/ReflectionFunctionAbstract.php
index b2c350b52..1927856b5 100644
--- a/src/Reflection/ReflectionFunctionAbstract.php
+++ b/src/Reflection/ReflectionFunctionAbstract.php
@@ -181,9 +181,7 @@ public function getNumberOfRequiredParameters(): int
{
return count(array_filter(
$this->getParameters(),
- static function (ReflectionParameter $p): bool {
- return ! $p->isOptional();
- },
+ static fn (ReflectionParameter $p): bool => ! $p->isOptional(),
));
}
@@ -533,9 +531,7 @@ public function setBodyFromAst(array $nodes): void
{
// This slightly confusing code simply type-checks the $sourceLocators
// array by unpacking them and splatting them in the closure.
- $validator = static function (Node ...$node): array {
- return $node;
- };
+ $validator = static fn (Node ...$node): array => $node;
$this->getNode()->stmts = $validator(...$nodes);
}
diff --git a/src/Reflection/ReflectionMethod.php b/src/Reflection/ReflectionMethod.php
index 003ad7c18..348cd8052 100644
--- a/src/Reflection/ReflectionMethod.php
+++ b/src/Reflection/ReflectionMethod.php
@@ -283,16 +283,12 @@ public function getClosure(?object $object = null): Closure
if ($this->isStatic()) {
$this->assertClassExist($declaringClassName);
- return function (...$args) {
- return $this->callStaticMethod($args);
- };
+ return fn (...$args) => $this->callStaticMethod($args);
}
$instance = $this->assertObject($object);
- return function (...$args) use ($instance) {
- return $this->callObjectMethod($instance, $args);
- };
+ return fn (...$args) => $this->callObjectMethod($instance, $args);
}
/**
@@ -332,9 +328,7 @@ private function callStaticMethod(array $args): mixed
{
$declaringClassName = $this->getDeclaringClass()->getName();
- $closure = Closure::bind(function (string $declaringClassName, string $methodName, array $methodArgs) {
- return $declaringClassName::{$methodName}(...$methodArgs);
- }, null, $declaringClassName);
+ $closure = Closure::bind(fn (string $declaringClassName, string $methodName, array $methodArgs) => $declaringClassName::{$methodName}(...$methodArgs), null, $declaringClassName);
Assert::notFalse($closure);
@@ -346,9 +340,7 @@ private function callStaticMethod(array $args): mixed
*/
private function callObjectMethod(object $object, array $args): mixed
{
- $closure = Closure::bind(function ($object, string $methodName, array $methodArgs) {
- return $object->{$methodName}(...$methodArgs);
- }, $object, $this->getDeclaringClass()->getName());
+ $closure = Closure::bind(fn ($object, string $methodName, array $methodArgs) => $object->{$methodName}(...$methodArgs), $object, $this->getDeclaringClass()->getName());
Assert::notFalse($closure);
diff --git a/src/Reflection/ReflectionProperty.php b/src/Reflection/ReflectionProperty.php
index ec6e26574..65e69407b 100644
--- a/src/Reflection/ReflectionProperty.php
+++ b/src/Reflection/ReflectionProperty.php
@@ -315,9 +315,7 @@ public function getValue(?object $object = null): mixed
if ($this->isStatic()) {
$this->assertClassExist($declaringClassName);
- $closure = Closure::bind(function (string $declaringClassName, string $propertyName) {
- return $declaringClassName::${$propertyName};
- }, null, $declaringClassName);
+ $closure = Closure::bind(fn (string $declaringClassName, string $propertyName) => $declaringClassName::${$propertyName}, null, $declaringClassName);
Assert::notFalse($closure);
@@ -326,9 +324,7 @@ public function getValue(?object $object = null): mixed
$instance = $this->assertObject($object);
- $closure = Closure::bind(function (object $instance, string $propertyName) {
- return $instance->{$propertyName};
- }, $instance, $declaringClassName);
+ $closure = Closure::bind(fn (object $instance, string $propertyName) => $instance->{$propertyName}, $instance, $declaringClassName);
Assert::notFalse($closure);
diff --git a/src/Reflection/ReflectionUnionType.php b/src/Reflection/ReflectionUnionType.php
index 342d4f362..e19db7d78 100644
--- a/src/Reflection/ReflectionUnionType.php
+++ b/src/Reflection/ReflectionUnionType.php
@@ -17,9 +17,7 @@ class ReflectionUnionType extends ReflectionType
public function __construct(UnionType $type, bool $allowsNull)
{
parent::__construct($allowsNull);
- $this->types = array_map(static function ($type): ReflectionType {
- return ReflectionType::createFromTypeAndReflector($type);
- }, $type->types);
+ $this->types = array_map(static fn ($type): ReflectionType => ReflectionType::createFromTypeAndReflector($type), $type->types);
}
/**
@@ -32,8 +30,6 @@ public function getTypes(): array
public function __toString(): string
{
- return implode('|', array_map(static function (ReflectionType $type): string {
- return (string) $type;
- }, $this->types));
+ return implode('|', array_map(static fn (ReflectionType $type): string => (string) $type, $this->types));
}
}
diff --git a/src/Reflection/StringCast/ReflectionClassStringCast.php b/src/Reflection/StringCast/ReflectionClassStringCast.php
index 400cae85e..1b3d29035 100644
--- a/src/Reflection/StringCast/ReflectionClassStringCast.php
+++ b/src/Reflection/StringCast/ReflectionClassStringCast.php
@@ -136,9 +136,7 @@ private static function constantsToString(array $constants): string
return '';
}
- return self::itemsToString(array_map(static function (ReflectionClassConstant $constantReflection): string {
- return trim(ReflectionClassConstantStringCast::toString($constantReflection));
- }, $constants));
+ return self::itemsToString(array_map(static fn (ReflectionClassConstant $constantReflection): string => trim(ReflectionClassConstantStringCast::toString($constantReflection)), $constants));
}
/**
@@ -150,9 +148,7 @@ private static function propertiesToString(array $properties): string
return '';
}
- return self::itemsToString(array_map(static function (ReflectionProperty $propertyReflection): string {
- return ReflectionPropertyStringCast::toString($propertyReflection);
- }, $properties));
+ return self::itemsToString(array_map(static fn (ReflectionProperty $propertyReflection): string => ReflectionPropertyStringCast::toString($propertyReflection), $properties));
}
/**
@@ -164,9 +160,7 @@ private static function methodsToString(ReflectionClass $classReflection, array
return '';
}
- return self::itemsToString(array_map(static function (ReflectionMethod $method) use ($classReflection): string {
- return ReflectionMethodStringCast::toString($method, $classReflection);
- }, $methods), $emptyLinesAmongItems);
+ return self::itemsToString(array_map(static fn (ReflectionMethod $method): string => ReflectionMethodStringCast::toString($method, $classReflection), $methods), $emptyLinesAmongItems);
}
/**
@@ -189,9 +183,7 @@ private static function indent(): string
*/
private static function getStaticProperties(ReflectionClass $classReflection): array
{
- return array_filter($classReflection->getProperties(), static function (ReflectionProperty $propertyReflection): bool {
- return $propertyReflection->isStatic();
- });
+ return array_filter($classReflection->getProperties(), static fn (ReflectionProperty $propertyReflection): bool => $propertyReflection->isStatic());
}
/**
@@ -199,9 +191,7 @@ private static function getStaticProperties(ReflectionClass $classReflection): a
*/
private static function getStaticMethods(ReflectionClass $classReflection): array
{
- return array_filter($classReflection->getMethods(), static function (ReflectionMethod $methodReflection): bool {
- return $methodReflection->isStatic();
- });
+ return array_filter($classReflection->getMethods(), static fn (ReflectionMethod $methodReflection): bool => $methodReflection->isStatic());
}
/**
@@ -209,9 +199,7 @@ private static function getStaticMethods(ReflectionClass $classReflection): arra
*/
private static function getDefaultProperties(ReflectionClass $classReflection): array
{
- return array_filter($classReflection->getProperties(), static function (ReflectionProperty $propertyReflection): bool {
- return ! $propertyReflection->isStatic() && $propertyReflection->isDefault();
- });
+ return array_filter($classReflection->getProperties(), static fn (ReflectionProperty $propertyReflection): bool => ! $propertyReflection->isStatic() && $propertyReflection->isDefault());
}
/**
@@ -219,9 +207,7 @@ private static function getDefaultProperties(ReflectionClass $classReflection):
*/
private static function getDynamicProperties(ReflectionClass $classReflection): array
{
- return array_filter($classReflection->getProperties(), static function (ReflectionProperty $propertyReflection): bool {
- return ! $propertyReflection->isStatic() && ! $propertyReflection->isDefault();
- });
+ return array_filter($classReflection->getProperties(), static fn (ReflectionProperty $propertyReflection): bool => ! $propertyReflection->isStatic() && ! $propertyReflection->isDefault());
}
/**
@@ -229,8 +215,6 @@ private static function getDynamicProperties(ReflectionClass $classReflection):
*/
private static function getMethods(ReflectionClass $classReflection): array
{
- return array_filter($classReflection->getMethods(), static function (ReflectionMethod $methodReflection): bool {
- return ! $methodReflection->isStatic();
- });
+ return array_filter($classReflection->getMethods(), static fn (ReflectionMethod $methodReflection): bool => ! $methodReflection->isStatic());
}
}
diff --git a/src/Reflection/StringCast/ReflectionFunctionStringCast.php b/src/Reflection/StringCast/ReflectionFunctionStringCast.php
index fbd0dae48..5dbef2eda 100644
--- a/src/Reflection/StringCast/ReflectionFunctionStringCast.php
+++ b/src/Reflection/StringCast/ReflectionFunctionStringCast.php
@@ -50,8 +50,6 @@ private static function fileAndLinesToString(ReflectionFunction $functionReflect
private static function parametersToString(ReflectionFunction $functionReflection): string
{
- return array_reduce($functionReflection->getParameters(), static function (string $string, ReflectionParameter $parameterReflection): string {
- return $string . "\n " . ReflectionParameterStringCast::toString($parameterReflection);
- }, '');
+ return array_reduce($functionReflection->getParameters(), static fn (string $string, ReflectionParameter $parameterReflection): string => $string . "\n " . ReflectionParameterStringCast::toString($parameterReflection), '');
}
}
diff --git a/src/Reflection/StringCast/ReflectionMethodStringCast.php b/src/Reflection/StringCast/ReflectionMethodStringCast.php
index 9b94c344e..46619a540 100644
--- a/src/Reflection/StringCast/ReflectionMethodStringCast.php
+++ b/src/Reflection/StringCast/ReflectionMethodStringCast.php
@@ -111,8 +111,6 @@ private static function fileAndLinesToString(ReflectionMethod $methodReflection)
private static function parametersToString(ReflectionMethod $methodReflection): string
{
- return array_reduce($methodReflection->getParameters(), static function (string $string, ReflectionParameter $parameterReflection): string {
- return $string . "\n " . ReflectionParameterStringCast::toString($parameterReflection);
- }, '');
+ return array_reduce($methodReflection->getParameters(), static fn (string $string, ReflectionParameter $parameterReflection): string => $string . "\n " . ReflectionParameterStringCast::toString($parameterReflection), '');
}
}
diff --git a/src/SourceLocator/SourceStubber/AggregateSourceStubber.php b/src/SourceLocator/SourceStubber/AggregateSourceStubber.php
index b3ee59f01..90c22e6ea 100644
--- a/src/SourceLocator/SourceStubber/AggregateSourceStubber.php
+++ b/src/SourceLocator/SourceStubber/AggregateSourceStubber.php
@@ -45,8 +45,6 @@ public function generateFunctionStub(string $functionName): ?StubData
public function generateConstantStub(string $constantName): ?StubData
{
- return array_reduce($this->sourceStubbers, static function (?StubData $stubData, SourceStubber $sourceStubber) use ($constantName): ?StubData {
- return $stubData ?? $sourceStubber->generateConstantStub($constantName);
- }, null);
+ return array_reduce($this->sourceStubbers, static fn (?StubData $stubData, SourceStubber $sourceStubber): ?StubData => $stubData ?? $sourceStubber->generateConstantStub($constantName), null);
}
}
diff --git a/src/SourceLocator/Type/AggregateSourceLocator.php b/src/SourceLocator/Type/AggregateSourceLocator.php
index 5cfb84333..3996c5122 100644
--- a/src/SourceLocator/Type/AggregateSourceLocator.php
+++ b/src/SourceLocator/Type/AggregateSourceLocator.php
@@ -24,9 +24,7 @@ public function __construct(array $sourceLocators = [])
{
// This slightly confusing code simply type-checks the $sourceLocators
// array by unpacking them and splatting them in the closure.
- $validator = static function (SourceLocator ...$sourceLocator): array {
- return $sourceLocator;
- };
+ $validator = static fn (SourceLocator ...$sourceLocator): array => $sourceLocator;
$this->sourceLocators = $validator(...$sourceLocators);
}
@@ -50,9 +48,7 @@ public function locateIdentifiersByType(Reflector $reflector, IdentifierType $id
{
return array_merge(
[],
- ...array_map(static function (SourceLocator $sourceLocator) use ($reflector, $identifierType) {
- return $sourceLocator->locateIdentifiersByType($reflector, $identifierType);
- }, $this->sourceLocators),
+ ...array_map(static fn (SourceLocator $sourceLocator) => $sourceLocator->locateIdentifiersByType($reflector, $identifierType), $this->sourceLocators),
);
}
}
diff --git a/src/SourceLocator/Type/AnonymousClassObjectSourceLocator.php b/src/SourceLocator/Type/AnonymousClassObjectSourceLocator.php
index a7b55f1d1..59b033d8a 100644
--- a/src/SourceLocator/Type/AnonymousClassObjectSourceLocator.php
+++ b/src/SourceLocator/Type/AnonymousClassObjectSourceLocator.php
@@ -112,9 +112,7 @@ public function enterNode(Node $node)
public function getAnonymousClassNode(): ?Class_
{
/** @var Class_[] $anonymousClassNodesOnSameLine */
- $anonymousClassNodesOnSameLine = array_values(array_filter($this->anonymousClassNodes, function (Class_ $node): bool {
- return $node->getLine() === $this->startLine;
- }));
+ $anonymousClassNodesOnSameLine = array_values(array_filter($this->anonymousClassNodes, fn (Class_ $node): bool => $node->getLine() === $this->startLine));
if (! $anonymousClassNodesOnSameLine) {
return null;
diff --git a/src/SourceLocator/Type/AutoloadSourceLocator.php b/src/SourceLocator/Type/AutoloadSourceLocator.php
index 4beca8894..446f678bf 100644
--- a/src/SourceLocator/Type/AutoloadSourceLocator.php
+++ b/src/SourceLocator/Type/AutoloadSourceLocator.php
@@ -173,9 +173,7 @@ static function () use ($className): ?string {
private function silenceErrors(): void
{
- set_error_handler(static function (): bool {
- return true;
- });
+ set_error_handler(static fn (): bool => true);
}
/**
diff --git a/src/SourceLocator/Type/ClosureSourceLocator.php b/src/SourceLocator/Type/ClosureSourceLocator.php
index 94a9ee183..5f6cd97a8 100644
--- a/src/SourceLocator/Type/ClosureSourceLocator.php
+++ b/src/SourceLocator/Type/ClosureSourceLocator.php
@@ -132,9 +132,7 @@ public function leaveNode(Node $node)
public function getClosureNodes(): ?array
{
/** @var (Node|null)[][] $closureNodesDataOnSameLine */
- $closureNodesDataOnSameLine = array_values(array_filter($this->closureNodes, function (array $nodes): bool {
- return $nodes[0]->getLine() === $this->startLine;
- }));
+ $closureNodesDataOnSameLine = array_values(array_filter($this->closureNodes, fn (array $nodes): bool => $nodes[0]->getLine() === $this->startLine));
if (! $closureNodesDataOnSameLine) {
return null;
diff --git a/src/SourceLocator/Type/Composer/Factory/MakeLocatorForComposerJson.php b/src/SourceLocator/Type/Composer/Factory/MakeLocatorForComposerJson.php
index f2795bab0..555f06b1e 100644
--- a/src/SourceLocator/Type/Composer/Factory/MakeLocatorForComposerJson.php
+++ b/src/SourceLocator/Type/Composer/Factory/MakeLocatorForComposerJson.php
@@ -71,9 +71,7 @@ public function __invoke(string $installationPath, Locator $astLocator): SourceL
),
new DirectoriesSourceLocator($classMapDirectories, $astLocator),
],
- ...array_map(static function (string $file) use ($astLocator): array {
- return [new SingleFileSourceLocator($file, $astLocator)];
- }, array_merge($classMapFiles, $filePaths)),
+ ...array_map(static fn (string $file): array => [new SingleFileSourceLocator($file, $astLocator)], array_merge($classMapFiles, $filePaths)),
));
}
@@ -84,9 +82,7 @@ public function __invoke(string $installationPath, Locator $astLocator): SourceL
*/
private function packageToPsr4AutoloadNamespaces(array $package): array
{
- return array_map(static function ($namespacePaths): array {
- return (array) $namespacePaths;
- }, $package['autoload']['psr-4'] ?? []);
+ return array_map(static fn ($namespacePaths): array => (array) $namespacePaths, $package['autoload']['psr-4'] ?? []);
}
/**
@@ -96,9 +92,7 @@ private function packageToPsr4AutoloadNamespaces(array $package): array
*/
private function packageToPsr0AutoloadNamespaces(array $package): array
{
- return array_map(static function ($namespacePaths): array {
- return (array) $namespacePaths;
- }, $package['autoload']['psr-0'] ?? []);
+ return array_map(static fn ($namespacePaths): array => (array) $namespacePaths, $package['autoload']['psr-0'] ?? []);
}
/**
@@ -128,9 +122,7 @@ private function packageToFilePaths(array $package): array
*/
private function prefixWithInstallationPath(array $paths, string $trimmedInstallationPath): array
{
- return array_map(function (array $paths) use ($trimmedInstallationPath): array {
- return $this->prefixPaths($paths, $trimmedInstallationPath);
- }, $paths);
+ return array_map(fn (array $paths): array => $this->prefixPaths($paths, $trimmedInstallationPath), $paths);
}
/**
@@ -140,8 +132,6 @@ private function prefixWithInstallationPath(array $paths, string $trimmedInstall
*/
private function prefixPaths(array $paths, string $prefix): array
{
- return array_map(static function (string $path) use ($prefix) {
- return $prefix . $path;
- }, $paths);
+ return array_map(static fn (string $path) => $prefix . $path, $paths);
}
}
diff --git a/src/SourceLocator/Type/Composer/Factory/MakeLocatorForComposerJsonAndInstalledJson.php b/src/SourceLocator/Type/Composer/Factory/MakeLocatorForComposerJsonAndInstalledJson.php
index a5403448f..82fa62a08 100644
--- a/src/SourceLocator/Type/Composer/Factory/MakeLocatorForComposerJsonAndInstalledJson.php
+++ b/src/SourceLocator/Type/Composer/Factory/MakeLocatorForComposerJsonAndInstalledJson.php
@@ -77,23 +77,19 @@ public function __invoke(string $installationPath, Locator $astLocator): SourceL
$classMapPaths = array_merge(
$this->prefixPaths($this->packageToClassMapPaths($composer), $realInstallationPath . '/'),
- ...array_map(function (array $package) use ($realInstallationPath, $vendorDir): array {
- return $this->prefixPaths(
- $this->packageToClassMapPaths($package),
- $this->packagePrefixPath($realInstallationPath, $package, $vendorDir),
- );
- }, $installed),
+ ...array_map(fn (array $package): array => $this->prefixPaths(
+ $this->packageToClassMapPaths($package),
+ $this->packagePrefixPath($realInstallationPath, $package, $vendorDir),
+ ), $installed),
);
$classMapFiles = array_filter($classMapPaths, 'is_file');
$classMapDirectories = array_filter($classMapPaths, 'is_dir');
$filePaths = array_merge(
$this->prefixPaths($this->packageToFilePaths($composer), $realInstallationPath . '/'),
- ...array_map(function (array $package) use ($realInstallationPath, $vendorDir): array {
- return $this->prefixPaths(
- $this->packageToFilePaths($package),
- $this->packagePrefixPath($realInstallationPath, $package, $vendorDir),
- );
- }, $installed),
+ ...array_map(fn (array $package): array => $this->prefixPaths(
+ $this->packageToFilePaths($package),
+ $this->packagePrefixPath($realInstallationPath, $package, $vendorDir),
+ ), $installed),
);
return new AggregateSourceLocator(array_merge(
@@ -101,36 +97,30 @@ public function __invoke(string $installationPath, Locator $astLocator): SourceL
new PsrAutoloaderLocator(
Psr4Mapping::fromArrayMappings(array_merge_recursive(
$this->prefixWithInstallationPath($this->packageToPsr4AutoloadNamespaces($composer), $realInstallationPath),
- ...array_map(function (array $package) use ($realInstallationPath, $vendorDir): array {
- return $this->prefixWithPackagePath(
- $this->packageToPsr4AutoloadNamespaces($package),
- $realInstallationPath,
- $package,
- $vendorDir,
- );
- }, $installed),
+ ...array_map(fn (array $package): array => $this->prefixWithPackagePath(
+ $this->packageToPsr4AutoloadNamespaces($package),
+ $realInstallationPath,
+ $package,
+ $vendorDir,
+ ), $installed),
)),
$astLocator,
),
new PsrAutoloaderLocator(
Psr0Mapping::fromArrayMappings(array_merge_recursive(
$this->prefixWithInstallationPath($this->packageToPsr0AutoloadNamespaces($composer), $realInstallationPath),
- ...array_map(function (array $package) use ($realInstallationPath, $vendorDir): array {
- return $this->prefixWithPackagePath(
- $this->packageToPsr0AutoloadNamespaces($package),
- $realInstallationPath,
- $package,
- $vendorDir,
- );
- }, $installed),
+ ...array_map(fn (array $package): array => $this->prefixWithPackagePath(
+ $this->packageToPsr0AutoloadNamespaces($package),
+ $realInstallationPath,
+ $package,
+ $vendorDir,
+ ), $installed),
)),
$astLocator,
),
new DirectoriesSourceLocator($classMapDirectories, $astLocator),
],
- ...array_map(static function (string $file) use ($astLocator): array {
- return [new SingleFileSourceLocator($file, $astLocator)];
- }, array_merge($classMapFiles, $filePaths)),
+ ...array_map(static fn (string $file): array => [new SingleFileSourceLocator($file, $astLocator)], array_merge($classMapFiles, $filePaths)),
));
}
@@ -141,9 +131,7 @@ public function __invoke(string $installationPath, Locator $astLocator): SourceL
*/
private function packageToPsr4AutoloadNamespaces(array $package): array
{
- return array_map(static function ($namespacePaths): array {
- return (array) $namespacePaths;
- }, $package['autoload']['psr-4'] ?? []);
+ return array_map(static fn ($namespacePaths): array => (array) $namespacePaths, $package['autoload']['psr-4'] ?? []);
}
/**
@@ -153,9 +141,7 @@ private function packageToPsr4AutoloadNamespaces(array $package): array
*/
private function packageToPsr0AutoloadNamespaces(array $package): array
{
- return array_map(static function ($namespacePaths): array {
- return (array) $namespacePaths;
- }, $package['autoload']['psr-0'] ?? []);
+ return array_map(static fn ($namespacePaths): array => (array) $namespacePaths, $package['autoload']['psr-0'] ?? []);
}
/**
@@ -196,9 +182,7 @@ private function prefixWithPackagePath(array $paths, string $trimmedInstallation
{
$prefix = $this->packagePrefixPath($trimmedInstallationPath, $package, $vendorDir);
- return array_map(function (array $paths) use ($prefix): array {
- return $this->prefixPaths($paths, $prefix);
- }, $paths);
+ return array_map(fn (array $paths): array => $this->prefixPaths($paths, $prefix), $paths);
}
/**
@@ -208,9 +192,7 @@ private function prefixWithPackagePath(array $paths, string $trimmedInstallation
*/
private function prefixWithInstallationPath(array $paths, string $trimmedInstallationPath): array
{
- return array_map(function (array $paths) use ($trimmedInstallationPath): array {
- return $this->prefixPaths($paths, $trimmedInstallationPath . '/');
- }, $paths);
+ return array_map(fn (array $paths): array => $this->prefixPaths($paths, $trimmedInstallationPath . '/'), $paths);
}
/**
@@ -220,8 +202,6 @@ private function prefixWithInstallationPath(array $paths, string $trimmedInstall
*/
private function prefixPaths(array $paths, string $prefix): array
{
- return array_map(static function (string $path) use ($prefix) {
- return $prefix . $path;
- }, $paths);
+ return array_map(static fn (string $path) => $prefix . $path, $paths);
}
}
diff --git a/src/SourceLocator/Type/Composer/Factory/MakeLocatorForInstalledJson.php b/src/SourceLocator/Type/Composer/Factory/MakeLocatorForInstalledJson.php
index c7e3c3c0c..c6bbb92a7 100644
--- a/src/SourceLocator/Type/Composer/Factory/MakeLocatorForInstalledJson.php
+++ b/src/SourceLocator/Type/Composer/Factory/MakeLocatorForInstalledJson.php
@@ -73,23 +73,19 @@ public function __invoke(string $installationPath, Locator $astLocator): SourceL
$classMapPaths = array_merge(
[],
- ...array_map(function (array $package) use ($realInstallationPath, $vendorDir): array {
- return $this->prefixPaths(
- $this->packageToClassMapPaths($package),
- $this->packagePrefixPath($realInstallationPath, $package, $vendorDir),
- );
- }, $installed),
+ ...array_map(fn (array $package): array => $this->prefixPaths(
+ $this->packageToClassMapPaths($package),
+ $this->packagePrefixPath($realInstallationPath, $package, $vendorDir),
+ ), $installed),
);
$classMapFiles = array_filter($classMapPaths, 'is_file');
$classMapDirectories = array_filter($classMapPaths, 'is_dir');
$filePaths = array_merge(
[],
- ...array_map(function (array $package) use ($realInstallationPath, $vendorDir): array {
- return $this->prefixPaths(
- $this->packageToFilePaths($package),
- $this->packagePrefixPath($realInstallationPath, $package, $vendorDir),
- );
- }, $installed),
+ ...array_map(fn (array $package): array => $this->prefixPaths(
+ $this->packageToFilePaths($package),
+ $this->packagePrefixPath($realInstallationPath, $package, $vendorDir),
+ ), $installed),
);
return new AggregateSourceLocator(array_merge(
@@ -97,36 +93,30 @@ public function __invoke(string $installationPath, Locator $astLocator): SourceL
new PsrAutoloaderLocator(
Psr4Mapping::fromArrayMappings(array_merge_recursive(
[],
- ...array_map(function (array $package) use ($realInstallationPath, $vendorDir): array {
- return $this->prefixWithPackagePath(
- $this->packageToPsr4AutoloadNamespaces($package),
- $realInstallationPath,
- $package,
- $vendorDir,
- );
- }, $installed),
+ ...array_map(fn (array $package): array => $this->prefixWithPackagePath(
+ $this->packageToPsr4AutoloadNamespaces($package),
+ $realInstallationPath,
+ $package,
+ $vendorDir,
+ ), $installed),
)),
$astLocator,
),
new PsrAutoloaderLocator(
Psr0Mapping::fromArrayMappings(array_merge_recursive(
[],
- ...array_map(function (array $package) use ($realInstallationPath, $vendorDir): array {
- return $this->prefixWithPackagePath(
- $this->packageToPsr0AutoloadNamespaces($package),
- $realInstallationPath,
- $package,
- $vendorDir,
- );
- }, $installed),
+ ...array_map(fn (array $package): array => $this->prefixWithPackagePath(
+ $this->packageToPsr0AutoloadNamespaces($package),
+ $realInstallationPath,
+ $package,
+ $vendorDir,
+ ), $installed),
)),
$astLocator,
),
new DirectoriesSourceLocator($classMapDirectories, $astLocator),
],
- ...array_map(static function (string $file) use ($astLocator): array {
- return [new SingleFileSourceLocator($file, $astLocator)];
- }, array_merge($classMapFiles, $filePaths)),
+ ...array_map(static fn (string $file): array => [new SingleFileSourceLocator($file, $astLocator)], array_merge($classMapFiles, $filePaths)),
));
}
@@ -137,9 +127,7 @@ public function __invoke(string $installationPath, Locator $astLocator): SourceL
*/
private function packageToPsr4AutoloadNamespaces(array $package): array
{
- return array_map(static function ($namespacePaths): array {
- return (array) $namespacePaths;
- }, $package['autoload']['psr-4'] ?? []);
+ return array_map(static fn ($namespacePaths): array => (array) $namespacePaths, $package['autoload']['psr-4'] ?? []);
}
/**
@@ -149,9 +137,7 @@ private function packageToPsr4AutoloadNamespaces(array $package): array
*/
private function packageToPsr0AutoloadNamespaces(array $package): array
{
- return array_map(static function ($namespacePaths): array {
- return (array) $namespacePaths;
- }, $package['autoload']['psr-0'] ?? []);
+ return array_map(static fn ($namespacePaths): array => (array) $namespacePaths, $package['autoload']['psr-0'] ?? []);
}
/**
@@ -192,9 +178,7 @@ private function prefixWithPackagePath(array $paths, string $trimmedInstallation
{
$prefix = $this->packagePrefixPath($trimmedInstallationPath, $package, $vendorDir);
- return array_map(function (array $paths) use ($prefix): array {
- return $this->prefixPaths($paths, $prefix);
- }, $paths);
+ return array_map(fn (array $paths): array => $this->prefixPaths($paths, $prefix), $paths);
}
/**
@@ -204,8 +188,6 @@ private function prefixWithPackagePath(array $paths, string $trimmedInstallation
*/
private function prefixPaths(array $paths, string $prefix): array
{
- return array_map(static function (string $path) use ($prefix) {
- return $prefix . $path;
- }, $paths);
+ return array_map(static fn (string $path) => $prefix . $path, $paths);
}
}
diff --git a/src/SourceLocator/Type/Composer/Psr/Psr0Mapping.php b/src/SourceLocator/Type/Composer/Psr/Psr0Mapping.php
index f483817df..1abd0d644 100644
--- a/src/SourceLocator/Type/Composer/Psr/Psr0Mapping.php
+++ b/src/SourceLocator/Type/Composer/Psr/Psr0Mapping.php
@@ -34,9 +34,7 @@ public static function fromArrayMappings(array $mappings): self
$instance->mappings = array_map(
static function (array $directories): array {
- return array_map(static function (string $directory): string {
- return rtrim($directory, '/');
- }, $directories);
+ return array_map(static fn (string $directory): string => rtrim($directory, '/'), $directories);
},
$mappings,
);
@@ -56,9 +54,7 @@ public function resolvePossibleFilePaths(Identifier $identifier): array
foreach ($this->mappings as $prefix => $paths) {
if (strpos($className, $prefix) === 0) {
return array_map(
- static function (string $path) use ($className): string {
- return rtrim($path, '/') . '/' . str_replace(['\\', '_'], '/', $className) . '.php';
- },
+ static fn (string $path): string => rtrim($path, '/') . '/' . str_replace(['\\', '_'], '/', $className) . '.php',
$paths,
);
}
diff --git a/src/SourceLocator/Type/Composer/Psr/Psr4Mapping.php b/src/SourceLocator/Type/Composer/Psr/Psr4Mapping.php
index 461953b82..9054b9b44 100644
--- a/src/SourceLocator/Type/Composer/Psr/Psr4Mapping.php
+++ b/src/SourceLocator/Type/Composer/Psr/Psr4Mapping.php
@@ -41,9 +41,7 @@ public static function fromArrayMappings(array $mappings): self
$instance->mappings = array_map(
static function (array $directories): array {
- return array_map(static function (string $directory): string {
- return rtrim($directory, '/');
- }, $directories);
+ return array_map(static fn (string $directory): string => rtrim($directory, '/'), $directories);
},
$mappings,
);
@@ -70,9 +68,7 @@ public function resolvePossibleFilePaths(Identifier $identifier): array
return [];
}
- return array_map(static function (string $path) use ($subPath): string {
- return rtrim($path, '/') . '/' . $subPath . '.php';
- }, $paths);
+ return array_map(static fn (string $path): string => rtrim($path, '/') . '/' . $subPath . '.php', $paths);
}, $matchingPrefixes, array_keys($matchingPrefixes)),
)));
}
@@ -82,9 +78,7 @@ private function matchingPrefixes(string $className): array
{
return array_filter(
$this->mappings,
- static function (string $prefix) use ($className): bool {
- return strpos($className, $prefix) === 0;
- },
+ static fn (string $prefix): bool => strpos($className, $prefix) === 0,
ARRAY_FILTER_USE_KEY,
);
}
diff --git a/src/TypesFinder/PhpDocumentor/NamespaceNodeToReflectionTypeContext.php b/src/TypesFinder/PhpDocumentor/NamespaceNodeToReflectionTypeContext.php
index ab053f9d3..8744922ca 100644
--- a/src/TypesFinder/PhpDocumentor/NamespaceNodeToReflectionTypeContext.php
+++ b/src/TypesFinder/PhpDocumentor/NamespaceNodeToReflectionTypeContext.php
@@ -67,12 +67,10 @@ private function classAlikeUses(Namespace_ $namespace): array
{
return array_filter(
$namespace->stmts,
- static function (Node $node): bool {
- return (
+ static fn (Node $node): bool => (
$node instanceof Use_
|| $node instanceof GroupUse
- ) && in_array($node->type, [Use_::TYPE_UNKNOWN, Use_::TYPE_NORMAL], true);
- },
+ ) && in_array($node->type, [Use_::TYPE_UNKNOWN, Use_::TYPE_NORMAL], true),
);
}
}
diff --git a/test/unit/Reflection/Adapter/ReflectionClassConstantTest.php b/test/unit/Reflection/Adapter/ReflectionClassConstantTest.php
index e85433c1c..d82127f05 100644
--- a/test/unit/Reflection/Adapter/ReflectionClassConstantTest.php
+++ b/test/unit/Reflection/Adapter/ReflectionClassConstantTest.php
@@ -24,9 +24,7 @@ public function coreReflectionMethodNamesProvider(): array
{
$methods = get_class_methods(CoreReflectionClassConstant::class);
- return array_combine($methods, array_map(static function (string $i): array {
- return [$i];
- }, $methods));
+ return array_combine($methods, array_map(static fn (string $i): array => [$i], $methods));
}
/**
diff --git a/test/unit/Reflection/Adapter/ReflectionClassTest.php b/test/unit/Reflection/Adapter/ReflectionClassTest.php
index 37bc667af..12afaf405 100644
--- a/test/unit/Reflection/Adapter/ReflectionClassTest.php
+++ b/test/unit/Reflection/Adapter/ReflectionClassTest.php
@@ -34,9 +34,7 @@ public function coreReflectionMethodNamesProvider(): array
{
$methods = get_class_methods(CoreReflectionClass::class);
- return array_combine($methods, array_map(static function (string $i): array {
- return [$i];
- }, $methods));
+ return array_combine($methods, array_map(static fn (string $i): array => [$i], $methods));
}
/**
diff --git a/test/unit/Reflection/Adapter/ReflectionFunctionTest.php b/test/unit/Reflection/Adapter/ReflectionFunctionTest.php
index 713dd58b8..4df4f39f5 100644
--- a/test/unit/Reflection/Adapter/ReflectionFunctionTest.php
+++ b/test/unit/Reflection/Adapter/ReflectionFunctionTest.php
@@ -29,9 +29,7 @@ public function coreReflectionMethodNamesProvider(): array
{
$methods = get_class_methods(CoreReflectionFunction::class);
- return array_combine($methods, array_map(static function (string $i): array {
- return [$i];
- }, $methods));
+ return array_combine($methods, array_map(static fn (string $i): array => [$i], $methods));
}
/**
diff --git a/test/unit/Reflection/Adapter/ReflectionMethodTest.php b/test/unit/Reflection/Adapter/ReflectionMethodTest.php
index b423f37a6..bb4f988f1 100644
--- a/test/unit/Reflection/Adapter/ReflectionMethodTest.php
+++ b/test/unit/Reflection/Adapter/ReflectionMethodTest.php
@@ -36,9 +36,7 @@ public function coreReflectionMethodNamesProvider(): array
{
$methods = get_class_methods(CoreReflectionMethod::class);
- return array_combine($methods, array_map(static function (string $i): array {
- return [$i];
- }, $methods));
+ return array_combine($methods, array_map(static fn (string $i): array => [$i], $methods));
}
/**
diff --git a/test/unit/Reflection/Adapter/ReflectionNamedTypeTest.php b/test/unit/Reflection/Adapter/ReflectionNamedTypeTest.php
index 4aa8ec3a2..2460084b1 100644
--- a/test/unit/Reflection/Adapter/ReflectionNamedTypeTest.php
+++ b/test/unit/Reflection/Adapter/ReflectionNamedTypeTest.php
@@ -23,9 +23,7 @@ public function coreReflectionTypeNamesProvider(): array
{
$methods = get_class_methods(CoreReflectionNamedType::class);
- return array_combine($methods, array_map(static function (string $i): array {
- return [$i];
- }, $methods));
+ return array_combine($methods, array_map(static fn (string $i): array => [$i], $methods));
}
/**
diff --git a/test/unit/Reflection/Adapter/ReflectionObjectTest.php b/test/unit/Reflection/Adapter/ReflectionObjectTest.php
index b6ca3c2ec..f48757ba1 100644
--- a/test/unit/Reflection/Adapter/ReflectionObjectTest.php
+++ b/test/unit/Reflection/Adapter/ReflectionObjectTest.php
@@ -34,9 +34,7 @@ public function coreReflectionMethodNamesProvider(): array
{
$methods = get_class_methods(CoreReflectionObject::class);
- return array_combine($methods, array_map(static function (string $i): array {
- return [$i];
- }, $methods));
+ return array_combine($methods, array_map(static fn (string $i): array => [$i], $methods));
}
/**
diff --git a/test/unit/Reflection/Adapter/ReflectionParameterTest.php b/test/unit/Reflection/Adapter/ReflectionParameterTest.php
index 981775581..840054448 100644
--- a/test/unit/Reflection/Adapter/ReflectionParameterTest.php
+++ b/test/unit/Reflection/Adapter/ReflectionParameterTest.php
@@ -27,9 +27,7 @@ public function coreReflectionParameterNamesProvider(): array
{
$methods = get_class_methods(CoreReflectionParameter::class);
- return array_combine($methods, array_map(static function (string $i): array {
- return [$i];
- }, $methods));
+ return array_combine($methods, array_map(static fn (string $i): array => [$i], $methods));
}
/**
diff --git a/test/unit/Reflection/Adapter/ReflectionPropertyTest.php b/test/unit/Reflection/Adapter/ReflectionPropertyTest.php
index 61a731ef8..7a5c13d0d 100644
--- a/test/unit/Reflection/Adapter/ReflectionPropertyTest.php
+++ b/test/unit/Reflection/Adapter/ReflectionPropertyTest.php
@@ -31,9 +31,7 @@ public function coreReflectionPropertyNamesProvider(): array
{
$methods = get_class_methods(CoreReflectionProperty::class);
- return array_combine($methods, array_map(static function (string $i): array {
- return [$i];
- }, $methods));
+ return array_combine($methods, array_map(static fn (string $i): array => [$i], $methods));
}
/**
diff --git a/test/unit/Reflection/Adapter/ReflectionTypeTest.php b/test/unit/Reflection/Adapter/ReflectionTypeTest.php
index 2ae51192f..6af75c7a0 100644
--- a/test/unit/Reflection/Adapter/ReflectionTypeTest.php
+++ b/test/unit/Reflection/Adapter/ReflectionTypeTest.php
@@ -23,9 +23,7 @@ public function coreReflectionTypeNamesProvider(): array
{
$methods = get_class_methods(CoreReflectionType::class);
- return array_combine($methods, array_map(static function (string $i): array {
- return [$i];
- }, $methods));
+ return array_combine($methods, array_map(static fn (string $i): array => [$i], $methods));
}
/**
diff --git a/test/unit/Reflection/ReflectionClassTest.php b/test/unit/Reflection/ReflectionClassTest.php
index a6a82e50c..3e094d806 100644
--- a/test/unit/Reflection/ReflectionClassTest.php
+++ b/test/unit/Reflection/ReflectionClassTest.php
@@ -269,9 +269,7 @@ public function testGetMethodsOrder(): void
$this->astLocator,
)))->reflect(MethodsOrder::class);
- $actualMethodNames = array_map(static function (ReflectionMethod $method): string {
- return $method->getName();
- }, $classInfo->getMethods());
+ $actualMethodNames = array_map(static fn (ReflectionMethod $method): string => $method->getName(), $classInfo->getMethods());
$expectedMethodNames = [
'f1',
@@ -1582,15 +1580,11 @@ public function testGetImmediateInterfacesDoesNotIncludeCurrentInterface(): void
));
$cInterfaces = array_map(
- static function (ReflectionClass $interface): string {
- return $interface->getShortName();
- },
+ static fn (ReflectionClass $interface): string => $interface->getShortName(),
$reflector->reflect(ClassWithInterfacesExtendingInterfaces\C::class)->getImmediateInterfaces(),
);
$dInterfaces = array_map(
- static function (ReflectionClass $interface): string {
- return $interface->getShortName();
- },
+ static fn (ReflectionClass $interface): string => $interface->getShortName(),
$reflector->reflect(ClassWithInterfacesExtendingInterfaces\D::class)->getImmediateInterfaces(),
);
diff --git a/test/unit/Reflection/ReflectionFunctionTest.php b/test/unit/Reflection/ReflectionFunctionTest.php
index 72cdcb984..9803cfd6e 100644
--- a/test/unit/Reflection/ReflectionFunctionTest.php
+++ b/test/unit/Reflection/ReflectionFunctionTest.php
@@ -119,18 +119,22 @@ public function testStaticCreationFromName(): void
public function testCreateFromClosure(): void
{
- $myClosure = static function () {
+ // phpcs:disable SlevomatCodingStandard.Functions.RequireArrowFunction
+ $myClosure = static function () {
return 5;
};
+ // phpcs:enable
$reflection = ReflectionFunction::createFromClosure($myClosure);
self::assertSame(ReflectionFunction::CLOSURE_NAME, $reflection->getShortName());
}
public function testCreateFromClosureCanReflectTypeHints(): void
{
- $myClosure = static function (stdClass $theParam): int {
+ // phpcs:disable SlevomatCodingStandard.Functions.RequireArrowFunction
+ $myClosure = static function (stdClass $theParam): int {
return 5;
};
+ // phpcs:enable
$reflection = ReflectionFunction::createFromClosure($myClosure);
$theParam = $reflection->getParameter('theParam')->getClass();
diff --git a/test/unit/SourceLocator/Ast/LocatorTest.php b/test/unit/SourceLocator/Ast/LocatorTest.php
index e9f89d2ff..bfc179c56 100644
--- a/test/unit/SourceLocator/Ast/LocatorTest.php
+++ b/test/unit/SourceLocator/Ast/LocatorTest.php
@@ -33,9 +33,7 @@ protected function setUp(): void
$betterReflection = BetterReflectionSingleton::instance();
- $this->locator = new Locator($betterReflection->phpParser(), static function () use ($betterReflection): FunctionReflector {
- return $betterReflection->functionReflector();
- });
+ $this->locator = new Locator($betterReflection->phpParser(), static fn (): FunctionReflector => $betterReflection->functionReflector());
}
private function getIdentifier(string $name, string $type): Identifier
diff --git a/test/unit/SourceLocator/Ast/Parser/MemoizingParserTest.php b/test/unit/SourceLocator/Ast/Parser/MemoizingParserTest.php
index 134e4f0b5..7ef5ba832 100644
--- a/test/unit/SourceLocator/Ast/Parser/MemoizingParserTest.php
+++ b/test/unit/SourceLocator/Ast/Parser/MemoizingParserTest.php
@@ -28,9 +28,7 @@ public function testParse(): void
$wrappedParser = $this->createMock(Parser::class);
$randomCodeStrings = array_unique(array_map(
- static function (): string {
- return uniqid('code', true);
- },
+ static fn (): string => uniqid('code', true),
range(0, 100),
));
@@ -39,9 +37,7 @@ static function (): string {
$wrappedParser
->expects(self::exactly($randomCodeStringsCount))
->method('parse')
- ->willReturnCallback(static function (): array {
- return [new Name('bool')];
- });
+ ->willReturnCallback(static fn (): array => [new Name('bool')]);
$parser = new MemoizingParser($wrappedParser);
@@ -55,9 +51,7 @@ static function (): string {
}
$nodeIdentifiers = array_map(
- static function (array $nodes): string {
- return spl_object_hash($nodes[0]);
- },
+ static fn (array $nodes): string => spl_object_hash($nodes[0]),
$producedNodes,
);
diff --git a/test/unit/SourceLocator/SourceStubber/PhpStormStubsSourceStubberTest.php b/test/unit/SourceLocator/SourceStubber/PhpStormStubsSourceStubberTest.php
index 1fbf72f71..80e2bffbf 100644
--- a/test/unit/SourceLocator/SourceStubber/PhpStormStubsSourceStubberTest.php
+++ b/test/unit/SourceLocator/SourceStubber/PhpStormStubsSourceStubberTest.php
@@ -78,9 +78,7 @@ public function internalClassesProvider(): array
);
return array_map(
- static function (string $className): array {
- return [$className];
- },
+ static fn (string $className): array => [$className],
array_filter(
$classNames,
static function (string $className): bool {
@@ -165,15 +163,11 @@ private function assertSameClassAttributes(CoreReflectionClass $original, Reflec
private function assertSameMethodAttributes(CoreReflectionMethod $original, ReflectionMethod $stubbed): void
{
$originalParameterNames = array_map(
- static function (CoreReflectionParameter $parameter): string {
- return $parameter->getDeclaringFunction()->getName() . '.' . $parameter->getName();
- },
+ static fn (CoreReflectionParameter $parameter): string => $parameter->getDeclaringFunction()->getName() . '.' . $parameter->getName(),
$original->getParameters(),
);
$stubParameterNames = array_map(
- static function (ReflectionParameter $parameter): string {
- return $parameter->getDeclaringFunction()->getName() . '.' . $parameter->getName();
- },
+ static fn (ReflectionParameter $parameter): string => $parameter->getDeclaringFunction()->getName() . '.' . $parameter->getName(),
$stubbed->getParameters(),
);
@@ -286,9 +280,7 @@ public function internalFunctionsProvider(): array
$functionNames = get_defined_functions()['internal'];
return array_map(
- static function (string $functionName): array {
- return [$functionName];
- },
+ static fn (string $functionName): array => [$functionName],
array_filter(
$functionNames,
static function (string $functionName): bool {
diff --git a/test/unit/SourceLocator/SourceStubber/ReflectionSourceStubberTest.php b/test/unit/SourceLocator/SourceStubber/ReflectionSourceStubberTest.php
index 70c92d113..c657fec4b 100644
--- a/test/unit/SourceLocator/SourceStubber/ReflectionSourceStubberTest.php
+++ b/test/unit/SourceLocator/SourceStubber/ReflectionSourceStubberTest.php
@@ -183,9 +183,7 @@ public function internalClassesProvider(): array
);
return array_map(
- static function (string $symbol): array {
- return [$symbol];
- },
+ static fn (string $symbol): array => [$symbol],
array_filter(
$allSymbols,
static function (string $symbol): bool {
@@ -263,15 +261,11 @@ private function assertSameClassAttributes(CoreReflectionClass $original, Reflec
private function assertSameMethodAttributes(CoreReflectionMethod $original, ReflectionMethod $stubbed): void
{
$originalParameterNames = array_map(
- static function (CoreReflectionParameter $parameter): string {
- return $parameter->getDeclaringFunction()->getName() . '.' . $parameter->getName();
- },
+ static fn (CoreReflectionParameter $parameter): string => $parameter->getDeclaringFunction()->getName() . '.' . $parameter->getName(),
$original->getParameters(),
);
$stubParameterNames = array_map(
- static function (ReflectionParameter $parameter): string {
- return $parameter->getDeclaringFunction()->getName() . '.' . $parameter->getName();
- },
+ static fn (ReflectionParameter $parameter): string => $parameter->getDeclaringFunction()->getName() . '.' . $parameter->getName(),
$stubbed->getParameters(),
);
@@ -339,9 +333,7 @@ public function internalFunctionsProvider(): array
$functionNames = get_defined_functions()['internal'];
return array_map(
- static function (string $functionName): array {
- return [$functionName];
- },
+ static fn (string $functionName): array => [$functionName],
array_filter(
$functionNames,
static function (string $functionName): bool {
diff --git a/test/unit/SourceLocator/Type/AutoloadSourceLocatorTest.php b/test/unit/SourceLocator/Type/AutoloadSourceLocatorTest.php
index 6a623ce76..c1bd0abfa 100644
--- a/test/unit/SourceLocator/Type/AutoloadSourceLocatorTest.php
+++ b/test/unit/SourceLocator/Type/AutoloadSourceLocatorTest.php
@@ -375,9 +375,7 @@ public function testWillLocateSourcesInPharPath(): void
public function testBrokenAutoloader(): void
{
$getErrorHandler = static function (): ?callable {
- $errorHandler = set_error_handler(static function (): bool {
- return true;
- });
+ $errorHandler = set_error_handler(static fn (): bool => true);
restore_error_handler();
return $errorHandler;
diff --git a/test/unit/SourceLocator/Type/Composer/PsrAutoloaderLocatorTest.php b/test/unit/SourceLocator/Type/Composer/PsrAutoloaderLocatorTest.php
index a715a2de9..c40cfb600 100644
--- a/test/unit/SourceLocator/Type/Composer/PsrAutoloaderLocatorTest.php
+++ b/test/unit/SourceLocator/Type/Composer/PsrAutoloaderLocatorTest.php
@@ -148,9 +148,7 @@ public function testWillLocateAllClassesInMappedPsr4Paths(): void
];
$actual = array_map(
- static function (Reflection $reflection): string {
- return $reflection->getName();
- },
+ static fn (Reflection $reflection): string => $reflection->getName(),
$locator->locateIdentifiersByType(
new ClassReflector($locator),
new IdentifierType(IdentifierType::IDENTIFIER_CLASS),
diff --git a/test/unit/SourceLocator/Type/DirectoriesSourceLocatorTest.php b/test/unit/SourceLocator/Type/DirectoriesSourceLocatorTest.php
index d2513e0fb..a50df9cd1 100644
--- a/test/unit/SourceLocator/Type/DirectoriesSourceLocatorTest.php
+++ b/test/unit/SourceLocator/Type/DirectoriesSourceLocatorTest.php
@@ -50,9 +50,7 @@ public function testScanDirectoryClasses(): void
self::assertCount(4, $classes);
$classNames = array_map(
- static function (ReflectionClass $reflectionClass): string {
- return $reflectionClass->getName();
- },
+ static fn (ReflectionClass $reflectionClass): string => $reflectionClass->getName(),
$classes,
);
diff --git a/test/unit/SourceLocator/Type/FileIteratorSourceLocatorTest.php b/test/unit/SourceLocator/Type/FileIteratorSourceLocatorTest.php
index 31b451a96..c553952f4 100644
--- a/test/unit/SourceLocator/Type/FileIteratorSourceLocatorTest.php
+++ b/test/unit/SourceLocator/Type/FileIteratorSourceLocatorTest.php
@@ -48,9 +48,7 @@ public function testScanDirectoryClasses(): void
self::assertCount(2, $classes);
$classNames = array_map(
- static function (ReflectionClass $reflectionClass): string {
- return $reflectionClass->getName();
- },
+ static fn (ReflectionClass $reflectionClass): string => $reflectionClass->getName(),
$classes,
);
diff --git a/test/unit/SourceLocator/Type/MemoizingSourceLocatorTest.php b/test/unit/SourceLocator/Type/MemoizingSourceLocatorTest.php
index 5a3986b78..39f80188f 100644
--- a/test/unit/SourceLocator/Type/MemoizingSourceLocatorTest.php
+++ b/test/unit/SourceLocator/Type/MemoizingSourceLocatorTest.php
@@ -51,9 +51,7 @@ protected function setUp(): void
$this->wrappedLocator = $this->createMock(SourceLocator::class);
$this->memoizingLocator = new MemoizingSourceLocator($this->wrappedLocator);
$this->identifierNames = array_unique(array_map(
- static function (): string {
- return uniqid('identifier', true);
- },
+ static fn (): string => uniqid('identifier', true),
range(1, 20),
));
$this->identifierCount = count($this->identifierNames);
@@ -63,14 +61,12 @@ public function testLocateIdentifierIsMemoized(): void
{
$this->assertMemoization(
array_map(
- static function (string $identifier): Identifier {
- return new Identifier(
- $identifier,
- new IdentifierType(
- [IdentifierType::IDENTIFIER_CLASS, IdentifierType::IDENTIFIER_FUNCTION][random_int(0, 1)],
- ),
- );
- },
+ static fn (string $identifier): Identifier => new Identifier(
+ $identifier,
+ new IdentifierType(
+ [IdentifierType::IDENTIFIER_CLASS, IdentifierType::IDENTIFIER_FUNCTION][random_int(0, 1)],
+ ),
+ ),
$this->identifierNames,
),
$this->identifierCount,
@@ -81,15 +77,11 @@ static function (string $identifier): Identifier {
public function testLocateIdentifiersDistinguishesBetweenIdentifierTypes(): void
{
$classIdentifiers = array_map(
- static function (string $identifier): Identifier {
- return new Identifier($identifier, new IdentifierType(IdentifierType::IDENTIFIER_CLASS));
- },
+ static fn (string $identifier): Identifier => new Identifier($identifier, new IdentifierType(IdentifierType::IDENTIFIER_CLASS)),
$this->identifierNames,
);
$functionIdentifiers = array_map(
- static function (string $identifier): Identifier {
- return new Identifier($identifier, new IdentifierType(IdentifierType::IDENTIFIER_FUNCTION));
- },
+ static fn (string $identifier): Identifier => new Identifier($identifier, new IdentifierType(IdentifierType::IDENTIFIER_FUNCTION)),
$this->identifierNames,
);
@@ -104,14 +96,12 @@ public function testLocateIdentifiersDistinguishesBetweenReflectorInstances(): v
{
$this->assertMemoization(
array_map(
- static function (string $identifier): Identifier {
- return new Identifier(
- $identifier,
- new IdentifierType(
- [IdentifierType::IDENTIFIER_CLASS, IdentifierType::IDENTIFIER_FUNCTION][random_int(0, 1)],
- ),
- );
- },
+ static fn (string $identifier): Identifier => new Identifier(
+ $identifier,
+ new IdentifierType(
+ [IdentifierType::IDENTIFIER_CLASS, IdentifierType::IDENTIFIER_FUNCTION][random_int(0, 1)],
+ ),
+ ),
$this->identifierNames,
),
$this->identifierCount * 2,
@@ -193,9 +183,7 @@ private function assertMemoization(
->method('locateIdentifier')
->with(
self::logicalOr(...$reflectors),
- self::callback(static function (Identifier $identifier) use ($identifiers) {
- return in_array($identifier, $identifiers, true);
- }),
+ self::callback(static fn (Identifier $identifier) => in_array($identifier, $identifiers, true)),
)
->willReturnCallback(function (
Reflector $reflector,
diff --git a/test/unit/SourceLocator/Type/PhpInternalSourceLocatorTest.php b/test/unit/SourceLocator/Type/PhpInternalSourceLocatorTest.php
index 9accc187d..37bd51930 100644
--- a/test/unit/SourceLocator/Type/PhpInternalSourceLocatorTest.php
+++ b/test/unit/SourceLocator/Type/PhpInternalSourceLocatorTest.php
@@ -94,9 +94,7 @@ public function internalClassesProvider(): array
);
return array_map(
- static function (string $symbol): array {
- return [$symbol];
- },
+ static fn (string $symbol): array => [$symbol],
array_filter(
$allSymbols,
static function (string $symbol): bool {
@@ -140,9 +138,7 @@ public function internalFunctionsProvider(): array
$allSymbols = get_defined_functions()['internal'];
return array_map(
- static function (string $symbol): array {
- return [$symbol];
- },
+ static fn (string $symbol): array => [$symbol],
$allSymbols,
);
}
@@ -172,23 +168,16 @@ public function internalConstantsProvider(): array
$allSymbols = get_defined_constants(true);
return array_map(
- static function (string $symbol): array {
- return [$symbol];
- },
+ static fn (string $symbol): array => [$symbol],
array_filter(
array_keys(
array_merge(
...array_values(
- array_filter($allSymbols, static function (string $extensionName): bool {
- return $extensionName !== 'user';
- }, ARRAY_FILTER_USE_KEY),
+ array_filter($allSymbols, static fn (string $extensionName): bool => $extensionName !== 'user', ARRAY_FILTER_USE_KEY),
),
),
),
- static function (string $constantName): bool {
- // Not supported because of resource as value
- return ! in_array($constantName, ['STDIN', 'STDOUT', 'STDERR'], true);
- },
+ static fn (string $constantName): bool => ! in_array($constantName, ['STDIN', 'STDOUT', 'STDERR'], true),
),
);
}