/** * @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']]])])); }
/** * @param Property $property * * @return string */ private function generateGetResultBody(Property $property) { if ($this->wrapperClass === null) { return sprintf('return $this->%s;', $property->getName()); } return sprintf('return new %s($this->%s);', Normalizer::getClassNameFromFQN($this->wrapperClass), $property->getName()); }