forked from phpstan/phpstan-src
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCallStaticMethodsRuleTest.php
899 lines (834 loc) · 23.4 KB
/
CallStaticMethodsRuleTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
<?php declare(strict_types = 1);
namespace PHPStan\Rules\Methods;
use PHPStan\Rules\ClassCaseSensitivityCheck;
use PHPStan\Rules\ClassForbiddenNameCheck;
use PHPStan\Rules\ClassNameCheck;
use PHPStan\Rules\FunctionCallParametersCheck;
use PHPStan\Rules\NullsafeCheck;
use PHPStan\Rules\PhpDoc\UnresolvableTypeHelper;
use PHPStan\Rules\Properties\PropertyReflectionFinder;
use PHPStan\Rules\Rule;
use PHPStan\Rules\RuleLevelHelper;
use PHPStan\Testing\RuleTestCase;
use function array_merge;
use function usort;
use const PHP_VERSION_ID;
/**
* @extends RuleTestCase<CallStaticMethodsRule>
*/
class CallStaticMethodsRuleTest extends RuleTestCase
{
private bool $checkThisOnly;
private bool $checkExplicitMixed = false;
private bool $checkImplicitMixed = false;
protected function getRule(): Rule
{
$reflectionProvider = $this->createReflectionProvider();
$ruleLevelHelper = new RuleLevelHelper($reflectionProvider, true, $this->checkThisOnly, true, $this->checkExplicitMixed, $this->checkImplicitMixed, false);
return new CallStaticMethodsRule(
new StaticMethodCallCheck(
$reflectionProvider,
$ruleLevelHelper,
new ClassNameCheck(
new ClassCaseSensitivityCheck($reflectionProvider, true),
new ClassForbiddenNameCheck(self::getContainer()),
),
true,
true,
),
new FunctionCallParametersCheck(
$ruleLevelHelper,
new NullsafeCheck(),
new UnresolvableTypeHelper(),
new PropertyReflectionFinder(),
true,
true,
true,
true,
),
);
}
public function testCallStaticMethods(): void
{
$this->checkThisOnly = false;
$this->analyse([__DIR__ . '/data/call-static-methods.php'], [
[
'Call to an undefined static method CallStaticMethods\Foo::bar().',
39,
],
[
'Call to an undefined static method CallStaticMethods\Bar::bar().',
40,
],
[
'Call to an undefined static method CallStaticMethods\Foo::bar().',
41,
],
[
'Static call to instance method CallStaticMethods\Foo::loremIpsum().',
42,
],
[
'Call to private static method dolor() of class CallStaticMethods\Foo.',
43,
],
[
'CallStaticMethods\Ipsum::ipsumTest() calls parent::lorem() but CallStaticMethods\Ipsum does not extend any class.',
63,
],
[
'Static method CallStaticMethods\Foo::test() invoked with 1 parameter, 0 required.',
65,
],
[
'Call to protected static method baz() of class CallStaticMethods\Foo.',
66,
],
[
'Call to static method loremIpsum() on an unknown class CallStaticMethods\UnknownStaticMethodClass.',
67,
'Learn more at https://phpstan.org/user-guide/discovering-symbols',
],
[
'Call to private method __construct() of class CallStaticMethods\ClassWithConstructor.',
87,
],
[
'Method CallStaticMethods\ClassWithConstructor::__construct() invoked with 0 parameters, 1 required.',
87,
],
[
'Calling self::someStaticMethod() outside of class scope.',
93,
],
[
'Calling static::someStaticMethod() outside of class scope.',
94,
],
[
'Calling parent::someStaticMethod() outside of class scope.',
95,
],
[
'Call to protected static method baz() of class CallStaticMethods\Foo.',
97,
],
[
'Call to an undefined static method CallStaticMethods\Foo::bar().',
98,
],
[
'Static call to instance method CallStaticMethods\Foo::loremIpsum().',
99,
],
[
'Call to private static method dolor() of class CallStaticMethods\Foo.',
100,
],
[
'Static method Locale::getDisplayLanguage() invoked with 3 parameters, 1-2 required.',
104,
],
[
'Static method CallStaticMethods\Foo::test() invoked with 3 parameters, 0 required.',
115,
],
[
'Cannot call static method foo() on int|string.',
120,
],
[
'Class CallStaticMethods\Foo referenced with incorrect case: CallStaticMethods\FOO.',
127,
],
[
'Call to an undefined static method CallStaticMethods\Foo::unknownMethod().',
127,
],
[
'Class CallStaticMethods\Foo referenced with incorrect case: CallStaticMethods\FOO.',
128,
],
[
'Static call to instance method CallStaticMethods\Foo::loremIpsum().',
128,
],
[
'Class CallStaticMethods\Foo referenced with incorrect case: CallStaticMethods\FOO.',
129,
],
[
'Call to private static method dolor() of class CallStaticMethods\Foo.',
129,
],
[
'Class CallStaticMethods\Foo referenced with incorrect case: CallStaticMethods\FOO.',
130,
],
[
'Static method CallStaticMethods\Foo::test() invoked with 3 parameters, 0 required.',
130,
],
[
'Class CallStaticMethods\Foo referenced with incorrect case: CallStaticMethods\FOO.',
131,
],
[
'Call to static method CallStaticMethods\Foo::test() with incorrect case: TEST',
131,
],
[
'Class CallStaticMethods\Foo referenced with incorrect case: CallStaticMethods\FOO.',
132,
],
[
'Call to an undefined static method CallStaticMethods\Foo::__construct().',
144,
],
[
'Call to an undefined static method CallStaticMethods\Foo::nonexistent().',
154,
],
[
'Call to an undefined static method CallStaticMethods\Foo::nonexistent().',
159,
],
[
'Static call to instance method CallStaticMethods\Foo::loremIpsum().',
160,
],
[
'Static method CallStaticMethods\ClassOrString::calledMethod() invoked with 1 parameter, 0 required.',
173,
],
[
'Cannot call abstract static method CallStaticMethods\InterfaceWithStaticMethod::doFoo().',
208,
],
[
'Call to an undefined static method CallStaticMethods\InterfaceWithStaticMethod::doBar().',
209,
],
[
'Static call to instance method CallStaticMethods\InterfaceWithStaticMethod::doInstanceFoo().',
212,
],
[
'Static call to instance method CallStaticMethods\InterfaceWithStaticMethod::doInstanceFoo().',
213,
],
[
'Static method CallStaticMethods\Foo::test() invoked with 3 parameters, 0 required.',
298,
],
[
'Call to an undefined static method T of CallStaticMethods\Foo::nonexistentMethod().',
299,
],
[
'Static method CallStaticMethods\Foo::test() invoked with 3 parameters, 0 required.',
302,
],
[
'Call to an undefined static method CallStaticMethods\Foo::nonexistentMethod().',
303,
],
[
'Call to static method doFoo() on an unknown class CallStaticMethods\TraitWithStaticMethod.',
328,
'Learn more at https://phpstan.org/user-guide/discovering-symbols',
],
[
'Call to an undefined static method CallStaticMethods\CallWithStatic::nonexistent().',
344,
],
]);
}
public function testCallInterfaceMethods(): void
{
$this->checkThisOnly = false;
$this->analyse([__DIR__ . '/data/call-interface-methods.php'], [
[
'Cannot call abstract static method InterfaceMethods\Foo::fooStaticMethod().',
26,
],
[
'Call to an undefined static method InterfaceMethods\Baz::barStaticMethod().',
27,
],
]);
}
public function testCallToIncorrectCaseMethodName(): void
{
$this->checkThisOnly = false;
$this->analyse([__DIR__ . '/data/incorrect-static-method-case.php'], [
[
'Call to static method IncorrectStaticMethodCase\Foo::fooBar() with incorrect case: foobar',
10,
],
]);
}
public function testStaticCallsToInstanceMethods(): void
{
$this->checkThisOnly = false;
$this->analyse([__DIR__ . '/data/static-calls-to-instance-methods.php'], [
[
'Static call to instance method StaticCallsToInstanceMethods\Foo::doFoo().',
10,
],
[
'Static call to instance method StaticCallsToInstanceMethods\Bar::doBar().',
16,
],
[
'Static call to instance method StaticCallsToInstanceMethods\Foo::doFoo().',
36,
],
[
'Call to method StaticCallsToInstanceMethods\Foo::doFoo() with incorrect case: dofoo',
42,
],
[
'Method StaticCallsToInstanceMethods\Foo::doFoo() invoked with 1 parameter, 0 required.',
43,
],
[
'Call to private method doPrivateFoo() of class StaticCallsToInstanceMethods\Foo.',
45,
],
[
'Method StaticCallsToInstanceMethods\Foo::doFoo() invoked with 1 parameter, 0 required.',
48,
],
]);
}
public function testStaticCallOnExpression(): void
{
$this->checkThisOnly = false;
$this->analyse([__DIR__ . '/data/static-call-on-expression.php'], [
[
'Call to an undefined static method StaticCallOnExpression\Foo::doBar().',
16,
],
]);
}
public function testStaticCallOnExpressionWithCheckDisabled(): void
{
$this->checkThisOnly = true;
$this->analyse([__DIR__ . '/data/static-call-on-expression.php'], []);
}
public function testReturnStatic(): void
{
$this->checkThisOnly = false;
$this->analyse([__DIR__ . '/data/return-static-static-method.php'], [
[
'Call to an undefined static method ReturnStaticStaticMethod\Bar::doBaz().',
24,
],
]);
}
public function testCallParentAbstractMethod(): void
{
$this->checkThisOnly = false;
$this->analyse([__DIR__ . '/data/call-parent-abstract-method.php'], [
[
'Cannot call abstract method CallParentAbstractMethod\Baz::uninstall().',
21,
],
[
'Cannot call abstract method CallParentAbstractMethod\Lorem::doFoo().',
38,
],
[
'Cannot call abstract method CallParentAbstractMethod\Lorem::doFoo().',
48,
],
[
'Cannot call abstract static method CallParentAbstractMethod\SitAmet::doFoo().',
61,
],
]);
}
public function testClassExists(): void
{
$this->checkThisOnly = false;
$this->analyse([__DIR__ . '/data/static-methods-class-exists.php'], []);
}
public function testBug3448(): void
{
$this->checkThisOnly = false;
$this->analyse([__DIR__ . '/data/bug-3448.php'], [
[
'Parameter #1 $lall of static method Bug3448\Foo::add() expects int, string given.',
21,
],
[
'Parameter #1 $lall of static method Bug3448\Foo::add() expects int, string given.',
22,
],
]);
}
public function testBug3641(): void
{
$this->checkThisOnly = false;
$this->analyse([__DIR__ . '/data/bug-3641.php'], [
[
'Static method Bug3641\Foo::bar() invoked with 1 parameter, 0 required.',
32,
],
]);
}
public function testBug2164(): void
{
$this->checkThisOnly = false;
$this->analyse([__DIR__ . '/data/bug-2164.php'], [
[
'Parameter #1 $arg of static method Bug2164\A::staticTest() expects static(Bug2164\B)|string, Bug2164\B|string given.',
24,
],
]);
}
public function testNamedArguments(): void
{
$this->checkThisOnly = false;
if (PHP_VERSION_ID < 80000) {
$this->markTestSkipped('Test requires PHP 8.0');
}
$this->analyse([__DIR__ . '/data/static-method-named-arguments.php'], [
[
'Missing parameter $j (int) in call to static method StaticMethodNamedArguments\Foo::doFoo().',
15,
],
[
'Unknown parameter $z in call to static method StaticMethodNamedArguments\Foo::doFoo().',
16,
],
]);
}
public function testBug577(): void
{
$this->checkThisOnly = false;
$this->analyse([__DIR__ . '/data/bug-577.php'], []);
}
public function testBug4550(): void
{
$this->checkThisOnly = false;
$this->analyse([__DIR__ . '/data/bug-4550.php'], [
[
'Parameter #1 $class of static method Bug4550\Test::valuesOf() expects class-string<Person>, string given.',
34,
],
[
'Parameter #1 $class of static method Bug4550\Test::valuesOf() expects class-string<Person>, string given.',
44,
],
]);
}
public function testBug1971(): void
{
if (PHP_VERSION_ID >= 80000) {
$this->markTestSkipped('Test requires PHP 7.x');
}
$this->checkThisOnly = false;
$this->analyse([__DIR__ . '/data/bug-1971.php'], [
[
'Parameter #1 $callback of static method Closure::fromCallable() expects callable(): mixed, array{class-string<static(Bug1971\\HelloWorld)>, \'sayHello2\'} given.',
16,
],
]);
}
public function testBug1971Php8(): void
{
if (PHP_VERSION_ID < 80000) {
$this->markTestSkipped('Test requires PHP 8.0');
}
$this->checkThisOnly = false;
$this->analyse([__DIR__ . '/data/bug-1971.php'], [
[
'Parameter #1 $callback of static method Closure::fromCallable() expects callable(): mixed, array{\'Bug1971\\\HelloWorld\', \'sayHello\'} given.',
14,
],
[
'Parameter #1 $callback of static method Closure::fromCallable() expects callable(): mixed, array{class-string<static(Bug1971\\HelloWorld)>, \'sayHello\'} given.',
15,
],
[
'Parameter #1 $callback of static method Closure::fromCallable() expects callable(): mixed, array{class-string<static(Bug1971\\HelloWorld)>, \'sayHello2\'} given.',
16,
],
]);
}
public function testBug5259(): void
{
$this->checkThisOnly = false;
$this->analyse([__DIR__ . '/data/bug-5259.php'], []);
}
public function testBug5536(): void
{
$this->checkThisOnly = false;
$this->analyse([__DIR__ . '/data/bug-5536.php'], []);
}
public function testBug4886(): void
{
$this->checkThisOnly = false;
$this->analyse([__DIR__ . '/data/bug-4886.php'], []);
}
public function testFirstClassCallables(): void
{
$this->checkThisOnly = false;
// handled by a different rule
$this->analyse([__DIR__ . '/data/first-class-static-method-callable.php'], []);
}
public function testBug5893(): void
{
$this->checkThisOnly = false;
$this->checkExplicitMixed = true;
$this->analyse([__DIR__ . '/data/bug-5893.php'], []);
}
public function testBug6249(): void
{
// discussion https://github.com/phpstan/phpstan/discussions/6249
$this->checkThisOnly = false;
$this->checkExplicitMixed = true;
$this->analyse([__DIR__ . '/data/bug-6249.php'], []);
}
public function testBug5749(): void
{
$this->checkThisOnly = false;
$this->checkExplicitMixed = true;
$this->analyse([__DIR__ . '/data/bug-5749.php'], []);
}
public function testBug5757(): void
{
$this->checkThisOnly = false;
$this->checkExplicitMixed = true;
$this->analyse([__DIR__ . '/data/bug-5757.php'], []);
}
public function testDiscussion7004(): void
{
$this->checkThisOnly = false;
$this->checkExplicitMixed = true;
$this->analyse([__DIR__ . '/data/discussion-7004.php'], [
[
'Parameter #1 $data of static method Discussion7004\Foo::fromArray1() expects array<array{newsletterName: string, subscriberCount: int}>, array<mixed, mixed> given.',
46,
],
[
'Parameter #1 $data of static method Discussion7004\Foo::fromArray2() expects array{array{newsletterName: string, subscriberCount: int}}, array<mixed, mixed> given.',
47,
],
[
'Parameter #1 $data of static method Discussion7004\Foo::fromArray3() expects array{newsletterName: string, subscriberCount: int}, array<mixed, mixed> given.',
48,
],
]);
}
public function testTemplateTypeInOneBranchOfConditional(): void
{
$this->checkThisOnly = false;
$this->checkExplicitMixed = true;
$this->analyse([__DIR__ . '/data/template-type-in-one-branch-of-conditional.php'], [
[
'Parameter #1 $params of static method TemplateTypeInOneBranchOfConditional\DriverManager::getConnection() expects array{wrapperClass?: class-string<TemplateTypeInOneBranchOfConditional\Connection>}, array{wrapperClass: \'stdClass\'} given.',
27,
"Offset 'wrapperClass' (class-string<TemplateTypeInOneBranchOfConditional\Connection>) does not accept type string.",
],
[
'Unable to resolve the template type T in call to method static method TemplateTypeInOneBranchOfConditional\DriverManager::getConnection()',
27,
'See: https://phpstan.org/blog/solving-phpstan-error-unable-to-resolve-template-type',
],
]);
}
public function testBug7489(): void
{
$this->checkThisOnly = false;
$this->checkExplicitMixed = true;
$this->analyse([__DIR__ . '/data/bug-7489.php'], []);
}
public function testHasMethodStaticCall(): void
{
$this->checkThisOnly = false;
$this->checkExplicitMixed = false;
$this->analyse([__DIR__ . '/data/static-has-method.php'], [
[
'Call to an undefined static method StaticHasMethodCall\rex_var::doesNotExist().',
38,
],
[
'Call to an undefined static method StaticHasMethodCall\rex_var::doesNotExist().',
48,
],
]);
}
public function testBug1267(): void
{
$this->checkThisOnly = false;
$this->checkExplicitMixed = false;
$this->analyse([__DIR__ . '/data/bug-1267.php'], []);
}
public function testBug6147(): void
{
$this->checkThisOnly = false;
$this->checkExplicitMixed = false;
$this->analyse([__DIR__ . '/data/bug-6147.php'], []);
}
public function testBug5781(): void
{
$this->checkThisOnly = false;
$this->checkExplicitMixed = false;
$this->analyse([__DIR__ . '/data/bug-5781.php'], [
[
'Parameter #1 $param of static method Bug5781\Foo::bar() expects array{a: bool, b: bool, c: bool, d: bool, e: bool, f: bool, g: bool, h: bool, ...}, array{} given.',
17,
"Array does not have offset 'a'.",
],
]);
}
public function testBug8296(): void
{
$this->checkThisOnly = false;
$this->analyse([__DIR__ . '/data/bug-8296.php'], [
[
'Parameter #1 $objects of static method Bug8296\VerifyLoginTask::continueDump() expects array<string, object>, array<string, Bug8296\stdClass|true> given.',
12,
],
[
'Parameter #1 $string of static method Bug8296\VerifyLoginTask::stringByRef() expects string, int given.',
15,
],
]);
}
public function testRequireExtends(): void
{
$this->checkThisOnly = false;
$this->checkExplicitMixed = false;
$this->analyse([__DIR__ . '/../Properties/data/require-extends.php'], [
[
'Call to an undefined static method RequireExtends\MyInterface::doesNotExistStatic().',
44,
],
]);
}
public function testRequireImplements(): void
{
$this->checkThisOnly = false;
$this->checkExplicitMixed = false;
$this->analyse([__DIR__ . '/../Properties/data/require-implements.php'], [
[
'Call to an undefined static method RequireImplements\MyBaseClass::doesNotExistStatic().',
45,
],
]);
}
public function dataMixed(): array
{
$explicitOnlyErrors = [
[
'Cannot call static method foo() on mixed.',
17,
],
[
'Cannot call static method foo() on T of mixed.',
26,
],
[
'Parameter #1 $i of static method CallStaticMethodMixed\Bar::doBar() expects int, mixed given.',
43,
],
[
'Only iterables can be unpacked, mixed given in argument #1.',
52,
],
[
'Parameter #1 $i of static method CallStaticMethodMixed\Bar::doBar() expects int, T given.',
81,
],
[
'Only iterables can be unpacked, T of mixed given in argument #1.',
84,
],
[
'Parameter #1 $cb of static method CallStaticMethodMixed\CallableMixed::callAcceptsExplicitMixed() expects callable(mixed): void, Closure(int): void given.',
134,
'Type int of parameter #1 $i of passed callable needs to be same or wider than parameter type mixed of accepting callable.',
],
[
'Parameter #1 $cb of static method CallStaticMethodMixed\CallableMixed::callReturnsInt() expects callable(): int, Closure(): mixed given.',
161,
],
[
'Parameter #1 $cb of static method CallStaticMethodMixed\CallableMixed::callReturnsInt() expects callable(): int, Closure(): mixed given.',
168,
],
];
$implicitOnlyErrors = [
[
'Cannot call static method foo() on mixed.',
16,
],
[
'Parameter #1 $i of static method CallStaticMethodMixed\Bar::doBar() expects int, mixed given.',
42,
],
[
'Only iterables can be unpacked, mixed given in argument #1.',
51,
],
];
$combinedErrors = array_merge($explicitOnlyErrors, $implicitOnlyErrors);
usort($combinedErrors, static fn (array $a, array $b): int => $a[1] <=> $b[1]);
return [
[
true,
false,
$explicitOnlyErrors,
],
[
false,
true,
$implicitOnlyErrors,
],
[
true,
true,
$combinedErrors,
],
[
false,
false,
[],
],
];
}
/**
* @dataProvider dataMixed
* @param list<array{0: string, 1: int, 2?: string}> $errors
*/
public function testMixed(bool $checkExplicitMixed, bool $checkImplicitMixed, array $errors): void
{
if (PHP_VERSION_ID < 80000) {
self::markTestSkipped('Test requires PHP 8.0.');
}
$this->checkThisOnly = false;
$this->checkExplicitMixed = $checkExplicitMixed;
$this->checkImplicitMixed = $checkImplicitMixed;
$this->analyse([__DIR__ . '/data/call-static-method-mixed.php'], $errors);
}
public function testBugWrongMethodNameWithTemplateMixed(): void
{
if (PHP_VERSION_ID < 80100) {
$this->markTestSkipped('Test requires PHP 8.1');
}
$this->checkThisOnly = false;
$this->checkExplicitMixed = true;
$this->checkImplicitMixed = true;
$this->analyse([__DIR__ . '/data/bug-wrong-method-name-with-template-mixed.php'], [
[
'Call to an undefined static method T of mixed&UnitEnum::from().',
14,
],
[
'Call to an undefined static method T of mixed&UnitEnum::from().',
25,
],
[
'Call to an undefined static method T of object&UnitEnum::from().',
36,
],
[
'Call to an undefined static method UnitEnum::from().',
43,
],
]);
}
public function testConditionalParam(): void
{
$this->checkThisOnly = false;
$this->checkExplicitMixed = true;
$this->checkImplicitMixed = true;
$this->analyse([__DIR__ . '/data/conditional-param.php'], [
[
'Parameter #1 $demoArg of static method ConditionalParam\HelloWorld::replaceCallback() expects string, true given.',
16,
],
[
'Parameter #1 $demoArg of static method ConditionalParam\HelloWorld::replaceCallback() expects bool, string given.',
20,
],
[
// wrong
'Parameter #1 $demoArg of static method ConditionalParam\HelloWorld::replaceCallback() expects string, true given.',
22,
],
]);
}
public function testClosureBindParamClosureThis(): void
{
$this->checkThisOnly = false;
$this->checkExplicitMixed = true;
$this->checkImplicitMixed = true;
$this->analyse([__DIR__ . '/data/closure-bind-param-closure-this.php'], [
[
'Parameter #2 $newThis of static method Closure::bind() expects stdClass, ClosureBindParamClosureThis\Foo given.',
25,
],
]);
}
public function testClosureBind(): void
{
$this->checkThisOnly = false;
$this->analyse([__DIR__ . '/data/closure-bind.php'], [
[
'Parameter #3 $newScope of static method Closure::bind() expects \'static\'|class-string|object|null, \'CallClosureBind\\\Bar3\' given.',
68,
],
]);
}
public function testBug10872(): void
{
$this->checkThisOnly = false;
$this->checkExplicitMixed = true;
$this->checkImplicitMixed = true;
$this->analyse([__DIR__ . '/data/bug-10872.php'], []);
}
public function testBug12015(): void
{
$this->checkThisOnly = false;
$this->checkExplicitMixed = true;
$this->checkImplicitMixed = true;
$this->analyse([__DIR__ . '/data/bug-12015.php'], []);
}
public function testDynamicCall(): void
{
$this->checkThisOnly = false;
$this->checkExplicitMixed = true;
$this->checkImplicitMixed = true;
$this->analyse([__DIR__ . '/data/dynamic-call.php'], [
[
'Call to an undefined static method MethodsDynamicCall\Foo::bar().',
33,
],
[
'Call to an undefined static method MethodsDynamicCall\Foo::doBar().',
36,
],
[
'Call to an undefined static method MethodsDynamicCall\Foo::doBuz().',
36,
],
[
'Parameter #1 $n of method MethodsDynamicCall\Foo::doFoo() expects int, int|string given.',
58,
],
[
'Parameter #1 $s of static method MethodsDynamicCall\Foo::doQux() expects string, int given.',
59,
],
[
'Parameter #1 $n of method MethodsDynamicCall\Foo::doFoo() expects int, string given.',
60,
],
]);
}
}