Skip to content

Commit 3faa605

Browse files
committed
Update build-cs
1 parent 953195d commit 3faa605

23 files changed

+153
-228
lines changed

Diff for: .github/workflows/build.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ jobs:
5656
with:
5757
repository: "phpstan/build-cs"
5858
path: "build-cs"
59-
ref: "1.x"
59+
ref: "2.x"
6060

6161
- name: "Install PHP"
6262
uses: "shivammathur/setup-php@v2"

Diff for: Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ lint:
1313
.PHONY: cs-install
1414
cs-install:
1515
git clone https://github.com/phpstan/build-cs.git || true
16-
git -C build-cs fetch origin && git -C build-cs reset --hard origin/1.x
16+
git -C build-cs fetch origin && git -C build-cs reset --hard origin/2.x
1717
composer install --working-dir build-cs
1818

1919
.PHONY: cs

Diff for: src/PhpDoc/PHPUnit/MockObjectTypeNodeResolverExtension.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@
1717
class MockObjectTypeNodeResolverExtension implements TypeNodeResolverExtension, TypeNodeResolverAwareExtension
1818
{
1919

20-
/** @var TypeNodeResolver */
21-
private $typeNodeResolver;
20+
private TypeNodeResolver $typeNodeResolver;
2221

2322
public function setTypeNodeResolver(TypeNodeResolver $typeNodeResolver): void
2423
{

Diff for: src/Rules/PHPUnit/AnnotationHelper.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public function processDocComment(Doc $docComment): array
5656
}
5757

5858
$errors[] = RuleErrorBuilder::message(
59-
'Annotation "' . $matches['annotation'] . '" is invalid, "@' . $matches['property'] . '" should be followed by a space and a value.'
59+
'Annotation "' . $matches['annotation'] . '" is invalid, "@' . $matches['property'] . '" should be followed by a space and a value.',
6060
)->identifier('phpunit.invalidPhpDoc')->build();
6161
}
6262

