src/Generator/OutputGeneratorTrait.php
protected function createResponseDenormalizationStatement($status, $schema, Context $context, $reference)
    {
        $jsonReference  = $reference;
        $array          = false;

        if ($schema instanceof Reference) {
            list($jsonReference, $schema) = $this->resolve($schema, Schema::class);
        }

        if ($schema instanceof Schema && $schema->getType() == "array") {
            $array = true;
            $jsonReference .= '/items';

            if ($schema->getItems() instanceof Reference) {
                list($jsonReference, ) = $this->resolve($schema->getItems(), Schema::class);
            }
        }

        $class = $context->getRegistry()->getClass($jsonReference);

        // Happens when reference resolve to a none object
        if ($class === null) {
            $returnType = 'null';
            $returnStmt = new Stmt\Return_(new Expr\ConstFetch(new Name('null')));
        } else {
            $class = $context->getRegistry()->getSchema($jsonReference)->getNamespace() . "\\Model\\" . $class->getName();

            if ($array) {
                $class .= "[]";
            }

            $returnType = "\\" . $class;
            $returnStmt = new Stmt\Return_(new Expr\MethodCall(
                new Expr\PropertyFetch(new Expr\Variable('this'), 'serializer'),
                'deserialize',
                [
                    new Arg(new Expr\Cast\String_(new Expr\MethodCall(new Expr\Variable('response'), 'getBody'))),
                    new Arg(new Scalar\String_($class)),
                    new Arg(new Scalar\String_('json'))
                ]
            ));
        }

        if ($status === 'default') {
            return [$returnType, $returnStmt];
        }

        return [$returnType, new Stmt\If_(
            new Expr\BinaryOp\Equal(
                new Scalar\String_($status),
                new Expr\MethodCall(new Expr\Variable('response'), 'getStatusCode')
            ),
            [
                'stmts' => [$returnStmt]
            ]
        )];
    }
protected function createResponseDenormalizationStatement($status, $schema, Context $context, $reference)
    {
        $jsonReference  = $reference;
        $array          = false;

        if ($schema instanceof Reference) {
            list($jsonReference, $schema) = $this->resolve($schema, Schema::class);
        }

        if ($schema instanceof Schema && $schema->getType() == "array") {
            $array = true;
            $jsonReference .= '/items';

            if ($schema->getItems() instanceof Reference) {
                list($jsonReference, ) = $this->resolve($schema->getItems(), Schema::class);
            }
        }

        $class = $context->getRegistry()->getClass($jsonReference);

        // Happens when reference resolve to a none object
        if ($class === null) {
            $returnType = 'null';
            $returnStmt = new Stmt\Return_(new Expr\ConstFetch(new Name('null')));
        } else {
            $class = $context->getRegistry()->getSchema($jsonReference)->getNamespace() . "\\Model\\" . $class->getName();

            if ($array) {
                $class .= "[]";
            }

            $returnType = "\\" . $class;
            $returnStmt = new Stmt\Return_(new Expr\MethodCall(
                new Expr\PropertyFetch(new Expr\Variable('this'), 'serializer'),
                'deserialize',
                [
                    new Arg(new Expr\Cast\String_(new Expr\MethodCall(new Expr\Variable('response'), 'getBody'))),
                    new Arg(new Scalar\String_($class)),
                    new Arg(new Scalar\String_('json'))
                ]
            ));
        }

        if ($status === 'default') {
            return [$returnType, $returnStmt];
        }

        return [$returnType, new Stmt\If_(
            new Expr\BinaryOp\Equal(
                new Scalar\String_($status),
                new Expr\MethodCall(new Expr\Variable('response'), 'getStatusCode')
            ),
            [
                'stmts' => [$returnStmt]
            ]
        )];
    }
@param         $status
@param         $schema
@param Context $context

@return [string, null|Stmt\If_]