Skip to content

Commit 58de58f

Browse files
Another solution
1 parent 980ccc1 commit 58de58f

File tree

2 files changed

+32
-13
lines changed

2 files changed

+32
-13
lines changed

src/Type/Constant/ConstantArrayType.php

+29-13
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ public function equals(Type $type): bool
458458

459459
public function isCallable(): TrinaryLogic
460460
{
461-
$typeAndMethods = $this->findTypeAndMethodNames(false);
461+
$typeAndMethods = $this->findTypeAndMethodNames();
462462
if ($typeAndMethods === []) {
463463
return TrinaryLogic::createNo();
464464
}
@@ -468,7 +468,19 @@ public function isCallable(): TrinaryLogic
468468
$typeAndMethods,
469469
);
470470

471-
return TrinaryLogic::extremeIdentity(...$results);
471+
$isCallable = TrinaryLogic::createYes()->and(...$results);
472+
if ($isCallable->yes()) {
473+
$callableArray = $this->getClassOrObjectAndMethods();
474+
if ($callableArray !== []) {
475+
[$classOrObject, $methods] = $callableArray;
476+
477+
if (count($methods->getConstantStrings()) !== count($typeAndMethods)) {
478+
return TrinaryLogic::createMaybe();
479+
}
480+
}
481+
}
482+
483+
return $isCallable;
472484
}
473485

474486
public function getCallableParametersAcceptors(ClassMemberAccessAnswerer $scope): array
@@ -561,7 +573,7 @@ public function findTypeAndMethodName(): ?ConstantArrayTypeAndMethod
561573
}
562574

563575
/** @return ConstantArrayTypeAndMethod[] */
564-
public function findTypeAndMethodNames(bool $atLeastMaybe = true): array
576+
public function findTypeAndMethodNames(): array
565577
{
566578
$callableArray = $this->getClassOrObjectAndMethods();
567579
if ($callableArray === []) {
@@ -582,21 +594,25 @@ public function findTypeAndMethodNames(bool $atLeastMaybe = true): array
582594
$phpVersion = PhpVersionStaticAccessor::getInstance();
583595
foreach ($methods->getConstantStrings() as $method) {
584596
$has = $type->hasMethod($method->getValue());
597+
if ($has->no()) {
598+
continue;
599+
}
585600

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());
601+
if (
602+
BleedingEdgeToggle::isBleedingEdge()
603+
&& $has->yes()
604+
&& !$phpVersion->supportsCallableInstanceMethods()
605+
) {
606+
$methodReflection = $type->getMethod($method->getValue(), new OutOfClassScope());
607+
if ($classOrObject->isString()->yes() && !$methodReflection->isStatic()) {
608+
continue;
594609
}
595610
}
596611

597-
if ($atLeastMaybe && $has->no()) {
598-
continue;
612+
if ($this->isOptionalKey(0) || $this->isOptionalKey(1)) {
613+
$has = $has->and(TrinaryLogic::createMaybe());
599614
}
615+
600616
$typeAndMethods[] = ConstantArrayTypeAndMethod::createConcrete($type, $method->getValue(), $has);
601617
}
602618

src/Type/Constant/ConstantArrayTypeAndMethod.php

+3
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ public static function createConcrete(
2727
TrinaryLogic $certainty,
2828
): self
2929
{
30+
if ($certainty->no()) {
31+
throw new ShouldNotHappenException();
32+
}
3033
return new self($type, $method, $certainty);
3134
}
3235

0 commit comments

Comments
 (0)