public static function fromReflection(ReflectionParameter $reflectionParameter)
    {
        $param = new static($reflectionParameter->getName());

        if ($reflectionParameter->isArray() === true) {
            $param->setType('array');
        } else {
            $typeClass = $reflectionParameter->getClass();
            if ($typeClass !== null) {
                $param->setType('\\' . $typeClass->getName());
            }
        }

        if ($reflectionParameter->isOptional() === true) {
            $param->setDefaultValue($reflectionParameter->getDefaultValue());

            if ($reflectionParameter->isDefaultValueConstant() === true) {
                $defaultValueConstantName = $reflectionParameter->getDefaultValueConstantName();

                $declaringFunction = $reflectionParameter->getDeclaringFunction();
                if ($declaringFunction instanceof \ReflectionMethod) {
                    $ns = $declaringFunction->getDeclaringClass()->getNamespaceName();
                } else {
                    $ns = $declaringFunction->getNamespaceName();
                }

                if ($ns !== '' && strpos($defaultValueConstantName, $ns) === 0) {
                    $defaultValueConstantName = substr($defaultValueConstantName, strlen($ns) + 1);
                } elseif (strpos($defaultValueConstantName, '\\') !== false) {
                    $defaultValueConstantName = '\\' . $defaultValueConstantName;
                }

                $param->setDefaultValueConstantName($defaultValueConstantName);
            }
        }

        $param->setPassByReference($reflectionParameter->isPassedByReference());

        return $param;
    }
public static function fromReflection(ReflectionParameter $reflectionParameter)
    {
        $param = new static($reflectionParameter->getName());

        if ($reflectionParameter->isArray() === true) {
            $param->setType('array');
        } else {
            $typeClass = $reflectionParameter->getClass();
            if ($typeClass !== null) {
                $param->setType('\\' . $typeClass->getName());
            }
        }

        if ($reflectionParameter->isOptional() === true) {
            $param->setDefaultValue($reflectionParameter->getDefaultValue());

            if ($reflectionParameter->isDefaultValueConstant() === true) {
                $defaultValueConstantName = $reflectionParameter->getDefaultValueConstantName();

                $declaringFunction = $reflectionParameter->getDeclaringFunction();
                if ($declaringFunction instanceof \ReflectionMethod) {
                    $ns = $declaringFunction->getDeclaringClass()->getNamespaceName();
                } else {
                    $ns = $declaringFunction->getNamespaceName();
                }

                if ($ns !== '' && strpos($defaultValueConstantName, $ns) === 0) {
                    $defaultValueConstantName = substr($defaultValueConstantName, strlen($ns) + 1);
                } elseif (strpos($defaultValueConstantName, '\\') !== false) {
                    $defaultValueConstantName = '\\' . $defaultValueConstantName;
                }

                $param->setDefaultValueConstantName($defaultValueConstantName);
            }
        }

        $param->setPassByReference($reflectionParameter->isPassedByReference());

        return $param;
    }
public static function fromReflection ( ReflectionParameter $ reflectionParameter ) { $ param = new static ( $ reflectionParameter -> getName ( ) ) ; if ( $ reflectionParameter -> isArray ( ) === true ) { $ param -> setType ( 'array' ) ; } else { $ typeClass = $ reflectionParameter -> getClass ( ) ; if ( $ typeClass !== null ) { $ param -> setType ( '\\' . $ typeClass -> getName ( ) ) ; } } if ( $ reflectionParameter -> isOptional ( ) === true ) { $ param -> setDefaultValue ( $ reflectionParameter -> getDefaultValue ( ) ) ; if ( $ reflectionParameter -> isDefaultValueConstant ( ) === true ) { $ defaultValueConstantName = $ reflectionParameter -> getDefaultValueConstantName ( ) ; $ declaringFunction = $ reflectionParameter -> getDeclaringFunction ( ) ; if ( $ declaringFunction instanceof \ ReflectionMethod ) { $ ns = $ declaringFunction -> getDeclaringClass ( ) -> getNamespaceName ( ) ; } else { $ ns = $ declaringFunction -> getNamespaceName ( ) ; } if ( $ ns !== '' && strpos ( $ defaultValueConstantName , $ ns ) === 0 ) { $ defaultValueConstantName = substr ( $ defaultValueConstantName , strlen ( $ ns ) + 1 ) ; } elseif ( strpos ( $ defaultValueConstantName , '\\' ) !== false ) { $ defaultValueConstantName = '\\' . $ defaultValueConstantName ; } $ param -> setDefaultValueConstantName ( $ defaultValueConstantName ) ; } } $ param -> setPassByReference ( $ reflectionParameter -> isPassedByReference ( ) ) ; return $ param ; }
Create a new parameter from reflection.

@param \Wingu\OctopusCore\Reflection\ReflectionParameter $reflectionParameter The reflection of a parameter.
@return \Wingu\OctopusCore\CodeGenerator\PHP\ParameterGenerator
Create a new parameter from reflection .