Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 3faa605

Browse files
committedSep 4, 2024··
Update build-cs
1 parent 953195d commit 3faa605

23 files changed

+153
-228
lines changed
 

‎.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
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"

‎Makefile

Lines changed: 1 addition & 1 deletion
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

‎src/PhpDoc/PHPUnit/MockObjectTypeNodeResolverExtension.php

Lines changed: 1 addition & 2 deletions
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
{

‎src/Rules/PHPUnit/AnnotationHelper.php

Lines changed: 1 addition & 1 deletion
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

‎src/Rules/PHPUnit/AssertRuleHelper.php

Lines changed: 1 addition & 1 deletion
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());

‎src/Rules/PHPUnit/ClassCoversExistsRule.php

Lines changed: 5 additions & 7 deletions
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

‎src/Rules/PHPUnit/ClassMethodCoversExistsRule.php

Lines changed: 7 additions & 11 deletions
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

‎src/Rules/PHPUnit/CoversHelper.php

Lines changed: 6 additions & 7 deletions
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) {

‎src/Rules/PHPUnit/DataProviderDeclarationRule.php

Lines changed: 5 additions & 8 deletions
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

‎src/Rules/PHPUnit/DataProviderHelper.php

Lines changed: 10 additions & 13 deletions
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')

‎src/Rules/PHPUnit/DataProviderHelperFactory.php

Lines changed: 2 additions & 4 deletions
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
{

‎src/Rules/PHPUnit/MockMethodCallRule.php

Lines changed: 3 additions & 5 deletions
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

‎src/Rules/PHPUnit/NoMissingSpaceInClassAnnotationRule.php

Lines changed: 1 addition & 2 deletions
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
{

‎src/Rules/PHPUnit/NoMissingSpaceInMethodAnnotationRule.php

Lines changed: 1 addition & 2 deletions
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
{

‎src/Rules/PHPUnit/ShouldCallParentMethodsRule.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public function processNode(Node $node, Scope $scope): array
5656
if (!$hasParentCall) {
5757
return [
5858
RuleErrorBuilder::message(
59-
sprintf('Missing call to parent::%s() method.', $methodName)
59+
sprintf('Missing call to parent::%s() method.', $methodName),
6060
)->identifier('phpunit.callParent')->build(),
6161
];
6262
}

‎src/Type/PHPUnit/Assert/AssertFunctionTypeSpecifyingExtension.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@
1717
class AssertFunctionTypeSpecifyingExtension implements FunctionTypeSpecifyingExtension, TypeSpecifierAwareExtension
1818
{
1919

20-
/** @var TypeSpecifier */
21-
private $typeSpecifier;
20+
private TypeSpecifier $typeSpecifier;
2221

2322
public function setTypeSpecifier(TypeSpecifier $typeSpecifier): void
2423
{
@@ -33,7 +32,7 @@ public function isFunctionSupported(
3332
{
3433
return AssertTypeSpecifyingExtensionHelper::isSupported(
3534
$this->trimName($functionReflection->getName()),
36-
$node->getArgs()
35+
$node->getArgs(),
3736
);
3837
}
3938

@@ -48,7 +47,7 @@ public function specifyTypes(
4847
$this->typeSpecifier,
4948
$scope,
5049
$this->trimName($functionReflection->getName()),
51-
$node->getArgs()
50+
$node->getArgs(),
5251
);
5352
}
5453

‎src/Type/PHPUnit/Assert/AssertMethodTypeSpecifyingExtension.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@
1414
class AssertMethodTypeSpecifyingExtension implements MethodTypeSpecifyingExtension, TypeSpecifierAwareExtension
1515
{
1616

17-
/** @var TypeSpecifier */
18-
private $typeSpecifier;
17+
private TypeSpecifier $typeSpecifier;
1918

2019
public function setTypeSpecifier(TypeSpecifier $typeSpecifier): void
2120
{
@@ -35,7 +34,7 @@ public function isMethodSupported(
3534
{
3635
return AssertTypeSpecifyingExtensionHelper::isSupported(
3736
$methodReflection->getName(),
38-
$node->getArgs()
37+
$node->getArgs(),
3938
);
4039
}
4140

@@ -50,7 +49,7 @@ public function specifyTypes(
5049
$this->typeSpecifier,
5150
$scope,
5251
$functionReflection->getName(),
53-
$node->getArgs()
52+
$node->getArgs(),
5453
);
5554
}
5655

‎src/Type/PHPUnit/Assert/AssertStaticMethodTypeSpecifyingExtension.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@
1414
class AssertStaticMethodTypeSpecifyingExtension implements StaticMethodTypeSpecifyingExtension, TypeSpecifierAwareExtension
1515
{
1616

17-
/** @var TypeSpecifier */
18-
private $typeSpecifier;
17+
private TypeSpecifier $typeSpecifier;
1918

2019
public function setTypeSpecifier(TypeSpecifier $typeSpecifier): void
2120
{
@@ -35,7 +34,7 @@ public function isStaticMethodSupported(
3534
{
3635
return AssertTypeSpecifyingExtensionHelper::isSupported(
3736
$methodReflection->getName(),
38-
$node->getArgs()
37+
$node->getArgs(),
3938
);
4039
}
4140

@@ -50,7 +49,7 @@ public function specifyTypes(
5049
$this->typeSpecifier,
5150
$scope,
5251
$functionReflection->getName(),
53-
$node->getArgs()
52+
$node->getArgs(),
5453
);
5554
}
5655

‎src/Type/PHPUnit/Assert/AssertTypeSpecifyingExtensionHelper.php

Lines changed: 94 additions & 144 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,13 @@ class AssertTypeSpecifyingExtensionHelper
3232
{
3333

3434
/** @var Closure[] */
35-
private static $resolvers;
35+
private static ?array $resolvers = null;
3636

3737
/**
3838
* Those can specify types correctly, but would produce always-true issue
3939
* @var string[]
4040
*/
41-
private static $resolversCausingAlwaysTrue = ['ContainsOnlyInstancesOf', 'ContainsEquals', 'Contains'];
41+
private static array $resolversCausingAlwaysTrue = ['ContainsOnlyInstancesOf', 'ContainsEquals', 'Contains'];
4242

4343
/**
4444
* @param Arg[] $args
@@ -101,7 +101,7 @@ public static function specifyTypes(
101101
$scope,
102102
$expression,
103103
TypeSpecifierContext::createTruthy(),
104-
$bypassAlwaysTrueIssue ? new Expr\BinaryOp\BooleanAnd($expression, new Expr\Variable('nonsense')) : null
104+
$bypassAlwaysTrueIssue ? new Expr\BinaryOp\BooleanAnd($expression, new Expr\Variable('nonsense')) : null,
105105
);
106106
}
107107

@@ -136,95 +136,57 @@ private static function getExpressionResolvers(): array
136136
{
137137
if (self::$resolvers === null) {
138138
self::$resolvers = [
139-
'Count' => static function (Scope $scope, Arg $expected, Arg $actual): Identical {
140-
return new Identical(
139+
'Count' => static fn (Scope $scope, Arg $expected, Arg $actual): Identical => new Identical(
140+
$expected->value,
141+
new FuncCall(new Name('count'), [$actual]),
142+
),
143+
'NotCount' => static fn (Scope $scope, Arg $expected, Arg $actual): BooleanNot => new BooleanNot(
144+
new Identical(
141145
$expected->value,
142-
new FuncCall(new Name('count'), [$actual])
143-
);
144-
},
145-
'NotCount' => static function (Scope $scope, Arg $expected, Arg $actual): BooleanNot {
146-
return new BooleanNot(
147-
new Identical(
148-
$expected->value,
149-
new FuncCall(new Name('count'), [$actual])
150-
)
151-
);
152-
},
153-
'InstanceOf' => static function (Scope $scope, Arg $class, Arg $object): Instanceof_ {
154-
return new Instanceof_(
155-
$object->value,
156-
$class->value
157-
);
158-
},
159-
'Same' => static function (Scope $scope, Arg $expected, Arg $actual): Identical {
160-
return new Identical(
161-
$expected->value,
162-
$actual->value
163-
);
164-
},
165-
'True' => static function (Scope $scope, Arg $actual): Identical {
166-
return new Identical(
167-
$actual->value,
168-
new ConstFetch(new Name('true'))
169-
);
170-
},
171-
'False' => static function (Scope $scope, Arg $actual): Identical {
172-
return new Identical(
173-
$actual->value,
174-
new ConstFetch(new Name('false'))
175-
);
176-
},
177-
'Null' => static function (Scope $scope, Arg $actual): Identical {
178-
return new Identical(
179-
$actual->value,
180-
new ConstFetch(new Name('null'))
181-
);
182-
},
183-
'Empty' => static function (Scope $scope, Arg $actual): Expr\BinaryOp\BooleanOr {
184-
return new Expr\BinaryOp\BooleanOr(
185-
new Instanceof_($actual->value, new Name(EmptyIterator::class)),
186-
new Expr\BinaryOp\BooleanOr(
187-
new Expr\BinaryOp\BooleanAnd(
188-
new Instanceof_($actual->value, new Name(Countable::class)),
189-
new Identical(new FuncCall(new Name('count'), [new Arg($actual->value)]), new LNumber(0))
190-
),
191-
new Expr\Empty_($actual->value)
192-
)
193-
);
194-
},
195-
'IsArray' => static function (Scope $scope, Arg $actual): FuncCall {
196-
return new FuncCall(new Name('is_array'), [$actual]);
197-
},
198-
'IsBool' => static function (Scope $scope, Arg $actual): FuncCall {
199-
return new FuncCall(new Name('is_bool'), [$actual]);
200-
},
201-
'IsCallable' => static function (Scope $scope, Arg $actual): FuncCall {
202-
return new FuncCall(new Name('is_callable'), [$actual]);
203-
},
204-
'IsFloat' => static function (Scope $scope, Arg $actual): FuncCall {
205-
return new FuncCall(new Name('is_float'), [$actual]);
206-
},
207-
'IsInt' => static function (Scope $scope, Arg $actual): FuncCall {
208-
return new FuncCall(new Name('is_int'), [$actual]);
209-
},
210-
'IsIterable' => static function (Scope $scope, Arg $actual): FuncCall {
211-
return new FuncCall(new Name('is_iterable'), [$actual]);
212-
},
213-
'IsNumeric' => static function (Scope $scope, Arg $actual): FuncCall {
214-
return new FuncCall(new Name('is_numeric'), [$actual]);
215-
},
216-
'IsObject' => static function (Scope $scope, Arg $actual): FuncCall {
217-
return new FuncCall(new Name('is_object'), [$actual]);
218-
},
219-
'IsResource' => static function (Scope $scope, Arg $actual): FuncCall {
220-
return new FuncCall(new Name('is_resource'), [$actual]);
221-
},
222-
'IsString' => static function (Scope $scope, Arg $actual): FuncCall {
223-
return new FuncCall(new Name('is_string'), [$actual]);
224-
},
225-
'IsScalar' => static function (Scope $scope, Arg $actual): FuncCall {
226-
return new FuncCall(new Name('is_scalar'), [$actual]);
227-
},
146+
new FuncCall(new Name('count'), [$actual]),
147+
),
148+
),
149+
'InstanceOf' => static fn (Scope $scope, Arg $class, Arg $object): Instanceof_ => new Instanceof_(
150+
$object->value,
151+
$class->value,
152+
),
153+
'Same' => static fn (Scope $scope, Arg $expected, Arg $actual): Identical => new Identical(
154+
$expected->value,
155+
$actual->value,
156+
),
157+
'True' => static fn (Scope $scope, Arg $actual): Identical => new Identical(
158+
$actual->value,
159+
new ConstFetch(new Name('true')),
160+
),
161+
'False' => static fn (Scope $scope, Arg $actual): Identical => new Identical(
162+
$actual->value,
163+
new ConstFetch(new Name('false')),
164+
),
165+
'Null' => static fn (Scope $scope, Arg $actual): Identical => new Identical(
166+
$actual->value,
167+
new ConstFetch(new Name('null')),
168+
),
169+
'Empty' => static fn (Scope $scope, Arg $actual): Expr\BinaryOp\BooleanOr => new Expr\BinaryOp\BooleanOr(
170+
new Instanceof_($actual->value, new Name(EmptyIterator::class)),
171+
new Expr\BinaryOp\BooleanOr(
172+
new Expr\BinaryOp\BooleanAnd(
173+
new Instanceof_($actual->value, new Name(Countable::class)),
174+
new Identical(new FuncCall(new Name('count'), [new Arg($actual->value)]), new LNumber(0)),
175+
),
176+
new Expr\Empty_($actual->value),
177+
),
178+
),
179+
'IsArray' => static fn (Scope $scope, Arg $actual): FuncCall => new FuncCall(new Name('is_array'), [$actual]),
180+
'IsBool' => static fn (Scope $scope, Arg $actual): FuncCall => new FuncCall(new Name('is_bool'), [$actual]),
181+
'IsCallable' => static fn (Scope $scope, Arg $actual): FuncCall => new FuncCall(new Name('is_callable'), [$actual]),
182+
'IsFloat' => static fn (Scope $scope, Arg $actual): FuncCall => new FuncCall(new Name('is_float'), [$actual]),
183+
'IsInt' => static fn (Scope $scope, Arg $actual): FuncCall => new FuncCall(new Name('is_int'), [$actual]),
184+
'IsIterable' => static fn (Scope $scope, Arg $actual): FuncCall => new FuncCall(new Name('is_iterable'), [$actual]),
185+
'IsNumeric' => static fn (Scope $scope, Arg $actual): FuncCall => new FuncCall(new Name('is_numeric'), [$actual]),
186+
'IsObject' => static fn (Scope $scope, Arg $actual): FuncCall => new FuncCall(new Name('is_object'), [$actual]),
187+
'IsResource' => static fn (Scope $scope, Arg $actual): FuncCall => new FuncCall(new Name('is_resource'), [$actual]),
188+
'IsString' => static fn (Scope $scope, Arg $actual): FuncCall => new FuncCall(new Name('is_string'), [$actual]),
189+
'IsScalar' => static fn (Scope $scope, Arg $actual): FuncCall => new FuncCall(new Name('is_scalar'), [$actual]),
228190
'InternalType' => static function (Scope $scope, Arg $type, Arg $value): ?FuncCall {
229191
$typeNames = $scope->getType($type->value)->getConstantStrings();
230192
if (count($typeNames) !== 1) {
@@ -286,61 +248,49 @@ private static function getExpressionResolvers(): array
286248
new Name($functionName),
287249
[
288250
$value,
289-
]
290-
);
291-
},
292-
'ArrayHasKey' => static function (Scope $scope, Arg $key, Arg $array): Expr {
293-
return new Expr\BinaryOp\BooleanOr(
294-
new Expr\BinaryOp\BooleanAnd(
295-
new Expr\Instanceof_($array->value, new Name('ArrayAccess')),
296-
new Expr\MethodCall($array->value, 'offsetExists', [$key])
297-
),
298-
new FuncCall(new Name('array_key_exists'), [$key, $array])
299-
);
300-
},
301-
'ObjectHasAttribute' => static function (Scope $scope, Arg $property, Arg $object): FuncCall {
302-
return new FuncCall(new Name('property_exists'), [$object, $property]);
303-
},
304-
'ObjectHasProperty' => static function (Scope $scope, Arg $property, Arg $object): FuncCall {
305-
return new FuncCall(new Name('property_exists'), [$object, $property]);
306-
},
307-
'Contains' => static function (Scope $scope, Arg $needle, Arg $haystack): Expr {
308-
return new Expr\BinaryOp\BooleanOr(
309-
new Expr\Instanceof_($haystack->value, new Name('Traversable')),
310-
new FuncCall(new Name('in_array'), [$needle, $haystack, new Arg(new ConstFetch(new Name('true')))])
311-
);
312-
},
313-
'ContainsEquals' => static function (Scope $scope, Arg $needle, Arg $haystack): Expr {
314-
return new Expr\BinaryOp\BooleanOr(
315-
new Expr\Instanceof_($haystack->value, new Name('Traversable')),
316-
new Expr\BinaryOp\BooleanAnd(
317-
new Expr\BooleanNot(new Expr\Empty_($haystack->value)),
318-
new FuncCall(new Name('in_array'), [$needle, $haystack, new Arg(new ConstFetch(new Name('false')))])
319-
)
320-
);
321-
},
322-
'ContainsOnlyInstancesOf' => static function (Scope $scope, Arg $className, Arg $haystack): Expr {
323-
return new Expr\BinaryOp\BooleanOr(
324-
new Expr\Instanceof_($haystack->value, new Name('Traversable')),
325-
new Identical(
326-
$haystack->value,
327-
new FuncCall(new Name('array_filter'), [
328-
$haystack,
329-
new Arg(new Expr\Closure([
330-
'static' => true,
331-
'params' => [
332-
new Param(new Expr\Variable('_')),
333-
],
334-
'stmts' => [
335-
new Stmt\Return_(
336-
new FuncCall(new Name('is_a'), [new Arg(new Expr\Variable('_')), $className])
337-
),
338-
],
339-
])),
340-
])
341-
)
251+
],
342252
);
343253
},
254+
'ArrayHasKey' => static fn (Scope $scope, Arg $key, Arg $array): Expr => new Expr\BinaryOp\BooleanOr(
255+
new Expr\BinaryOp\BooleanAnd(
256+
new Expr\Instanceof_($array->value, new Name('ArrayAccess')),
257+
new Expr\MethodCall($array->value, 'offsetExists', [$key]),
258+
),
259+
new FuncCall(new Name('array_key_exists'), [$key, $array]),
260+
),
261+
'ObjectHasAttribute' => static fn (Scope $scope, Arg $property, Arg $object): FuncCall => new FuncCall(new Name('property_exists'), [$object, $property]),
262+
'ObjectHasProperty' => static fn (Scope $scope, Arg $property, Arg $object): FuncCall => new FuncCall(new Name('property_exists'), [$object, $property]),
263+
'Contains' => static fn (Scope $scope, Arg $needle, Arg $haystack): Expr => new Expr\BinaryOp\BooleanOr(
264+
new Expr\Instanceof_($haystack->value, new Name('Traversable')),
265+
new FuncCall(new Name('in_array'), [$needle, $haystack, new Arg(new ConstFetch(new Name('true')))]),
266+
),
267+
'ContainsEquals' => static fn (Scope $scope, Arg $needle, Arg $haystack): Expr => new Expr\BinaryOp\BooleanOr(
268+
new Expr\Instanceof_($haystack->value, new Name('Traversable')),
269+
new Expr\BinaryOp\BooleanAnd(
270+
new Expr\BooleanNot(new Expr\Empty_($haystack->value)),
271+
new FuncCall(new Name('in_array'), [$needle, $haystack, new Arg(new ConstFetch(new Name('false')))]),
272+
),
273+
),
274+
'ContainsOnlyInstancesOf' => static fn (Scope $scope, Arg $className, Arg $haystack): Expr => new Expr\BinaryOp\BooleanOr(
275+
new Expr\Instanceof_($haystack->value, new Name('Traversable')),
276+
new Identical(
277+
$haystack->value,
278+
new FuncCall(new Name('array_filter'), [
279+
$haystack,
280+
new Arg(new Expr\Closure([
281+
'static' => true,
282+
'params' => [
283+
new Param(new Expr\Variable('_')),
284+
],
285+
'stmts' => [
286+
new Stmt\Return_(
287+
new FuncCall(new Name('is_a'), [new Arg(new Expr\Variable('_')), $className]),
288+
),
289+
],
290+
])),
291+
]),
292+
),
293+
),
344294
];
345295
}
346296

‎src/Type/PHPUnit/MockBuilderDynamicReturnTypeExtension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function isMethodSupported(MethodReflection $methodReflection): bool
2727
'getMockForAbstractClass',
2828
'getMockForTrait',
2929
],
30-
true
30+
true,
3131
);
3232
}
3333

‎src/Type/PHPUnit/MockObjectDynamicReturnTypeExtension.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,7 @@ public function isMethodSupported(MethodReflection $methodReflection): bool
3131
public function getTypeFromMethodCall(MethodReflection $methodReflection, MethodCall $methodCall, Scope $scope): Type
3232
{
3333
$type = $scope->getType($methodCall->var);
34-
$mockClasses = array_values(array_filter($type->getObjectClassNames(), static function (string $class): bool {
35-
return $class !== MockObject::class;
36-
}));
34+
$mockClasses = array_values(array_filter($type->getObjectClassNames(), static fn (string $class): bool => $class !== MockObject::class));
3735

3836
if (count($mockClasses) !== 1) {
3937
return new ObjectType(InvocationMocker::class);

‎tests/Rules/PHPUnit/ClassCoversExistsRuleTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ protected function getRule(): Rule
1717

1818
return new ClassCoversExistsRule(
1919
new CoversHelper($reflection),
20-
$reflection
20+
$reflection,
2121
);
2222
}
2323

‎tests/Rules/PHPUnit/ClassMethodCoversExistsRuleTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ protected function getRule(): Rule
1818

1919
return new ClassMethodCoversExistsRule(
2020
new CoversHelper($reflection),
21-
self::getContainer()->getByType(FileTypeMapper::class)
21+
self::getContainer()->getByType(FileTypeMapper::class),
2222
);
2323
}
2424

0 commit comments

Comments
 (0)
Please sign in to comment.