Skip to content

Commit d56026c

Browse files
committed
Bring extension up to speed
1 parent 5933925 commit d56026c

13 files changed

+60
-39
lines changed

Diff for: build.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@
8686
>
8787
<arg value="analyse"/>
8888
<arg value="-l"/>
89-
<arg value="7"/>
89+
<arg value="8"/>
9090
<arg value="-c"/>
9191
<arg path="phpstan.neon"/>
9292
<arg path="src"/>

Diff for: composer.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@
2323
"nikic/php-parser": "^4.0"
2424
},
2525
"require-dev": {
26-
"consistence/coding-standard": "^3.0.1",
26+
"consistence/coding-standard": "^3.5",
2727
"dealerdirect/phpcodesniffer-composer-installer": "^0.4.4",
2828
"jakub-onderka/php-parallel-lint": "^1.0",
2929
"phing/phing": "^2.16.0",
3030
"phpstan/phpstan-strict-rules": "^0.12",
3131
"satooshi/php-coveralls": "^1.0",
32-
"slevomat/coding-standard": "^4.5.2",
32+
"slevomat/coding-standard": "^4.7.2",
3333
"phpunit/phpunit": "^7.0"
3434
},
3535
"conflict": {

Diff for: phpcs.xml

+2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
@requires
2525
"/>
2626
</properties>
27+
<exclude name="SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingTraversableParameterTypeHintSpecification"/>
28+
<exclude name="SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingTraversableReturnTypeHintSpecification"/>
2729
</rule>
2830
<rule ref="SlevomatCodingStandard.ControlStructures.AssignmentInCondition"/>
2931
<rule ref="SlevomatCodingStandard.ControlStructures.DisallowEqualOperators"/>

Diff for: phpstan.neon

+2-4
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,11 @@ includes:
22
- extension.neon
33
- rules.neon
44
- vendor/phpstan/phpstan-strict-rules/rules.neon
5-
- vendor/phpstan/phpstan/conf/bleedingEdge.neon
5+
- phar://phpstan.phar/conf/bleedingEdge.neon
66

77
parameters:
88
excludes_analyse:
9-
- */tests/*/data/*
10-
ignoreErrors:
11-
- '~^Parameter \#1 \$node \(.*\) of method .*Rule::processNode\(\) should be contravariant with parameter \$node \(PhpParser\\Node\) of method PHPStan\\Rules\\Rule::processNode\(\)$~'
9+
- tests/*/data/*
1210

1311
services:
1412
scopeIsInClass:

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

+6-5
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
use PHPStan\Analyser\Scope;
77
use PHPStan\Type\Constant\ConstantBooleanType;
88

9+
/**
10+
* @implements \PHPStan\Rules\Rule<\PhpParser\NodeAbstract>
11+
*/
912
class AssertSameBooleanExpectedRule implements \PHPStan\Rules\Rule
1013
{
1114

@@ -14,17 +17,15 @@ public function getNodeType(): string
1417
return \PhpParser\NodeAbstract::class;
1518
}
1619

17-
/**
18-
* @param \PhpParser\Node\Expr\MethodCall|\PhpParser\Node\Expr\StaticCall $node
19-
* @param \PHPStan\Analyser\Scope $scope
20-
* @return string[] errors
21-
*/
2220
public function processNode(Node $node, Scope $scope): array
2321
{
2422
if (!AssertRuleHelper::isMethodOrStaticCallOnAssert($node, $scope)) {
2523
return [];
2624
}
2725

26+
/** @var \PhpParser\Node\Expr\MethodCall|\PhpParser\Node\Expr\StaticCall $node */
27+
$node = $node;
28+
2829
if (count($node->args) < 2) {
2930
return [];
3031
}

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

+6-5
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
use PHPStan\Analyser\Scope;
77
use PHPStan\Type\NullType;
88

9+
/**
10+
* @implements \PHPStan\Rules\Rule<\PhpParser\NodeAbstract>
11+
*/
912
class AssertSameNullExpectedRule implements \PHPStan\Rules\Rule
1013
{
1114

@@ -14,17 +17,15 @@ public function getNodeType(): string
1417
return \PhpParser\NodeAbstract::class;
1518
}
1619

17-
/**
18-
* @param \PhpParser\Node\Expr\MethodCall|\PhpParser\Node\Expr\StaticCall $node
19-
* @param \PHPStan\Analyser\Scope $scope
20-
* @return string[] errors
21-
*/
2220
public function processNode(Node $node, Scope $scope): array
2321
{
2422
if (!AssertRuleHelper::isMethodOrStaticCallOnAssert($node, $scope)) {
2523
return [];
2624
}
2725

26+
/** @var \PhpParser\Node\Expr\MethodCall|\PhpParser\Node\Expr\StaticCall $node */
27+
$node = $node;
28+
2829
if (count($node->args) < 2) {
2930
return [];
3031
}

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

+6-5
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
use PhpParser\Node;
66
use PHPStan\Analyser\Scope;
77

8+
/**
9+
* @implements \PHPStan\Rules\Rule<\PhpParser\NodeAbstract>
10+
*/
811
class AssertSameWithCountRule implements \PHPStan\Rules\Rule
912
{
1013

@@ -13,17 +16,15 @@ public function getNodeType(): string
1316
return \PhpParser\NodeAbstract::class;
1417
}
1518

16-
/**
17-
* @param \PhpParser\Node\Expr\MethodCall|\PhpParser\Node\Expr\StaticCall $node
18-
* @param \PHPStan\Analyser\Scope $scope
19-
* @return string[] errors
20-
*/
2119
public function processNode(Node $node, Scope $scope): array
2220
{
2321
if (!AssertRuleHelper::isMethodOrStaticCallOnAssert($node, $scope)) {
2422
return [];
2523
}
2624

25+
/** @var \PhpParser\Node\Expr\MethodCall|\PhpParser\Node\Expr\StaticCall $node */
26+
$node = $node;
27+
2728
if (count($node->args) < 2) {
2829
return [];
2930
}

Diff for: src/Type/PHPUnit/Assert/AssertTypeSpecifyingExtensionHelper.php

+20-17
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
namespace PHPStan\Type\PHPUnit\Assert;
44

55
use PhpParser\Node\Arg;
6+
use PhpParser\Node\Expr\BinaryOp\Identical;
7+
use PhpParser\Node\Expr\FuncCall;
8+
use PhpParser\Node\Expr\Instanceof_;
69
use PhpParser\Node\Name;
710
use PHPStan\Analyser\Scope;
811
use PHPStan\Analyser\SpecifiedTypes;
@@ -117,7 +120,7 @@ private static function getExpressionResolvers(): array
117120
{
118121
if (self::$resolvers === null) {
119122
self::$resolvers = [
120-
'InstanceOf' => function (Scope $scope, Arg $class, Arg $object) {
123+
'InstanceOf' => function (Scope $scope, Arg $class, Arg $object): ?Instanceof_ {
121124
$classType = $scope->getType($class->value);
122125
if (!$classType instanceof ConstantStringType) {
123126
return null;
@@ -128,64 +131,64 @@ private static function getExpressionResolvers(): array
128131
new \PhpParser\Node\Name($classType->getValue())
129132
);
130133
},
131-
'Same' => function (Scope $scope, Arg $expected, Arg $actual) {
134+
'Same' => function (Scope $scope, Arg $expected, Arg $actual): Identical {
132135
return new \PhpParser\Node\Expr\BinaryOp\Identical(
133136
$expected->value,
134137
$actual->value
135138
);
136139
},
137-
'True' => function (Scope $scope, Arg $actual) {
140+
'True' => function (Scope $scope, Arg $actual): Identical {
138141
return new \PhpParser\Node\Expr\BinaryOp\Identical(
139142
$actual->value,
140143
new \PhpParser\Node\Expr\ConstFetch(new Name('true'))
141144
);
142145
},
143-
'False' => function (Scope $scope, Arg $actual) {
146+
'False' => function (Scope $scope, Arg $actual): Identical {
144147
return new \PhpParser\Node\Expr\BinaryOp\Identical(
145148
$actual->value,
146149
new \PhpParser\Node\Expr\ConstFetch(new Name('false'))
147150
);
148151
},
149-
'Null' => function (Scope $scope, Arg $actual) {
152+
'Null' => function (Scope $scope, Arg $actual): Identical {
150153
return new \PhpParser\Node\Expr\BinaryOp\Identical(
151154
$actual->value,
152155
new \PhpParser\Node\Expr\ConstFetch(new Name('null'))
153156
);
154157
},
155-
'IsArray' => function (Scope $scope, Arg $actual) {
158+
'IsArray' => function (Scope $scope, Arg $actual): FuncCall {
156159
return new \PhpParser\Node\Expr\FuncCall(new Name('is_array'), [$actual]);
157160
},
158-
'IsBool' => function (Scope $scope, Arg $actual) {
161+
'IsBool' => function (Scope $scope, Arg $actual): FuncCall {
159162
return new \PhpParser\Node\Expr\FuncCall(new Name('is_bool'), [$actual]);
160163
},
161-
'IsCallable' => function (Scope $scope, Arg $actual) {
164+
'IsCallable' => function (Scope $scope, Arg $actual): FuncCall {
162165
return new \PhpParser\Node\Expr\FuncCall(new Name('is_callable'), [$actual]);
163166
},
164-
'IsFloat' => function (Scope $scope, Arg $actual) {
167+
'IsFloat' => function (Scope $scope, Arg $actual): FuncCall {
165168
return new \PhpParser\Node\Expr\FuncCall(new Name('is_float'), [$actual]);
166169
},
167-
'IsInt' => function (Scope $scope, Arg $actual) {
170+
'IsInt' => function (Scope $scope, Arg $actual): FuncCall {
168171
return new \PhpParser\Node\Expr\FuncCall(new Name('is_int'), [$actual]);
169172
},
170-
'IsIterable' => function (Scope $scope, Arg $actual) {
173+
'IsIterable' => function (Scope $scope, Arg $actual): FuncCall {
171174
return new \PhpParser\Node\Expr\FuncCall(new Name('is_iterable'), [$actual]);
172175
},
173-
'IsNumeric' => function (Scope $scope, Arg $actual) {
176+
'IsNumeric' => function (Scope $scope, Arg $actual): FuncCall {
174177
return new \PhpParser\Node\Expr\FuncCall(new Name('is_numeric'), [$actual]);
175178
},
176-
'IsObject' => function (Scope $scope, Arg $actual) {
179+
'IsObject' => function (Scope $scope, Arg $actual): FuncCall {
177180
return new \PhpParser\Node\Expr\FuncCall(new Name('is_object'), [$actual]);
178181
},
179-
'IsResource' => function (Scope $scope, Arg $actual) {
182+
'IsResource' => function (Scope $scope, Arg $actual): FuncCall {
180183
return new \PhpParser\Node\Expr\FuncCall(new Name('is_resource'), [$actual]);
181184
},
182-
'IsString' => function (Scope $scope, Arg $actual) {
185+
'IsString' => function (Scope $scope, Arg $actual): FuncCall {
183186
return new \PhpParser\Node\Expr\FuncCall(new Name('is_string'), [$actual]);
184187
},
185-
'IsScalar' => function (Scope $scope, Arg $actual) {
188+
'IsScalar' => function (Scope $scope, Arg $actual): FuncCall {
186189
return new \PhpParser\Node\Expr\FuncCall(new Name('is_scalar'), [$actual]);
187190
},
188-
'InternalType' => function (Scope $scope, Arg $type, Arg $value) {
191+
'InternalType' => function (Scope $scope, Arg $type, Arg $value): ?FuncCall {
189192
$typeType = $scope->getType($type->value);
190193
if (!$typeType instanceof ConstantStringType) {
191194
return null;

Diff for: tests/Rules/PHPUnit/AssertSameBooleanExpectedRuleTest.php

+3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
use PHPStan\Rules\Rule;
66

7+
/**
8+
* @extends \PHPStan\Testing\RuleTestCase<AssertSameBooleanExpectedRule>
9+
*/
710
class AssertSameBooleanExpectedRuleTest extends \PHPStan\Testing\RuleTestCase
811
{
912

Diff for: tests/Rules/PHPUnit/AssertSameMethodDifferentTypesRuleTest.php

+3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
use PHPStan\Rules\Rule;
88
use PHPStan\Type\PHPUnit\Assert\AssertMethodTypeSpecifyingExtension;
99

10+
/**
11+
* @extends \PHPStan\Testing\RuleTestCase<ImpossibleCheckTypeMethodCallRule>
12+
*/
1013
class AssertSameMethodDifferentTypesRuleTest extends \PHPStan\Testing\RuleTestCase
1114
{
1215

Diff for: tests/Rules/PHPUnit/AssertSameNullExpectedRuleTest.php

+3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
use PHPStan\Rules\Rule;
66

7+
/**
8+
* @extends \PHPStan\Testing\RuleTestCase<AssertSameNullExpectedRule>
9+
*/
710
class AssertSameNullExpectedRuleTest extends \PHPStan\Testing\RuleTestCase
811
{
912

Diff for: tests/Rules/PHPUnit/AssertSameStaticMethodDifferentTypesRuleTest.php

+3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
use PHPStan\Rules\Rule;
88
use PHPStan\Type\PHPUnit\Assert\AssertStaticMethodTypeSpecifyingExtension;
99

10+
/**
11+
* @extends \PHPStan\Testing\RuleTestCase<ImpossibleCheckTypeStaticMethodCallRule>
12+
*/
1013
class AssertSameStaticMethodDifferentTypesRuleTest extends \PHPStan\Testing\RuleTestCase
1114
{
1215

Diff for: tests/Rules/PHPUnit/AssertSameWithCountRuleTest.php

+3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
use PHPStan\Rules\Rule;
66

7+
/**
8+
* @extends \PHPStan\Testing\RuleTestCase<AssertSameWithCountRule>
9+
*/
710
class AssertSameWithCountRuleTest extends \PHPStan\Testing\RuleTestCase
811
{
912

0 commit comments

Comments
 (0)