@@ -589,4 +589,81 @@ public function testResolveTemplateTypes(Type $received, Type $template, array $
589589 );
590590 }
591591
592+ /**
593+ * @dataProvider dataIsCallable
594+ * @group solo
595+ */
596+ public function testIsCallable (ConstantArrayType $ type , TrinaryLogic $ expectedResult ): void
597+ {
598+ $ actualResult = $ type ->isCallable ();
599+ $ this ->assertSame (
600+ $ expectedResult ->describe (),
601+ $ actualResult ->describe (),
602+ sprintf ('%s -> isCallable() ' , $ type ->describe (VerbosityLevel::precise ()))
603+ );
604+ }
605+
606+ public function dataIsCallable (): iterable
607+ {
608+ yield 'zero items ' => [
609+ new ConstantArrayType ([], []),
610+ TrinaryLogic::createNo (),
611+ ];
612+
613+ yield 'function name ' => [
614+ new ConstantArrayType ([
615+ new ConstantIntegerType (0 ),
616+ ], [
617+ new ConstantStringType ('strlen ' ),
618+ ]),
619+ TrinaryLogic::createNo (),
620+ ];
621+
622+ yield 'existing static method ' => [
623+ new ConstantArrayType ([
624+ new ConstantIntegerType (0 ),
625+ new ConstantIntegerType (1 ),
626+ ], [
627+ new ConstantStringType (\Closure::class, true ),
628+ new ConstantStringType ('bind ' ),
629+ ]),
630+ TrinaryLogic::createYes (),
631+ ];
632+
633+ yield 'non-existing static method ' => [
634+ new ConstantArrayType ([
635+ new ConstantIntegerType (0 ),
636+ new ConstantIntegerType (1 ),
637+ ], [
638+ new ConstantStringType (\Closure::class, true ),
639+ new ConstantStringType ('foobar ' ),
640+ ]),
641+ TrinaryLogic::createNo (),
642+ ];
643+
644+ /**
645+ * @see https://github.com/phpstan/phpstan/issues/3428
646+ */
647+ yield 'existing static method but not a class string ' => [
648+ new ConstantArrayType ([
649+ new ConstantIntegerType (0 ),
650+ new ConstantIntegerType (1 ),
651+ ], [
652+ new ConstantStringType ('Closure ' ),
653+ new ConstantStringType ('foobar ' ),
654+ ]),
655+ TrinaryLogic::createMaybe (),
656+ ];
657+
658+ yield 'existing static method but with string keys ' => [
659+ new ConstantArrayType ([
660+ new ConstantStringType ('a ' ),
661+ new ConstantStringType ('b ' ),
662+ ], [
663+ new ConstantStringType (\Closure::class, true ),
664+ new ConstantStringType ('bind ' ),
665+ ]),
666+ TrinaryLogic::createNo (),
667+ ];
668+ }
592669}
0 commit comments