Skip to content

Commit cff1f79

Browse files
committed
cs
1 parent 1dd180c commit cff1f79

File tree

3 files changed

+29
-29
lines changed

3 files changed

+29
-29
lines changed

src/Rules/PHPUnit/DataProviderDataRule.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,27 @@
22

33
namespace PHPStan\Rules\PHPUnit;
44

5-
use LogicException;
65
use PhpParser\Node;
76
use PHPStan\Analyser\Scope;
87
use PHPStan\Reflection\Php\PhpMethodFromParserNodeReflection;
98
use PHPStan\Reflection\ReflectionProvider;
109
use PHPStan\Rules\Rule;
1110
use PHPUnit\Framework\TestCase;
11+
use function count;
1212

1313
/**
1414
* @implements Rule<Node\Stmt\Return_>
1515
*/
1616
class DataProviderDataRule implements Rule
1717
{
18+
1819
private ReflectionProvider $reflectionProvider;
1920

2021
private TestMethodsHelper $testMethodsHelper;
2122

2223
public function __construct(
2324
ReflectionProvider $reflectionProvider,
24-
TestMethodsHelper $testMethodsHelper,
25+
TestMethodsHelper $testMethodsHelper
2526
)
2627
{
2728
$this->reflectionProvider = $reflectionProvider;
@@ -64,10 +65,8 @@ public function processNode(Node $node, Scope $scope): array
6465

6566
$testsWithProvider = [];
6667
$testMethods = $this->testMethodsHelper->getTestMethods($classReflection);
67-
foreach($testMethods as $testMethod)
68-
{
69-
foreach($this->testMethodsHelper->getDataProviderMethods($scope, $testMethod, $classReflection) as [$providerMethod])
70-
{
68+
foreach ($testMethods as $testMethod) {
69+
foreach ($this->testMethodsHelper->getDataProviderMethods($scope, $testMethod, $classReflection) as [$providerMethod]) {
7170
if ($providerMethod === $method->getName()) {
7271
$testsWithProvider[] = $testMethod;
7372
continue 2;
@@ -79,7 +78,7 @@ public function processNode(Node $node, Scope $scope): array
7978
return [];
8079
}
8180

82-
foreach($node->expr->items as $item) {
81+
foreach ($node->expr->items as $item) {
8382
if (!$item->value instanceof Node\Expr\Array_) {
8483
return [];
8584
}
@@ -90,7 +89,7 @@ public function processNode(Node $node, Scope $scope): array
9089
$var,
9190
$testsWithProvider[0]->getName(),
9291
$args,
93-
['startLine' => $item->getStartLine()]
92+
['startLine' => $item->getStartLine()],
9493
));
9594
}
9695

@@ -100,10 +99,11 @@ public function processNode(Node $node, Scope $scope): array
10099
/**
101100
* @return array<Node\Arg>
102101
*/
103-
private function arrayItemsToArgs(Node\Expr\Array_ $array): ?array {
102+
private function arrayItemsToArgs(Node\Expr\Array_ $array): ?array
103+
{
104104
$args = [];
105105

106-
foreach($array->items as $item) {
106+
foreach ($array->items as $item) {
107107
// XXX named args
108108
$value = $item->value;
109109

src/Rules/PHPUnit/TestMethodsHelper.php

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,19 @@
22

33
namespace PHPStan\Rules\PHPUnit;
44

5-
use PhpParser\Node;
6-
use PhpParser\Node\Name;
75
use PHPStan\Analyser\Scope;
8-
use PHPStan\Node\ClassMethod;
96
use PHPStan\Parser\Parser;
10-
use PHPStan\PhpDoc\ResolvedPhpDocBlock;
11-
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagNode;
127
use PHPStan\Reflection\ClassReflection;
138
use PHPStan\Reflection\ReflectionProvider;
14-
use PHPStan\Rules\IdentifierRuleError;
15-
use PHPStan\Rules\RuleErrorBuilder;
169
use PHPStan\Type\FileTypeMapper;
1710
use ReflectionMethod;
18-
use function array_merge;
19-
use function explode;
20-
use function sprintf;
21-
use function strpos;
11+
use function count;
12+
use function str_starts_with;
13+
use function strtolower;
2214

2315
final class TestMethodsHelper
2416
{
17+
2518
private ReflectionProvider $reflectionProvider;
2619

2720
private FileTypeMapper $fileTypeMapper;
@@ -45,7 +38,7 @@ public function __construct(
4538
public function getTestMethods(ClassReflection $class): array
4639
{
4740
$testMethods = [];
48-
foreach($class->getNativeReflection()->getMethods() as $reflectionMethod) {
41+
foreach ($class->getNativeReflection()->getMethods() as $reflectionMethod) {
4942
if (str_starts_with(strtolower($reflectionMethod->getName()), 'test')) {
5043
$testMethods[] = $reflectionMethod;
5144
continue;
@@ -54,9 +47,11 @@ public function getTestMethods(ClassReflection $class): array
5447
// todo: detect tests with @test annotation
5548

5649
$testAttributes = $reflectionMethod->getAttributes('PHPUnit\Framework\Attribute\Test');
57-
if ($testAttributes !== []) {
58-
$testMethods[] = $reflectionMethod;
50+
if ($testAttributes === []) {
51+
continue;
5952
}
53+
54+
$testMethods[] = $reflectionMethod;
6055
}
6156

6257
return $testMethods;
@@ -66,9 +61,9 @@ public function getTestMethods(ClassReflection $class): array
6661
* @return iterable<array{string}>
6762
*/
6863
public function getDataProviderMethods(
69-
Scope $scope,
64+
Scope $scope,
7065
ReflectionMethod $node,
71-
ClassReflection $classReflection
66+
ClassReflection $classReflection
7267
): iterable
7368
{
7469
/*

tests/PHPStan/Rules/CompositeRule.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
1-
<?php
1+
<?php declare(strict_types = 1);
22

33
namespace PHPStan\Rules;
44

55
use PhpParser\Node;
66
use PHPStan\Analyser\Scope;
7+
use function get_class;
8+
9+
class CompositeRule implements Rule
10+
{
711

8-
class CompositeRule implements Rule {
912
private DirectRegistry $registry;
1013

11-
public function __construct(DirectRegistry $ruleRegisty) {
14+
public function __construct(DirectRegistry $ruleRegisty)
15+
{
1216
$this->registry = $ruleRegisty;
1317
}
1418

@@ -31,4 +35,5 @@ public function processNode(Node $node, Scope $scope): array
3135

3236
return $errors;
3337
}
38+
3439
}

0 commit comments

Comments
 (0)