Skip to content

Commit

Permalink
fixed regression (#453)
Browse files Browse the repository at this point in the history
  • Loading branch information
staabm authored Nov 1, 2022
1 parent f9d94b1 commit 209142a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
8 changes: 7 additions & 1 deletion src/Rules/QueryPlanAnalyzerRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,19 +67,25 @@ public function processNode(Node $callLike, Scope $scope): array
}

$queryArgPosition = null;
$unsupportedMethod = true;
foreach ($this->classMethods as $classMethod) {
sscanf($classMethod, '%[^::]::%[^#]#%i', $className, $methodName, $queryArgPosition);
if (!\is_string($className) || !\is_string($methodName) || !\is_int($queryArgPosition)) {
throw new ShouldNotHappenException('Invalid classMethod definition');
}

if ($methodName === $methodReflection->getName() &&
($methodReflection->getDeclaringClass()->getName() === $className || $methodReflection->getDeclaringClass()->isSubclassOf($className))) {
($methodReflection->getDeclaringClass()->getName() === $className || $methodReflection->getDeclaringClass()->isSubclassOf($className))
) {
$unsupportedMethod = false;
break;
}
}

if (null === $queryArgPosition) {
throw new ShouldNotHappenException('Invalid classMethod definition');
}
if ($unsupportedMethod) {
return [];
}

Expand Down
5 changes: 5 additions & 0 deletions src/Rules/SyntaxErrorInQueryFunctionRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,18 +59,23 @@ public function processNode(Node $node, Scope $scope): array
}

$queryArgPosition = null;
$unsupportedFunction = true;
foreach ($this->functionNames as $functionName) {
sscanf($functionName, '%[^#]#%i', $functionName, $queryArgPosition);
if (!\is_string($functionName) || !\is_int($queryArgPosition)) {
throw new ShouldNotHappenException('Invalid functionName definition');
}

if (strtolower($functionName) === strtolower($calledFunctionName)) {
$unsupportedFunction = false;
break;
}
}

if (null === $queryArgPosition) {
throw new ShouldNotHappenException('Invalid classMethod definition');
}
if ($unsupportedFunction) {
return [];
}

Expand Down
8 changes: 7 additions & 1 deletion src/Rules/SyntaxErrorInQueryMethodRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,25 @@ public function processNode(Node $node, Scope $scope): array
}

$queryArgPosition = null;
$unsupportedMethod = true;
foreach ($this->classMethods as $classMethod) {
sscanf($classMethod, '%[^::]::%[^#]#%i', $className, $methodName, $queryArgPosition);
if (!\is_string($className) || !\is_string($methodName) || !\is_int($queryArgPosition)) {
throw new ShouldNotHappenException('Invalid classMethod definition');
}

if ($methodName === $methodReflection->getName() &&
($methodReflection->getDeclaringClass()->getName() === $className || $methodReflection->getDeclaringClass()->isSubclassOf($className))) {
($methodReflection->getDeclaringClass()->getName() === $className || $methodReflection->getDeclaringClass()->isSubclassOf($className))
) {
$unsupportedMethod = false;
break;
}
}

if (null === $queryArgPosition) {
throw new ShouldNotHappenException('Invalid classMethod definition');
}
if ($unsupportedMethod) {
return [];
}

Expand Down

0 comments on commit 209142a

Please sign in to comment.