Skip to content

Commit

Permalink
Enabled RequireArrowFunctionSniff and ArrowFunctionDeclarationSniff
Browse files Browse the repository at this point in the history
  • Loading branch information
kukulich committed Sep 15, 2021
1 parent e2cac77 commit a883839
Show file tree
Hide file tree
Showing 46 changed files with 231 additions and 518 deletions.
10 changes: 10 additions & 0 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@

<rule ref="SlevomatCodingStandard.Classes.RequireConstructorPropertyPromotion"/>
<rule ref="SlevomatCodingStandard.Exceptions.RequireNonCapturingCatch"/>
<rule ref="SlevomatCodingStandard.Functions.ArrowFunctionDeclaration">
<properties>
<property name="allowMultiLine" value="true"/>
</properties>
</rule>
<rule ref="SlevomatCodingStandard.Functions.RequireArrowFunction">
<properties>
<property name="allowNested" value="false"/>
</properties>
</rule>
<rule ref="SlevomatCodingStandard.Functions.RequireTrailingCommaInCall"/>
<rule ref="SlevomatCodingStandard.Functions.RequireTrailingCommaInDeclaration"/>
<rule ref="SlevomatCodingStandard.TypeHints.ParameterTypeHint"/>
Expand Down
4 changes: 1 addition & 3 deletions src/BetterReflection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
36 changes: 9 additions & 27 deletions src/Reflection/Adapter/ReflectionClass.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

/**
Expand Down Expand Up @@ -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)));
}

/**
Expand All @@ -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));
}

/**
Expand Down Expand Up @@ -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)));
}

/**
Expand All @@ -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),
);
}

Expand Down Expand Up @@ -310,15 +300,11 @@ public function getTraits()
$traits = $this->betterReflectionClass->getTraits();

/** @var array<trait-string> $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),
);
}

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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;

Expand Down
40 changes: 10 additions & 30 deletions src/Reflection/Adapter/ReflectionObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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()));
}

/**
Expand All @@ -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,
);
}
Expand Down Expand Up @@ -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(),
));
}
Expand Down Expand Up @@ -300,15 +288,11 @@ public function getTraits()
$traits = $this->betterReflectionObject->getTraits();

/** @var array<trait-string> $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),
);
}

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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;

Expand Down
4 changes: 1 addition & 3 deletions src/Reflection/Adapter/ReflectionUnionType.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit a883839

Please sign in to comment.