Skip to content

Commit

Permalink
Merge pull request #618 from jdreesen/patch-1
Browse files Browse the repository at this point in the history
Fix generation of enum default values with PHP 8.1
  • Loading branch information
stof committed Mar 29, 2024
2 parents 061a2fd + 310ddfe commit f9e07be
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/Prophecy/Doubler/Generator/ClassCodeGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,14 @@ private function generateArguments(array $arguments): array
$php .= '$'.$argument->getName();

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

// This is necessary for PHP 8.1, as enum cases are exported without a leading slash in this version
if ($argument->getDefault() instanceof \UnitEnum && 0 !== strpos($default, '\\')) {
$default = '\\'.$default;
}

$php .= ' = '.$default;
}

return $php;
Expand Down

0 comments on commit f9e07be

Please sign in to comment.