Goetas\Xsd\XsdToPhp\Php\ClassGenerator::handleGetter PHP Method

handleGetter() private method

private handleGetter ( ClassGenerator $generator, Goetas\Xsd\XsdToPhp\Php\Structure\PHPProperty $prop, PHPClass $class )
$generator Zend\Code\Generator\ClassGenerator
$prop Goetas\Xsd\XsdToPhp\Php\Structure\PHPProperty
$class Goetas\Xsd\XsdToPhp\Php\Structure\PHPClass
    private function handleGetter(Generator\ClassGenerator $generator, PHPProperty $prop, PHPClass $class)
    {
        if ($prop->getType() instanceof PHPClassOf) {
            $docblock = new DocBlockGenerator();
            $docblock->setShortDescription("isset " . $prop->getName());
            if ($prop->getDoc()) {
                $docblock->setLongDescription($prop->getDoc());
            }
            $patramTag = new ParamTag("index", "scalar");
            $docblock->setTag($patramTag);
            $docblock->setTag(new ReturnTag("boolean"));
            $paramIndex = new ParameterGenerator("index", "mixed");
            $method = new MethodGenerator("isset" . Inflector::classify($prop->getName()), [$paramIndex]);
            $method->setDocBlock($docblock);
            $method->setBody("return isset(\$this->" . $prop->getName() . "[\$index]);");
            $generator->addMethodFromGenerator($method);
            $docblock = new DocBlockGenerator();
            $docblock->setShortDescription("unset " . $prop->getName());
            if ($prop->getDoc()) {
                $docblock->setLongDescription($prop->getDoc());
            }
            $patramTag = new ParamTag("index", "scalar");
            $docblock->setTag($patramTag);
            $paramIndex = new ParameterGenerator("index", "mixed");
            $docblock->setTag(new ReturnTag("void"));
            $method = new MethodGenerator("unset" . Inflector::classify($prop->getName()), [$paramIndex]);
            $method->setDocBlock($docblock);
            $method->setBody("unset(\$this->" . $prop->getName() . "[\$index]);");
            $generator->addMethodFromGenerator($method);
        }
        // ////
        $docblock = new DocBlockGenerator();
        $docblock->setShortDescription("Gets as " . $prop->getName());
        if ($prop->getDoc()) {
            $docblock->setLongDescription($prop->getDoc());
        }
        $tag = new ReturnTag("mixed");
        $type = $prop->getType();
        if ($type && $type instanceof PHPClassOf) {
            $tt = $type->getArg()->getType();
            $tag->setTypes($this->getPhpType($tt) . "[]");
            if ($p = $this->isOneType($tt)) {
                if ($t = $p->getType()) {
                    $tag->setTypes($this->getPhpType($t) . "[]");
                }
            }
        } elseif ($type) {
            if ($p = $this->isOneType($type)) {
                if ($t = $p->getType()) {
                    $tag->setTypes($this->getPhpType($t));
                }
            } else {
                $tag->setTypes($this->getPhpType($type));
            }
        }
        $docblock->setTag($tag);
        $method = new MethodGenerator("get" . Inflector::classify($prop->getName()));
        $method->setDocBlock($docblock);
        $method->setBody("return \$this->" . $prop->getName() . ";");
        $generator->addMethodFromGenerator($method);
    }