Skip to content

Commit f934d91

Browse files
SerafimArtslisachenko
authored andcommitted
Fix error when there are default values for arguments
1 parent 0888578 commit f934d91

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

src/Aspect/AbstractContractAspect.php

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,22 @@ public function __construct(Reader $reader)
3939
*/
4040
protected function fetchMethodArguments(MethodInvocation $invocation)
4141
{
42-
$parameters = $invocation->getMethod()->getParameters();
43-
$argumentNames = array_map(function (\ReflectionParameter $parameter) {
44-
return $parameter->name;
45-
}, $parameters);
46-
$parameters = array_combine($argumentNames, $invocation->getArguments());
42+
$result = [];
43+
$parameters = $invocation->getMethod()->getParameters();
44+
$argumentValues = $invocation->getArguments();
4745

48-
return $parameters;
46+
// Number of arguments can be less than number of parameters because of default values
47+
foreach ($parameters as $parameterIndex => $reflectionParameter) {
48+
$hasArgumentValue = array_key_exists($parameterIndex, $argumentValues);
49+
$argumentValue = $hasArgumentValue ? $argumentValues[$parameterIndex] : null;
50+
if (!$hasArgumentValue && $reflectionParameter->isDefaultValueAvailable()) {
51+
$argumentValue = $reflectionParameter->getDefaultValue();
52+
}
53+
$result[$reflectionParameter->name] = $argumentValue;
54+
55+
}
56+
57+
return $result;
4958
}
5059

5160
/**

0 commit comments

Comments
 (0)