Skip to content

Commit

Permalink
Prevent crashes for unknown classes
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Mar 11, 2019
1 parent f7ce984 commit 6f599c2
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 16 deletions.
4 changes: 4 additions & 0 deletions src/Rules/Doctrine/ORM/MagicRepositoryMethodCallRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ public function processNode(Node $node, Scope $scope): array
}

$methodName = $methodNameIdentifier->toString();
if (!$this->broker->hasClass($calledOnType->getClassName())) {
return [];
}

$repositoryReflectionClass = $this->broker->getClass($calledOnType->getClassName());
if ($repositoryReflectionClass->hasNativeMethod($methodName)) {
return [];
Expand Down
34 changes: 18 additions & 16 deletions src/Type/Doctrine/ObjectRepositoryDynamicReturnTypeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,24 +53,26 @@ public function getTypeFromMethodCall(
}

$methodName = $methodReflection->getName();
$repositoryClassReflection = $this->broker->getClass($calledOnType->getClassName());
if (
(
if ($this->broker->hasClass($calledOnType->getClassName())) {
$repositoryClassReflection = $this->broker->getClass($calledOnType->getClassName());
if (
(
strpos($methodName, 'findBy') === 0
&& strlen($methodName) > strlen('findBy')
) || (
strpos($methodName, 'findOneBy') === 0
&& strlen($methodName) > strlen('findOneBy')
(
strpos($methodName, 'findBy') === 0
&& strlen($methodName) > strlen('findBy')
) || (
strpos($methodName, 'findOneBy') === 0
&& strlen($methodName) > strlen('findOneBy')
)
)
)
&& $repositoryClassReflection->hasNativeMethod($methodName)
) {
return ParametersAcceptorSelector::selectFromArgs(
$scope,
$methodCall->args,
$repositoryClassReflection->getNativeMethod($methodName)->getVariants()
)->getReturnType();
&& $repositoryClassReflection->hasNativeMethod($methodName)
) {
return ParametersAcceptorSelector::selectFromArgs(
$scope,
$methodCall->args,
$repositoryClassReflection->getNativeMethod($methodName)->getVariants()
)->getReturnType();
}
}

if (!$calledOnType instanceof ObjectRepositoryType) {
Expand Down

0 comments on commit 6f599c2

Please sign in to comment.