Skip to content

Commit

Permalink
Fallback to null when argument default value is an object
Browse files Browse the repository at this point in the history
  • Loading branch information
Jean85 committed Jan 24, 2024
1 parent 3e7dd4b commit 7d6edbe
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
4 changes: 3 additions & 1 deletion spec/Prophecy/Doubler/Generator/ClassCodeGeneratorSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -459,9 +459,11 @@ function it_generates_correct_code_if_argument_default_value_is_an_object(
$expected =<<<'PHP'
namespace {
class CustomClass extends \ClassWithArgument implements \Prophecy\Doubler\Generator\MirroredInterface {
public function foo(\DateTimeInterface $arg = NULL) {
public function foo(\DateTimeInterface $arg = NULL) {
}
}
}
PHP;
Expand Down
7 changes: 6 additions & 1 deletion src/Prophecy/Doubler/Generator/ClassCodeGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,12 @@ private function generateArguments(array $arguments): array
$php .= '$'.$argument->getName();

if ($argument->isOptional() && !$argument->isVariadic()) {
$php .= ' = '.var_export($argument->getDefault(), true);
$default = $argument->getDefault();
if (is_object($argument->getDefault())) {
$default = null;
}

$php .= ' = '.var_export($default, true);
}

return $php;
Expand Down

0 comments on commit 7d6edbe

Please sign in to comment.