File tree Expand file tree Collapse file tree 4 files changed +83
-13
lines changed
tests/PHPStan/Rules/Functions Expand file tree Collapse file tree 4 files changed +83
-13
lines changed Original file line number Diff line number Diff line change 36
36
- PHPStan\Rules\Functions\ArrowFunctionReturnNullsafeByRefRule
37
37
- PHPStan\Rules\Functions\CallToFunctionParametersRule
38
38
- PHPStan\Rules\Functions\ClosureAttributesRule
39
+ - PHPStan\Rules\Functions\DefineParametersRule
39
40
- PHPStan\Rules\Functions\ExistingClassesInArrowFunctionTypehintsRule
40
41
- PHPStan\Rules\Functions\ExistingClassesInClosureTypehintsRule
41
42
- PHPStan\Rules\Functions\ExistingClassesInTypehintsRule
Original file line number Diff line number Diff line change
1
+ <?php declare (strict_types = 1 );
2
+
3
+ namespace PHPStan \Rules \Functions ;
4
+
5
+ use PhpParser \Node ;
6
+ use PhpParser \Node \Expr \FuncCall ;
7
+ use PHPStan \Analyser \Scope ;
8
+ use PHPStan \Php \PhpVersion ;
9
+
10
+ /**
11
+ * @implements \PHPStan\Rules\Rule<\PhpParser\Node\Expr\FuncCall>
12
+ */
13
+ class DefineParametersRule implements \PHPStan \Rules \Rule
14
+ {
15
+
16
+ private PhpVersion $ phpVersion ;
17
+
18
+ public function __construct (PhpVersion $ phpVersion )
19
+ {
20
+ $ this ->phpVersion = $ phpVersion ;
21
+ }
22
+
23
+ public function getNodeType (): string
24
+ {
25
+ return FuncCall::class;
26
+ }
27
+
28
+ public function processNode (Node $ node , Scope $ scope ): array
29
+ {
30
+ if (!($ node ->name instanceof \PhpParser \Node \Name)) {
31
+ return [];
32
+ }
33
+ if ($ this ->phpVersion ->getVersionId () < 80000 ) {
34
+ return [];
35
+ }
36
+ $ name = strtolower ((string ) $ node ->name );
37
+ if ($ name !== 'define ' ) {
38
+ return [];
39
+ }
40
+ $ args = $ node ->getArgs ();
41
+ $ argsCount = count ($ args );
42
+ // Expects 2, 1 arg is caught by CallToFunctionParametersRule
43
+ if ($ argsCount < 3 ) {
44
+ return [];
45
+ }
46
+ return [
47
+ 'Argument #3 ($case_insensitive) is ignored since declaration of case-insensitive constants is no longer supported. ' ,
48
+ ];
49
+ }
50
+
51
+ }
Original file line number Diff line number Diff line change @@ -131,19 +131,6 @@ public function testCallToArrayUnique(): void
131
131
]);
132
132
}
133
133
134
- public function testCallToDefineCaseInsenstive (): void
135
- {
136
- if (PHP_VERSION_ID < 80000 ) {
137
- $ this ->markTestSkipped ('Test requires PHP 8.0. ' );
138
- }
139
- $ this ->analyse ([__DIR__ . '/data/call-to-define.php ' ], [
140
- [
141
- 'Argument #3 ($case_insensitive) is ignored since declaration of case-insensitive constants is no longer supported ' ,
142
- 3 ,
143
- ],
144
- ]);
145
- }
146
-
147
134
public function testCallToArrayMapVariadic (): void
148
135
{
149
136
$ this ->analyse ([__DIR__ . '/data/call-to-array-map-unique.php ' ], []);
Original file line number Diff line number Diff line change
1
+ <?php declare (strict_types = 1 );
2
+
3
+ namespace PHPStan \Rules \Functions ;
4
+
5
+ use PHPStan \Php \PhpVersion ;
6
+
7
+ /**
8
+ * @extends \PHPStan\Testing\RuleTestCase<DefineParametersRule>
9
+ */
10
+ class DefineParametersRuleTest extends \PHPStan \Testing \RuleTestCase
11
+ {
12
+
13
+ protected function getRule (): \PHPStan \Rules \Rule
14
+ {
15
+ return new DefineParametersRule (new PhpVersion (PHP_VERSION_ID ));
16
+ }
17
+
18
+ public function testFile (): void
19
+ {
20
+ if (PHP_VERSION_ID < 80000 ) {
21
+ $ this ->markTestSkipped ('Test requires PHP 8.0. ' );
22
+ }
23
+ $ this ->analyse ([__DIR__ . '/data/call-to-define.php ' ], [
24
+ [
25
+ 'Argument #3 ($case_insensitive) is ignored since declaration of case-insensitive constants is no longer supported. ' ,
26
+ 3 ,
27
+ ],
28
+ ]);
29
+ }
30
+
31
+ }
You can’t perform that action at this time.
0 commit comments