Skip to content

Commit ecadbdc

Browse files
committedMay 24, 2023
Fix generating default values
1 parent d93bd79 commit ecadbdc

File tree

2 files changed

+11
-39
lines changed

2 files changed

+11
-39
lines changed
 

‎src/ProxyManager/Generator/ClassGenerator.php

+2-36
Original file line numberDiff line numberDiff line change
@@ -5,48 +5,14 @@
55
namespace ProxyManager\Generator;
66

77
use Laminas\Code\Generator\ClassGenerator as LaminasClassGenerator;
8-
use ReflectionParameter;
9-
10-
use function method_exists;
118

129
/**
1310
* Class generator that ensures that interfaces/classes that are implemented/extended are FQCNs
1411
*
1512
* @internal do not use this in your code: it is only here for internal use
13+
* @deprecated this class was in use due to parent implementation not receiving prompt bugfixes, but
14+
* `laminas/laminas-code` is actively maintained and receives quick release iterations.
1615
*/
1716
class ClassGenerator extends LaminasClassGenerator
1817
{
19-
public function generate(): string
20-
{
21-
$extendedClass = $this->getExtendedClass();
22-
23-
foreach ($this->getMethods() as $method) {
24-
$class = $extendedClass;
25-
26-
if ($class === null) {
27-
foreach ($this->getImplementedInterfaces() as $interface) {
28-
if (method_exists($interface, $method->getName())) {
29-
$class = $interface;
30-
break;
31-
}
32-
}
33-
}
34-
35-
if ($class === null || ! method_exists($class, $method->getName())) {
36-
continue;
37-
}
38-
39-
foreach ($method->getParameters() as $parameter) {
40-
$default = $parameter->getDefaultValue();
41-
42-
if ($default === null) {
43-
continue;
44-
}
45-
46-
$parameter->setDefaultValue(new ValueGenerator($default, new ReflectionParameter([$class, $method->getName()], $parameter->getName())));
47-
}
48-
}
49-
50-
return parent::generate();
51-
}
5218
}

‎src/ProxyManager/Generator/MethodGenerator.php

+9-3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Laminas\Code\Reflection\MethodReflection;
1111
use ReflectionException;
1212
use ReflectionMethod;
13+
use ReflectionParameter;
1314

1415
/**
1516
* Method generator that fixes minor quirks in ZF2's method generator
@@ -61,9 +62,14 @@ public static function copyMethodSignature(MethodReflection $reflectionMethod):
6162
$method = parent::copyMethodSignature($reflectionMethod);
6263

6364
foreach ($reflectionMethod->getParameters() as $reflectionParameter) {
64-
$method->setParameter(
65-
ParameterGenerator::fromReflection($reflectionParameter)
66-
);
65+
$parameter = ParameterGenerator::fromReflection($reflectionParameter);
66+
$default = $parameter->getDefaultValue();
67+
68+
if ($default !== null) {
69+
$parameter->setDefaultValue(new ValueGenerator($default, $reflectionParameter));
70+
}
71+
72+
$method->setParameter($parameter);
6773
}
6874

6975
return $method;

0 commit comments

Comments
 (0)
Please sign in to comment.