Diff for: src/Rules/PHPUnit/AssertRuleHelper.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public static function isMethodOrStaticCallOnAssert(Node $node, Scope $scope): b
3030
'static',
3131
'parent',
3232
],
33-
true
33+
true,
3434
)
3535
) {
3636
$calledOnType = new ObjectType($scope->getClassReflection()->getName());

Diff for: src/Rules/PHPUnit/ClassCoversExistsRule.php

+5-7
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,14 @@ class ClassCoversExistsRule implements Rule
2323
/**
2424
* Covers helper.
2525
*
26-
* @var CoversHelper
2726
*/
28-
private $coversHelper;
27+
private CoversHelper $coversHelper;
2928

3029
/**
3130
* Reflection provider.
3231
*
33-
* @var ReflectionProvider
3432
*/
35-
private $reflectionProvider;
33+
private ReflectionProvider $reflectionProvider;
3634

3735
public function __construct(
3836
CoversHelper $coversHelper,
@@ -62,7 +60,7 @@ public function processNode(Node $node, Scope $scope): array
6260
if (count($classCoversDefaultClasses) >= 2) {
6361
return [
6462
RuleErrorBuilder::message(sprintf(
65-
'@coversDefaultClass is defined multiple times.'
63+
'@coversDefaultClass is defined multiple times.',
6664
))->identifier('phpunit.coversDuplicate')->build(),
6765
];
6866
}
@@ -75,15 +73,15 @@ public function processNode(Node $node, Scope $scope): array
7573
if (!$this->reflectionProvider->hasClass($className)) {
7674
$errors[] = RuleErrorBuilder::message(sprintf(
7775
'@coversDefaultClass references an invalid class %s.',
78-
$className
76+
$className,
7977
))->identifier('phpunit.coversClass')->build();
8078
}
8179
}
8280

8381
foreach ($classCovers as $covers) {
8482
$errors = array_merge(
8583
$errors,
86-
$this->coversHelper->processCovers($node, $covers, null)
84+
$this->coversHelper->processCovers($node, $covers, null),
8785
);
8886
}
8987

Diff for: src/Rules/PHPUnit/ClassMethodCoversExistsRule.php

+7-11
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,14 @@ class ClassMethodCoversExistsRule implements Rule
2525
/**
2626
* Covers helper.
2727
*
28-
* @var CoversHelper
2928
*/
30-
private $coversHelper;
29+
private CoversHelper $coversHelper;
3130

3231
/**
3332
* The file type mapper.
3433
*
35-
* @var FileTypeMapper
3634
*/
37-
private $fileTypeMapper;
35+
private FileTypeMapper $fileTypeMapper;
3836

3937
public function __construct(
4038
CoversHelper $coversHelper,
@@ -65,9 +63,7 @@ public function processNode(Node $node, Scope $scope): array
6563
$classPhpDoc = $classReflection->getResolvedPhpDoc();
6664
[$classCovers, $classCoversDefaultClasses] = $this->coversHelper->getCoverAnnotations($classPhpDoc);
6765

68-
$classCoversStrings = array_map(static function (PhpDocTagNode $covers): string {
69-
return (string) $covers->value;
70-
}, $classCovers);
66+
$classCoversStrings = array_map(static fn (PhpDocTagNode $covers): string => (string) $covers->value, $classCovers);
7167

7268
$docComment = $node->getDocComment();
7369
if ($docComment === null) {
@@ -83,7 +79,7 @@ public function processNode(Node $node, Scope $scope): array
8379
$classReflection->getName(),
8480
$scope->isInTrait() ? $scope->getTraitReflection()->getName() : null,
8581
$node->name->toString(),
86-
$docComment->getText()
82+
$docComment->getText(),
8783
);
8884

8985
[$methodCovers, $methodCoversDefaultClasses] = $this->coversHelper->getCoverAnnotations($methodPhpDoc);
@@ -93,21 +89,21 @@ public function processNode(Node $node, Scope $scope): array
9389
if (count($methodCoversDefaultClasses) > 0) {
9490
$errors[] = RuleErrorBuilder::message(sprintf(
9591
'@coversDefaultClass defined on class method %s.',
96-
$node->name
92+
$node->name,
9793
))->identifier('phpunit.covers')->build();
9894
}
9995

10096
foreach ($methodCovers as $covers) {
10197
if (in_array((string) $covers->value, $classCoversStrings, true)) {
10298
$errors[] = RuleErrorBuilder::message(sprintf(
10399
'Class already @covers %s so the method @covers is redundant.',
104-
$covers->value
100+
$covers->value,
105101
))->identifier('phpunit.coversDuplicate')->build();
106102
}
107103

108104
$errors = array_merge(
109105
$errors,
110-
$this->coversHelper->processCovers($node, $covers, $coversDefaultClass)
106+
$this->coversHelper->processCovers($node, $covers, $coversDefaultClass),
111107
);
112108
}
113109

Diff for: src/Rules/PHPUnit/CoversHelper.php

+6-7
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,8 @@ class CoversHelper
2020
/**
2121
* Reflection provider.
2222
*
23-
* @var ReflectionProvider
2423
*/
25-
private $reflectionProvider;
24+
private ReflectionProvider $reflectionProvider;
2625

2726
public function __construct(ReflectionProvider $reflectionProvider)
2827
{
@@ -48,12 +47,12 @@ public function getCoverAnnotations(?ResolvedPhpDocBlock $phpDoc): array
4847
foreach ($phpDocNodes as $docNode) {
4948
$covers = array_merge(
5049
$covers,
51-
$docNode->getTagsByName('@covers')
50+
$docNode->getTagsByName('@covers'),
5251
);
5352

5453
$coversDefaultClasses = array_merge(
5554
$coversDefaultClasses,
56-
$docNode->getTagsByName('@coversDefaultClass')
55+
$docNode->getTagsByName('@coversDefaultClass'),
5756
);
5857
}
5958

@@ -100,14 +99,14 @@ public function processCovers(
10099
if ($class->isInterface()) {
101100
$errors[] = RuleErrorBuilder::message(sprintf(
102101
'@covers value %s references an interface.',
103-
$fullName
102+
$fullName,
104103
))->identifier('phpunit.coversInterface')->build();
105104
}
106105

107106
if (isset($method) && $method !== '' && !$class->hasMethod($method)) {
108107
$errors[] = RuleErrorBuilder::message(sprintf(
109108
'@covers value %s references an invalid method.',
110-
$fullName
109+
$fullName,
111110
))->identifier('phpunit.coversMethod')->build();
112111
}
113112
} elseif (isset($method) && $this->reflectionProvider->hasFunction(new Name($method, []), null)) {
@@ -118,7 +117,7 @@ public function processCovers(
118117
$error = RuleErrorBuilder::message(sprintf(
119118
'@covers value %s references an invalid %s.',
120119
$fullName,
121-
$isMethod ? 'method' : 'class or function'
120+
$isMethod ? 'method' : 'class or function',
122121
))->identifier(sprintf('phpunit.covers%s', $isMethod ? 'Method' : ''));
123122

124123
if (strpos($className, '\\') === false) {

Diff for: src/Rules/PHPUnit/DataProviderDeclarationRule.php

+5-8
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,20 @@ class DataProviderDeclarationRule implements Rule
1717
/**
1818
* Data provider helper.
1919
*
20-
* @var DataProviderHelper
2120
*/
22-
private $dataProviderHelper;
21+
private DataProviderHelper $dataProviderHelper;
2322

2423
/**
2524
* When set to true, it reports data provider method with incorrect name case.
2625
*
27-
* @var bool
2826
*/
29-
private $checkFunctionNameCase;
27+
private bool $checkFunctionNameCase;
3028

3129
/**
3230
* When phpstan-deprecation-rules is installed, it reports deprecated usages.
3331
*
34-
* @var bool
3532
*/
36-
private $deprecationRulesInstalled;
33+
private bool $deprecationRulesInstalled;
3734

3835
public function __construct(
3936
DataProviderHelper $dataProviderHelper,
@@ -70,8 +67,8 @@ public function processNode(Node $node, Scope $scope): array
7067
$dataProviderMethodName,
7168
$lineNumber,
7269
$this->checkFunctionNameCase,
73-
$this->deprecationRulesInstalled
74-
)
70+
$this->deprecationRulesInstalled,
71+
),
7572
);
7673
}
7774

Diff for: src/Rules/PHPUnit/DataProviderHelper.php

+10-13
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,16 @@ class DataProviderHelper
2828
/**
2929
* Reflection provider.
3030
*
31-
* @var ReflectionProvider
3231
*/
33-
private $reflectionProvider;
32+
private ReflectionProvider $reflectionProvider;
3433

3534
/**
3635
* The file type mapper.
3736
*
38-
* @var FileTypeMapper
3937
*/
40-
private $fileTypeMapper;
38+
private FileTypeMapper $fileTypeMapper;
4139

42-
/** @var bool */
43-
private $phpunit10OrNewer;
40+
private bool $phpunit10OrNewer;
4441

4542
public function __construct(
4643
ReflectionProvider $reflectionProvider,
@@ -69,7 +66,7 @@ public function getDataProviderMethods(
6966
$classReflection->getName(),
7067
$scope->isInTrait() ? $scope->getTraitReflection()->getName() : null,
7168
$node->name->toString(),
72-
$docComment->getText()
69+
$docComment->getText(),
7370
);
7471
foreach ($this->getDataProviderAnnotations($methodPhpDoc) as $annotation) {
7572
$dataProviderValue = $this->getDataProviderAnnotationValue($annotation);
@@ -122,7 +119,7 @@ private function getDataProviderAnnotations(?ResolvedPhpDocBlock $phpDoc): array
122119
foreach ($phpDocNodes as $docNode) {
123120
$annotations = array_merge(
124121
$annotations,
125-
$docNode->getTagsByName('@dataProvider')
122+
$docNode->getTagsByName('@dataProvider'),
126123
);
127124
}
128125

@@ -145,7 +142,7 @@ public function processDataProvider(
145142
return [
146143
RuleErrorBuilder::message(sprintf(
147144
'@dataProvider %s related class not found.',
148-
$dataProviderValue
145+
$dataProviderValue,
149146
))
150147
->line($lineNumber)
151148
->identifier('phpunit.dataProviderClass')
@@ -159,7 +156,7 @@ public function processDataProvider(
159156
return [
160157
RuleErrorBuilder::message(sprintf(
161158
'@dataProvider %s related method not found.',
162-
$dataProviderValue
159+
$dataProviderValue,
163160
))
164161
->line($lineNumber)
165162
->identifier('phpunit.dataProviderMethod')
@@ -173,7 +170,7 @@ public function processDataProvider(
173170
$errors[] = RuleErrorBuilder::message(sprintf(
174171
'@dataProvider %s related method is used with incorrect case: %s.',
175172
$dataProviderValue,
176-
$dataProviderMethodReflection->getName()
173+
$dataProviderMethodReflection->getName(),
177174
))
178175
->line($lineNumber)
179176
->identifier('method.nameCase')
@@ -183,7 +180,7 @@ public function processDataProvider(
183180
if (!$dataProviderMethodReflection->isPublic()) {
184181
$errors[] = RuleErrorBuilder::message(sprintf(
185182
'@dataProvider %s related method must be public.',
186-
$dataProviderValue
183+
$dataProviderValue,
187184
))
188185
->line($lineNumber)
189186
->identifier('phpunit.dataProviderPublic')
@@ -193,7 +190,7 @@ public function processDataProvider(
193190
if ($deprecationRulesInstalled && $this->phpunit10OrNewer && !$dataProviderMethodReflection->isStatic()) {
194191
$errors[] = RuleErrorBuilder::message(sprintf(
195192
'@dataProvider %s related method must be static in PHPUnit 10 and newer.',
196-
$dataProviderValue
193+
$dataProviderValue,
197194
))
198195
->line($lineNumber)
199196
->identifier('phpunit.dataProviderStatic')

Diff for: src/Rules/PHPUnit/DataProviderHelperFactory.php

+2-4
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,9 @@
1414
class DataProviderHelperFactory
1515
{
1616

17-
/** @var ReflectionProvider */
18-
private $reflectionProvider;
17+
private ReflectionProvider $reflectionProvider;
1918

20-
/** @var FileTypeMapper */
21-
private $fileTypeMapper;
19+
private FileTypeMapper $fileTypeMapper;
2220

2321
public function __construct(ReflectionProvider $reflectionProvider, FileTypeMapper $fileTypeMapper)
2422
{

Diff for: src/Rules/PHPUnit/MockMethodCallRule.php

+3-5
Original file line numberDiff line numberDiff line change
@@ -54,17 +54,15 @@ public function processNode(Node $node, Scope $scope): array
5454
)
5555
&& !$type->hasMethod($method)->yes()
5656
) {
57-
$mockClasses = array_filter($type->getObjectClassNames(), static function (string $class): bool {
58-
return $class !== MockObject::class && $class !== Stub::class;
59-
});
57+
$mockClasses = array_filter($type->getObjectClassNames(), static fn (string $class): bool => $class !== MockObject::class && $class !== Stub::class);
6058
if (count($mockClasses) === 0) {
6159
continue;
6260
}
6361

6462
$errors[] = RuleErrorBuilder::message(sprintf(
6563
'Trying to mock an undefined method %s() on class %s.',
6664
$method,
67-
implode('&', $mockClasses)
65+
implode('&', $mockClasses),
6866
))->identifier('phpunit.mockMethod')->build();
6967
continue;
7068
}
@@ -82,7 +80,7 @@ public function processNode(Node $node, Scope $scope): array
8280
$errors[] = RuleErrorBuilder::message(sprintf(
8381
'Trying to mock an undefined method %s() on class %s.',
8482
$method,
85-
implode('|', $classNames)
83+
implode('|', $classNames),
8684
))->identifier('phpunit.mockMethod')->build();
8785
}
8886

Diff for: src/Rules/PHPUnit/NoMissingSpaceInClassAnnotationRule.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,8 @@ class NoMissingSpaceInClassAnnotationRule implements Rule
1717
/**
1818
* Covers helper.
1919
*
20-
* @var AnnotationHelper
2120
*/
22-
private $annotationHelper;
21+
private AnnotationHelper $annotationHelper;
2322

2423
public function __construct(AnnotationHelper $annotationHelper)
2524
{

Diff for: src/Rules/PHPUnit/NoMissingSpaceInMethodAnnotationRule.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,8 @@ class NoMissingSpaceInMethodAnnotationRule implements Rule
1717
/**
1818
* Covers helper.
1919
*
20-
* @var AnnotationHelper
2120
*/
22-
private $annotationHelper;
21+
private AnnotationHelper $annotationHelper;
2322

2423
public function __construct(AnnotationHelper $annotationHelper)
2524
{

0 commit comments

Comments
 (0)