Skip to content

Commit

Permalink
Another solution
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentLanglet committed Nov 19, 2024
1 parent 980ccc1 commit 0c165ad
Showing 1 changed file with 29 additions and 13 deletions.
42 changes: 29 additions & 13 deletions src/Type/Constant/ConstantArrayType.php
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ public function equals(Type $type): bool

public function isCallable(): TrinaryLogic
{
$typeAndMethods = $this->findTypeAndMethodNames(false);
$typeAndMethods = $this->findTypeAndMethodNames();
if ($typeAndMethods === []) {
return TrinaryLogic::createNo();
}
Expand All @@ -468,7 +468,19 @@ public function isCallable(): TrinaryLogic
$typeAndMethods,
);

return TrinaryLogic::extremeIdentity(...$results);
$isCallable = TrinaryLogic::createYes()->and(...$results);
if ($isCallable->yes()) {
$callableArray = $this->getClassOrObjectAndMethods();
if ($callableArray !== []) {
[$classOrObject, $methods] = $callableArray;

if (count($methods->getConstantStrings()) !== count($typeAndMethods)) {
return TrinaryLogic::createMaybe();
}
}
}

return $isCallable;
}

public function getCallableParametersAcceptors(ClassMemberAccessAnswerer $scope): array
Expand Down Expand Up @@ -561,7 +573,7 @@ public function findTypeAndMethodName(): ?ConstantArrayTypeAndMethod
}

/** @return ConstantArrayTypeAndMethod[] */
public function findTypeAndMethodNames(bool $atLeastMaybe = true): array
public function findTypeAndMethodNames(): array
{
$callableArray = $this->getClassOrObjectAndMethods();
if ($callableArray === []) {
Expand All @@ -582,21 +594,25 @@ public function findTypeAndMethodNames(bool $atLeastMaybe = true): array
$phpVersion = PhpVersionStaticAccessor::getInstance();
foreach ($methods->getConstantStrings() as $method) {
$has = $type->hasMethod($method->getValue());
if ($has->no()) {
continue;
}

if ($has->yes()) {
if (BleedingEdgeToggle::isBleedingEdge() && !$phpVersion->supportsCallableInstanceMethods()) {
$methodReflection = $type->getMethod($method->getValue(), new OutOfClassScope());
if ($classOrObject->isString()->yes() && !$methodReflection->isStatic()) {
$has = TrinaryLogic::createNo();
}
} elseif ($this->isOptionalKey(0) || $this->isOptionalKey(1)) {
$has = $has->and(TrinaryLogic::createMaybe());
if (
BleedingEdgeToggle::isBleedingEdge()
&& $has->yes()
&& !$phpVersion->supportsCallableInstanceMethods()
) {
$methodReflection = $type->getMethod($method->getValue(), new OutOfClassScope());
if ($classOrObject->isString()->yes() && !$methodReflection->isStatic()) {
continue;
}
}

if ($atLeastMaybe && $has->no()) {
continue;
if ($this->isOptionalKey(0) || $this->isOptionalKey(1)) {
$has = $has->and(TrinaryLogic::createMaybe());
}

$typeAndMethods[] = ConstantArrayTypeAndMethod::createConcrete($type, $method->getValue(), $has);
}

Expand Down

0 comments on commit 0c165ad

Please sign in to comment.