/** * @param ContextInterface $context * @param ClassGenerator $class * @param Property $property * * @throws \Zend\Code\Generator\Exception\InvalidArgumentException */ private function implementGetResult(ContextInterface $context, ClassGenerator $class, Property $property) { $useAssembler = new UseAssembler($this->wrapperClass ?: ResultInterface::class); if ($useAssembler->canAssemble($context)) { $useAssembler->assemble($context); } $methodName = 'getResult'; $class->removeMethod($methodName); $class->addMethodFromGenerator(MethodGenerator::fromArray(['name' => $methodName, 'parameters' => [], 'visibility' => MethodGenerator::VISIBILITY_PUBLIC, 'body' => $this->generateGetResultBody($property), 'docblock' => DocBlockGenerator::fromArray(['tags' => [['name' => 'return', 'description' => $this->generateGetResultReturnTag($property)]]])])); }
/** * @param ClassGenerator $class * @param Property $firstProperty * * @throws \Zend\Code\Generator\Exception\InvalidArgumentException */ private function implementGetIterator($class, $firstProperty) { $methodName = 'getIterator'; $class->removeMethod($methodName); $class->addMethodFromGenerator(MethodGenerator::fromArray(['name' => $methodName, 'parameters' => [], 'visibility' => MethodGenerator::VISIBILITY_PUBLIC, 'body' => sprintf('return new \\ArrayIterator(is_array($this->%1$s) ? $this->%1$s : []);', $firstProperty->getName()), 'docblock' => DocBlockGenerator::fromArray(['tags' => [['name' => 'return', 'description' => '\\ArrayIterator']]])])); }
public function testRemoveMethod() { $classGenerator = new ClassGenerator(); $classGenerator->addMethod('methodOne'); $this->assertTrue($classGenerator->hasMethod('methodOne')); $classGenerator->removeMethod('methodOne'); $this->assertFalse($classGenerator->hasMethod('methodOne')); }
public function testRemoveMethodInsensitive() { $classGenerator = new ClassGenerator(); $classGenerator->addMethod('methodOne'); $classGenerator->removeMethod('METHODONe'); $this->assertFalse($classGenerator->hasMethod('methodOne')); }