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: Chris@0: /** Chris@0: * ReflectionClass::newInstance patch. Chris@0: * Makes first argument of newInstance optional, since it works but signature is misleading Chris@0: * Chris@0: * @author Florian Klein Chris@0: */ Chris@0: class ReflectionClassNewInstancePatch implements ClassPatchInterface Chris@0: { Chris@0: /** Chris@0: * Supports ReflectionClass 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 'ReflectionClass' === $node->getParentClass(); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Updates newInstance's first argument to make it optional Chris@0: * Chris@0: * @param ClassNode $node Chris@0: */ Chris@0: public function apply(ClassNode $node) Chris@0: { Chris@0: foreach ($node->getMethod('newInstance')->getArguments() as $argument) { Chris@0: $argument->setDefault(null); Chris@0: } Chris@0: } Chris@0: Chris@0: /** Chris@0: * Returns patch priority, which determines when patch will be applied. Chris@0: * Chris@0: * @return int Priority number (higher = earlier) Chris@0: */ Chris@0: public function getPriority() Chris@0: { Chris@0: return 50; Chris@0: } Chris@0: }