src/Eloquent/Typhoon/Generator/TyphaxASTGenerator.php
public function visitStringableType(StringableType $type)
    {
        $this->typeCheck->visitStringableType(func_get_args());

        $closure = new Closure;
        $closure->addParameter(new Parameter($this->valueIdentifier));
        $valueVariable = new Variable($this->valueIdentifier);

        $isStringCall = new Call(QualifiedIdentifier::fromString('\is_string'));
        $isStringCall->add($valueVariable);
        $isIntCall = new Call(QualifiedIdentifier::fromString('\is_int'));
        $isIntCall->add($valueVariable);
        $isFloatCall = new Call(QualifiedIdentifier::fromString('\is_float'));
        $isFloatCall->add($valueVariable);
        $stringablePrimitiveExpression = new LogicalOr(
            $isStringCall,
            $isIntCall
        );
        $stringablePrimitiveExpression->add($isFloatCall);
        $ifStatement = new IfStatement($stringablePrimitiveExpression);
        $ifStatement->trueBranch()->add(
            new ReturnStatement(new Literal(true))
        );
        $closure->statementBlock()->add($ifStatement);

        $isObjectCall = new Call(QualifiedIdentifier::fromString('\is_object'));
        $isObjectCall->add($valueVariable);
        $ifStatement = new IfStatement(new LogicalNot($isObjectCall));
        $ifStatement->trueBranch()->add(
            new ReturnStatement(new Literal(false))
        );
        $closure->statementBlock()->add($ifStatement);

        $newReflectorCall = new Call(QualifiedIdentifier::fromString('\ReflectionObject'));
        $newReflectorCall->add($valueVariable);
        $newReflector = new NewOperator($newReflectorCall);
        $reflectorVariable = new Variable(new Identifier('reflector'));
        $closure->statementBlock()->add(new ExpressionStatement(new Assign(
            $reflectorVariable,
            $newReflector
        )));

        $hasMethodCall = new Call(
            new Member(
                $reflectorVariable,
                new Constant(new Identifier('hasMethod'))
            )
        );
        $hasMethodCall->add(new Literal('__toString'));
        $closure->statementBlock()->add(new ReturnStatement($hasMethodCall));

        return $closure;
    }
public function visitStringableType(StringableType $type)
    {
        $this->typeCheck->visitStringableType(func_get_args());

        $closure = new Closure;
        $closure->addParameter(new Parameter($this->valueIdentifier));
        $valueVariable = new Variable($this->valueIdentifier);

        $isStringCall = new Call(QualifiedIdentifier::fromString('\is_string'));
        $isStringCall->add($valueVariable);
        $isIntCall = new Call(QualifiedIdentifier::fromString('\is_int'));
        $isIntCall->add($valueVariable);
        $isFloatCall = new Call(QualifiedIdentifier::fromString('\is_float'));
        $isFloatCall->add($valueVariable);
        $stringablePrimitiveExpression = new LogicalOr(
            $isStringCall,
            $isIntCall
        );
        $stringablePrimitiveExpression->add($isFloatCall);
        $ifStatement = new IfStatement($stringablePrimitiveExpression);
        $ifStatement->trueBranch()->add(
            new ReturnStatement(new Literal(true))
        );
        $closure->statementBlock()->add($ifStatement);

        $isObjectCall = new Call(QualifiedIdentifier::fromString('\is_object'));
        $isObjectCall->add($valueVariable);
        $ifStatement = new IfStatement(new LogicalNot($isObjectCall));
        $ifStatement->trueBranch()->add(
            new ReturnStatement(new Literal(false))
        );
        $closure->statementBlock()->add($ifStatement);

        $newReflectorCall = new Call(QualifiedIdentifier::fromString('\ReflectionObject'));
        $newReflectorCall->add($valueVariable);
        $newReflector = new NewOperator($newReflectorCall);
        $reflectorVariable = new Variable(new Identifier('reflector'));
        $closure->statementBlock()->add(new ExpressionStatement(new Assign(
            $reflectorVariable,
            $newReflector
        )));

        $hasMethodCall = new Call(
            new Member(
                $reflectorVariable,
                new Constant(new Identifier('hasMethod'))
            )
        );
        $hasMethodCall->add(new Literal('__toString'));
        $closure->statementBlock()->add(new ReturnStatement($hasMethodCall));

        return $closure;
    }
@param StringableType $type

@return Closure