Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/code_analysis.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ jobs:
-
uses: shivammathur/setup-php@v2
with:
php-version: 8.3
php-version: 8.4
coverage: none

- uses: "ramsey/composer-install@v2"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/rector.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
-
uses: shivammathur/setup-php@v2
with:
php-version: 8.3
php-version: 8.4
coverage: none

- uses: "ramsey/composer-install@v2"
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"license": "MIT",
"description": "Rector upgrades rules for PHPUnit",
"require": {
"php": ">=8.3"
"php": ">=8.4"
},
"require-dev": {
"boundwize/structarmed": "^0.9",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,6 @@ public function isEntityClass(string $className): bool
return false;
}

foreach (self::ENTITY_DOCBLOCK_MARKERS as $entityDocBlockMarkers) {
if (str_contains($resolvedPhpDocBlock->getPhpDocString(), $entityDocBlockMarkers)) {
return true;
}
}

// @todo apply attributes as well

return false;
return array_any(self::ENTITY_DOCBLOCK_MARKERS, fn(string $entityDocBlockMarkers): bool => str_contains($resolvedPhpDocBlock->getPhpDocString(), $entityDocBlockMarkers));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,7 @@ public function refactor(Node $node): ?Node
return null;
}

$hasAnnotation = false;
foreach (NewLineSplitter::split($docComment->getText()) as $row) {
if (in_array(trim($row), ['*@test', '* @test'], true)) {
$hasAnnotation = true;
break;
}
}
$hasAnnotation = array_any(NewLineSplitter::split($docComment->getText()), fn(string $row): bool => in_array(trim($row), ['*@test', '* @test'], true));

if (! $hasAnnotation) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Rector\PHPUnit\CodeQuality\Rector\Class_;

use PhpParser\Node\Identifier;
use PhpParser\Node;
use PhpParser\Node\Stmt\Class_;
use Rector\PHPUnit\NodeAnalyzer\TestsNodeAnalyzer;
Expand Down Expand Up @@ -86,7 +87,7 @@ public function refactor(Node $node): ?Node
continue;
}

$classMethod->name = new Node\Identifier($newName);
$classMethod->name = new Identifier($newName);
$hasChanged = true;
}

Expand All @@ -100,8 +101,8 @@ public function refactor(Node $node): ?Node
private function toCamelCase(string $value): string
{
$words = explode(' ', str_replace(['-', '_'], ' ', $value));
$words = array_map(fn (string $word): string => ucfirst($word), $words);
$words = array_map(ucfirst(...), $words);

return lcfirst(implode($words));
return lcfirst(implode('', $words));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Rector\PHPUnit\CodeQuality\Rector\Class_;

use PhpParser\Node\Identifier;
use PhpParser\Node;
use PhpParser\Node\Stmt\Class_;
use Rector\PHPUnit\NodeAnalyzer\TestsNodeAnalyzer;
Expand Down Expand Up @@ -86,7 +87,7 @@ public function refactor(Node $node): ?Node
continue;
}

$classMethod->name = new Node\Identifier($newName);
$classMethod->name = new Identifier($newName);
$hasChanged = true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,13 +161,6 @@ public function refactor(Node $node): ?array
*/
private function hasAllKeysString(array $assertedArrayValues): bool
{
// all keys must be string
foreach (array_keys($assertedArrayValues) as $key) {
if (! is_string($key)) {
return false;
}
}

return true;
return array_all(array_keys($assertedArrayValues), fn(int|string $key): bool => is_string($key));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public function refactor(Node $node): MethodCall|StaticCall|null
) {
$type = $this->getType($comparedExpr->var);

if ((new ObjectType('Countable'))->isSuperTypeOf($type)->yes()) {
if (new ObjectType('Countable')->isSuperTypeOf($type)->yes()) {
$args = $assertArgs;
$args[1] = new Arg($comparedExpr->var);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,6 @@ private function hasRelateParentClass(Class_ $class): bool
return false;
}

foreach (self::PARENT_CLASSES as $parentClass) {
if ($classReflection->is($parentClass)) {
return true;
}
}

return false;
return array_any(self::PARENT_CLASSES, fn(string $parentClass): bool => $classReflection->is($parentClass));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -270,13 +270,7 @@ private function shouldAddAttribute(array $missedTestMethodsByMockPropertyName):
*/
private function isAtLeastOneMockPropertyMockedOnce(array $usingTestMethodsByMockPropertyName): bool
{
foreach ($usingTestMethodsByMockPropertyName as $usingTestMethods) {
if (count($usingTestMethods) !== 0) {
return true;
}
}

return false;
return array_any($usingTestMethodsByMockPropertyName, fn(array $usingTestMethods): bool => $usingTestMethods !== []);
}

private function isMissingExpectsOnMockObjectMethodCallInSetUp(Class_ $class): bool
Expand Down
8 changes: 1 addition & 7 deletions src/NodeAnalyzer/AssertCallAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,7 @@ public function isAssertMethodCall(MethodCall|StaticCall $call): bool
return false;
}

foreach (self::ASSERT_METHOD_NAME_PREFIXES as $assertMethodNamePrefix) {
if (str_starts_with($callName, $assertMethodNamePrefix)) {
return true;
}
}

return false;
return array_any(self::ASSERT_METHOD_NAME_PREFIXES, fn(string $assertMethodNamePrefix): bool => str_starts_with($callName, $assertMethodNamePrefix));
}

private function hasDirectAssertOrMockCall(ClassMethod $classMethod): bool
Expand Down
8 changes: 1 addition & 7 deletions src/NodeAnalyzer/TestsNodeAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,7 @@ public function isInTestClass(Node $node): bool
return false;
}

foreach (PHPUnitClassName::TEST_CLASSES as $testCaseObjectClass) {
if ($classReflection->is($testCaseObjectClass)) {
return true;
}
}

return false;
return array_any(PHPUnitClassName::TEST_CLASSES, fn(string $testCaseObjectClass): bool => $classReflection->is($testCaseObjectClass));
}

public function isTestClassMethod(ClassMethod $classMethod): bool
Expand Down
Loading