src/Eloquent/Typhoon/Generator/FacadeGenerator.php
protected function generateCreateValidatorMethod(
        RuntimeConfiguration $configuration
    ) {
        $this->typeCheck->generateCreateValidatorMethod(func_get_args());

        $classNameIdentifier = new Identifier('className');
        $classNameVariable = new Variable($classNameIdentifier);
        $validatorClassNameVariable = new Variable(new Identifier('validatorClassName'));

        $method = new ConcreteMethod(
            new Identifier('createValidator'),
            AccessModifier::PROTECTED_(),
            true
        );
        $method->addParameter(new Parameter($classNameIdentifier));

        $validatorClassNameConcatenation = new Concat(
            new Literal(sprintf(
                '%s\\',
                $configuration
                    ->validatorNamespace()
                    ->joinAtoms('Validator')
                    ->string()
            )),
            $classNameVariable
        );
        $validatorClassNameConcatenation->add(new Literal('TypeCheck'));
        $method->statementBlock()->add(new ExpressionStatement(new Assign(
            $validatorClassNameVariable,
            $validatorClassNameConcatenation
        )));

        $staticConstant = new Constant(new Identifier('static'));
        $runtimeGenerationCall = new Call(new StaticMember(
            $staticConstant,
            new Constant(new Identifier('runtimeGeneration'))
        ));
        $classExistsCall = new Call(QualifiedIdentifier::fromString('\class_exists'));
        $classExistsCall->add($validatorClassNameVariable);
        $runtimeGenerationIf = new IfStatement(new LogicalAnd(
            $runtimeGenerationCall,
            new LogicalNot($classExistsCall)
        ));
        $dummyModeVariable = new Variable(new Identifier('dummyMode'));
        $dummyModeCall = new Call(new StaticMember(
            new Constant(new Identifier('static')),
            new Constant(new Identifier('dummyMode'))
        ));
        $runtimeGenerationIf->trueBranch()->add(
            new ExpressionStatement(new Assign(
                $dummyModeVariable,
                $dummyModeCall
            ))
        );
        $setDummyModeTrueCall = new Call(new StaticMember(
            new Constant(new Identifier('static')),
            new Constant(new Identifier('setDummyMode'))
        ));
        $setDummyModeTrueCall->add(new Literal(true));
        $runtimeGenerationIf->trueBranch()->add(new ExpressionStatement(
            $setDummyModeTrueCall
        ));
        $defineValidatorCall = new Call(new StaticMember(
            $staticConstant,
            new Constant(new Identifier('defineValidator'))
        ));
        $defineValidatorCall->add($classNameVariable);
        $runtimeGenerationIf->trueBranch()->add(
            new ExpressionStatement($defineValidatorCall)
        );
        $resetDummyModeCall = new Call(new StaticMember(
            new Constant(new Identifier('static')),
            new Constant(new Identifier('setDummyMode'))
        ));
        $resetDummyModeCall->add($dummyModeVariable);
        $runtimeGenerationIf->trueBranch()->add(new ExpressionStatement(
            $resetDummyModeCall
        ));
        $method->statementBlock()->add($runtimeGenerationIf);

        $method->statementBlock()->add(new ReturnStatement(
            new NewOperator($validatorClassNameVariable)
        ));

        return $method;
    }
protected function generateCreateValidatorMethod(
        RuntimeConfiguration $configuration
    ) {
        $this->typeCheck->generateCreateValidatorMethod(func_get_args());

        $classNameIdentifier = new Identifier('className');
        $classNameVariable = new Variable($classNameIdentifier);
        $validatorClassNameVariable = new Variable(new Identifier('validatorClassName'));

        $method = new ConcreteMethod(
            new Identifier('createValidator'),
            AccessModifier::PROTECTED_(),
            true
        );
        $method->addParameter(new Parameter($classNameIdentifier));

        $validatorClassNameConcatenation = new Concat(
            new Literal(sprintf(
                '%s\\',
                $configuration
                    ->validatorNamespace()
                    ->joinAtoms('Validator')
                    ->string()
            )),
            $classNameVariable
        );
        $validatorClassNameConcatenation->add(new Literal('TypeCheck'));
        $method->statementBlock()->add(new ExpressionStatement(new Assign(
            $validatorClassNameVariable,
            $validatorClassNameConcatenation
        )));

        $staticConstant = new Constant(new Identifier('static'));
        $runtimeGenerationCall = new Call(new StaticMember(
            $staticConstant,
            new Constant(new Identifier('runtimeGeneration'))
        ));
        $classExistsCall = new Call(QualifiedIdentifier::fromString('\class_exists'));
        $classExistsCall->add($validatorClassNameVariable);
        $runtimeGenerationIf = new IfStatement(new LogicalAnd(
            $runtimeGenerationCall,
            new LogicalNot($classExistsCall)
        ));
        $dummyModeVariable = new Variable(new Identifier('dummyMode'));
        $dummyModeCall = new Call(new StaticMember(
            new Constant(new Identifier('static')),
            new Constant(new Identifier('dummyMode'))
        ));
        $runtimeGenerationIf->trueBranch()->add(
            new ExpressionStatement(new Assign(
                $dummyModeVariable,
                $dummyModeCall
            ))
        );
        $setDummyModeTrueCall = new Call(new StaticMember(
            new Constant(new Identifier('static')),
            new Constant(new Identifier('setDummyMode'))
        ));
        $setDummyModeTrueCall->add(new Literal(true));
        $runtimeGenerationIf->trueBranch()->add(new ExpressionStatement(
            $setDummyModeTrueCall
        ));
        $defineValidatorCall = new Call(new StaticMember(
            $staticConstant,
            new Constant(new Identifier('defineValidator'))
        ));
        $defineValidatorCall->add($classNameVariable);
        $runtimeGenerationIf->trueBranch()->add(
            new ExpressionStatement($defineValidatorCall)
        );
        $resetDummyModeCall = new Call(new StaticMember(
            new Constant(new Identifier('static')),
            new Constant(new Identifier('setDummyMode'))
        ));
        $resetDummyModeCall->add($dummyModeVariable);
        $runtimeGenerationIf->trueBranch()->add(new ExpressionStatement(
            $resetDummyModeCall
        ));
        $method->statementBlock()->add($runtimeGenerationIf);

        $method->statementBlock()->add(new ReturnStatement(
            new NewOperator($validatorClassNameVariable)
        ));

        return $method;
    }
@param RuntimeConfiguration $configuration

@return ConcreteMethod