public function DisableConstructorPatch::apply in Zircon Profile 8.0
Same name and namespace in other branches
- 8 vendor/phpspec/prophecy/src/Prophecy/Doubler/ClassPatch/DisableConstructorPatch.php \Prophecy\Doubler\ClassPatch\DisableConstructorPatch::apply()
Makes all class constructor arguments optional.
Parameters
ClassNode $node:
Overrides ClassPatchInterface::apply
File
- vendor/
phpspec/ prophecy/ src/ Prophecy/ Doubler/ ClassPatch/ DisableConstructorPatch.php, line 42
Class
- DisableConstructorPatch
- Disable constructor. Makes all constructor arguments optional.
Namespace
Prophecy\Doubler\ClassPatchCode
public function apply(ClassNode $node) {
if (!$node
->hasMethod('__construct')) {
$node
->addMethod(new MethodNode('__construct', ''));
return;
}
$constructor = $node
->getMethod('__construct');
foreach ($constructor
->getArguments() as $argument) {
$argument
->setDefault(null);
}
$constructor
->setCode(<<<PHP
if (0 < func_num_args()) {
call_user_func_array(array('parent', '__construct'), func_get_args());
}
PHP
);
}