@@ -458,41 +458,17 @@ public function equals(Type $type): bool
458458
459459 public function isCallable (): TrinaryLogic
460460 {
461- $ callableArray = $ this ->getClassOrObjectAndMethods ();
462- if ($ callableArray === []) {
461+ $ typeAndMethods = $ this ->findTypeAndMethodNames ();
462+ if ($ typeAndMethods === []) {
463463 return TrinaryLogic::createNo ();
464464 }
465465
466- [$ classOrObject , $ methods ] = $ callableArray ;
467- if (count ($ methods ->getConstantStrings ()) === 0 ) {
468- return TrinaryLogic::createMaybe ();
469- }
470-
471- $ type = $ classOrObject ->getObjectTypeOrClassStringObjectType ();
472- if (!$ type ->isObject ()->yes ()) {
473- return TrinaryLogic::createMaybe ();
474- }
475-
476- $ hasMethodTrinary = [];
477- $ phpVersion = PhpVersionStaticAccessor::getInstance ();
478- foreach ($ methods ->getConstantStrings () as $ method ) {
479- $ has = $ type ->hasMethod ($ method ->getValue ());
480-
481- if ($ has ->yes ()) {
482- if (!$ phpVersion ->supportsCallableInstanceMethods ()) {
483- $ methodReflection = $ type ->getMethod ($ method ->getValue (), new OutOfClassScope ());
484- if ($ classOrObject ->isString ()->yes () && !$ methodReflection ->isStatic ()) {
485- $ has = TrinaryLogic::createNo ();
486- }
487- } elseif ($ this ->isOptionalKey (0 ) || $ this ->isOptionalKey (1 )) {
488- $ has = $ has ->and (TrinaryLogic::createMaybe ());
489- }
490- }
491-
492- $ hasMethodTrinary [] = $ has ;
493- }
466+ $ results = array_map (
467+ static fn (ConstantArrayTypeAndMethod $ typeAndMethod ): TrinaryLogic => $ typeAndMethod ->getCertainty (),
468+ $ typeAndMethods ,
469+ );
494470
495- return TrinaryLogic::extremeIdentity (...$ hasMethodTrinary );
471+ return TrinaryLogic::extremeIdentity (...$ results );
496472 }
497473
498474 public function getCallableParametersAcceptors (ClassMemberAccessAnswerer $ scope ): array
@@ -606,25 +582,18 @@ public function findTypeAndMethodNames(): array
606582 $ phpVersion = PhpVersionStaticAccessor::getInstance ();
607583 foreach ($ methods ->getConstantStrings () as $ method ) {
608584 $ has = $ type ->hasMethod ($ method ->getValue ());
609- if ($ has ->no ()) {
610- continue ;
611- }
612585
613- if (
614- BleedingEdgeToggle::isBleedingEdge ()
615- && $ has -> yes ()
616- && !$ phpVersion -> supportsCallableInstanceMethods ()
617- ) {
618- $ methodReflection = $ type -> getMethod ( $ method -> getValue (), new OutOfClassScope ());
619- if ( $ classOrObject -> isString ()-> yes () && ! $ methodReflection -> isStatic ( )) {
620- continue ;
586+ if ($ has -> yes ()) {
587+ if ( BleedingEdgeToggle::isBleedingEdge () && ! $ phpVersion -> supportsCallableInstanceMethods ()) {
588+ $ methodReflection = $ type -> getMethod ( $ method -> getValue (), new OutOfClassScope ());
589+ if ( $ classOrObject -> isString ()-> yes () && !$ methodReflection -> isStatic ()) {
590+ $ has = TrinaryLogic:: createNo ();
591+ }
592+ } elseif ( $ this -> isOptionalKey ( 0 ) || $ this -> isOptionalKey ( 1 )) {
593+ $ has = $ has -> and (TrinaryLogic:: createMaybe ()) ;
621594 }
622595 }
623596
624- if ($ this ->isOptionalKey (0 ) || $ this ->isOptionalKey (1 )) {
625- $ has = $ has ->and (TrinaryLogic::createMaybe ());
626- }
627-
628597 $ typeAndMethods [] = ConstantArrayTypeAndMethod::createConcrete ($ type , $ method ->getValue (), $ has );
629598 }
630599
0 commit comments