Skip to content

Commit c619238

Browse files
committed
Void methods were breaking Interceptor classes due to a return statement. PHP7.2 forbids the presence of a return statement with parameters in void methods, even if returning null.
1 parent 169b3eb commit c619238

File tree

3 files changed

+25
-4
lines changed

3 files changed

+25
-4
lines changed

lib/internal/Magento/Framework/Interception/Code/Generator/Interceptor.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,17 +102,20 @@ protected function _getMethodInfo(\ReflectionMethod $method)
102102
$parameters[] = $this->_getMethodParameterInfo($parameter);
103103
}
104104

105+
// Void methods must not use the return statement with any value
106+
$return = ((string) $method->getReturnType() === 'void') ? '' : 'return ';
107+
105108
$methodInfo = [
106109
'name' => ($method->returnsReference() ? '& ' : '') . $method->getName(),
107110
'parameters' => $parameters,
108111
'body' => "\$pluginInfo = \$this->pluginList->getNext(\$this->subjectType, '{$method->getName()}');\n" .
109112
"if (!\$pluginInfo) {\n" .
110-
" return parent::{$method->getName()}({$this->_getParameterList(
113+
" {$return}parent::{$method->getName()}({$this->_getParameterList(
111114
$parameters
112115
)});\n" .
113-
"} else {\n" .
114-
" return \$this->___callPlugins('{$method->getName()}', func_get_args(), \$pluginInfo);\n" .
115-
"}",
116+
"} else {\n" .
117+
" {$return}\$this->___callPlugins('{$method->getName()}', func_get_args(), \$pluginInfo);\n" .
118+
"}",
116119
'returnType' => $method->getReturnType(),
117120
'docblock' => ['shortDescription' => '{@inheritdoc}'],
118121
];

lib/internal/Magento/Framework/Interception/Test/Unit/Code/Generator/_files/TInterceptor.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,19 @@ class Interceptor extends \Magento\Framework\Interception\Code\Generator\TSample
1212
$this->___init();
1313
}
1414

15+
/**
16+
* {@inheritdoc}
17+
*/
18+
public function returnVoid() : void
19+
{
20+
$pluginInfo = $this->pluginList->getNext($this->subjectType, 'returnVoid');
21+
if (!$pluginInfo) {
22+
parent::returnVoid();
23+
} else {
24+
$this->___callPlugins('returnVoid', func_get_args(), $pluginInfo);
25+
}
26+
}
27+
1528
/**
1629
* {@inheritdoc}
1730
*/

lib/internal/Magento/Framework/Interception/Test/Unit/Code/Generator/_files/TSample.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ class TSample
1010
private $value;
1111
private $variadicValue;
1212

13+
public function returnVoid() : void
14+
{
15+
// Nothing to do here
16+
}
17+
1318
public function getValue() : string
1419
{
1520
return $this->value;

0 commit comments

Comments
 (0)