4 * This file is part of the Prophecy.
5 * (c) Konstantin Kudryashov <ever.zet@gmail.com>
6 * Marcello Duarte <marcello.duarte@gmail.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Prophecy\Doubler\ClassPatch;
14 use Prophecy\Doubler\Generator\Node\ClassNode;
15 use Prophecy\Doubler\Generator\Node\MethodNode;
18 * Disable constructor.
19 * Makes all constructor arguments optional.
21 * @author Konstantin Kudryashov <ever.zet@gmail.com>
23 class DisableConstructorPatch implements ClassPatchInterface
26 * Checks if class has `__construct` method.
28 * @param ClassNode $node
32 public function supports(ClassNode $node)
38 * Makes all class constructor arguments optional.
40 * @param ClassNode $node
42 public function apply(ClassNode $node)
44 if (!$node->hasMethod('__construct')) {
45 $node->addMethod(new MethodNode('__construct', ''));
50 $constructor = $node->getMethod('__construct');
51 foreach ($constructor->getArguments() as $argument) {
52 $argument->setDefault(null);
55 $constructor->setCode(<<<PHP
56 if (0 < func_num_args()) {
57 call_user_func_array(array('parent', '__construct'), func_get_args());
64 * Returns patch priority, which determines when patch will be applied.
66 * @return int Priority number (higher - earlier)
68 public function getPriority()