Chris@0: Chris@0: * Marcello Duarte Chris@0: * Chris@0: * For the full copyright and license information, please view the LICENSE Chris@0: * file that was distributed with this source code. Chris@0: */ Chris@0: Chris@0: namespace Prophecy\Doubler\ClassPatch; Chris@0: Chris@0: use Prophecy\Doubler\Generator\Node\ClassNode; Chris@0: use Prophecy\Doubler\Generator\Node\MethodNode; Chris@0: Chris@0: /** Chris@0: * Disable constructor. Chris@0: * Makes all constructor arguments optional. Chris@0: * Chris@0: * @author Konstantin Kudryashov Chris@0: */ Chris@0: class DisableConstructorPatch implements ClassPatchInterface Chris@0: { Chris@0: /** Chris@0: * Checks if class has `__construct` method. Chris@0: * Chris@0: * @param ClassNode $node Chris@0: * Chris@0: * @return bool Chris@0: */ Chris@0: public function supports(ClassNode $node) Chris@0: { Chris@0: return true; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Makes all class constructor arguments optional. Chris@0: * Chris@0: * @param ClassNode $node Chris@0: */ Chris@0: public function apply(ClassNode $node) Chris@0: { Chris@0: if (!$node->hasMethod('__construct')) { Chris@0: $node->addMethod(new MethodNode('__construct', '')); Chris@0: Chris@0: return; Chris@0: } Chris@0: Chris@0: $constructor = $node->getMethod('__construct'); Chris@0: foreach ($constructor->getArguments() as $argument) { Chris@0: $argument->setDefault(null); Chris@0: } Chris@0: Chris@0: $constructor->setCode(<<