Skip to content
This repository has been archived by the owner on Feb 20, 2023. It is now read-only.

Commit

Permalink
Closes #388
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Dec 2, 2017
1 parent a58b8fc commit 16b50f4
Showing 1 changed file with 1 addition and 33 deletions.
34 changes: 1 addition & 33 deletions src/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -1029,39 +1029,7 @@ private function generateMockedMethodDefinition($className, $methodName, $cloneA
*/
private function canMockMethod(ReflectionMethod $method)
{
return !($method->isConstructor() || $method->isFinal() || !$this->canReturnTypeBeStubbed($method) || $method->isPrivate() || $this->isMethodNameBlacklisted($method->getName()));
}

/**
* @param ReflectionMethod $method
*
* @return bool
*
* @throws \ReflectionException
*/
private function canReturnTypeBeStubbed(ReflectionMethod $method)
{
if (!$method->hasReturnType()) {
return true;
}

if (PHP_VERSION_ID >= 70100 && $method->getReturnType()->allowsNull()) {
return true;
}

$returnType = (string) $method->getReturnType();

if ($returnType === \Generator::class || $returnType === \Closure::class) {
return true;
}

if (\class_exists($returnType)) {
$class = new ReflectionClass($returnType);

return !$class->isFinal();
}

return true;
return !($method->isConstructor() || $method->isFinal() || $method->isPrivate() || $this->isMethodNameBlacklisted($method->getName()));
}

/**
Expand Down

0 comments on commit 16b50f4

Please sign in to comment.