public static function fromReflection(ReflectionClass $reflectionClass)
    {
        if ($reflectionClass->isTrait() !== true) {
            throw new InvalidArgumentException('The reflected class must be a trait.');
        }

        $tg = new static($reflectionClass->getShortName(), $reflectionClass->getNamespaceName());

        // Documentation.
        if ($reflectionClass->getReflectionDocComment()->isEmpty() !== true) {
            $tg->setDocumentation(DocCommentGenerator::fromReflection($reflectionClass->getReflectionDocComment()));
        }

        // Uses.
        foreach ($reflectionClass->getUses() as $use) {
            $use = UseTraitGenerator::fromReflection($use);
            if ($tg->getNamespace() !== null && strpos($use->getTraitClass(), $tg->getNamespace()) === 0) {
                $use->setTraitClass(substr($use->getTraitClass(), strlen($tg->getNamespace()) + 1));
            }

            $tg->addTraitUse($use);
        }

        // Properties.
        foreach ($reflectionClass->getOwnProperties() as $property) {
            $tg->addProperty(PropertyGenerator::fromReflection($property));
        }

        // Methods.
        foreach ($reflectionClass->getOwnMethods() as $method) {
            $tg->addMethod(MethodGenerator::fromReflection($method));
        }

        return $tg;
    }
public static function fromReflection(ReflectionClass $reflectionClass)
    {
        if ($reflectionClass->isTrait() !== true) {
            throw new InvalidArgumentException('The reflected class must be a trait.');
        }

        $tg = new static($reflectionClass->getShortName(), $reflectionClass->getNamespaceName());

        // Documentation.
        if ($reflectionClass->getReflectionDocComment()->isEmpty() !== true) {
            $tg->setDocumentation(DocCommentGenerator::fromReflection($reflectionClass->getReflectionDocComment()));
        }

        // Uses.
        foreach ($reflectionClass->getUses() as $use) {
            $use = UseTraitGenerator::fromReflection($use);
            if ($tg->getNamespace() !== null && strpos($use->getTraitClass(), $tg->getNamespace()) === 0) {
                $use->setTraitClass(substr($use->getTraitClass(), strlen($tg->getNamespace()) + 1));
            }

            $tg->addTraitUse($use);
        }

        // Properties.
        foreach ($reflectionClass->getOwnProperties() as $property) {
            $tg->addProperty(PropertyGenerator::fromReflection($property));
        }

        // Methods.
        foreach ($reflectionClass->getOwnMethods() as $method) {
            $tg->addMethod(MethodGenerator::fromReflection($method));
        }

        return $tg;
    }
public static function fromReflection ( ReflectionClass $ reflectionClass ) { if ( $ reflectionClass -> isTrait ( ) !== true ) { throw new InvalidArgumentException ( 'The reflected class must be a trait.' ) ; } $ tg = new static ( $ reflectionClass -> getShortName ( ) , $ reflectionClass -> getNamespaceName ( ) ) ; // Documentation. if ( $ reflectionClass -> getReflectionDocComment ( ) -> isEmpty ( ) !== true ) { $ tg -> setDocumentation ( DocCommentGenerator :: fromReflection ( $ reflectionClass -> getReflectionDocComment ( ) ) ) ; } // Uses. foreach ( $ reflectionClass -> getUses ( ) as $ use ) { $ use = UseTraitGenerator :: fromReflection ( $ use ) ; if ( $ tg -> getNamespace ( ) !== null && strpos ( $ use -> getTraitClass ( ) , $ tg -> getNamespace ( ) ) === 0 ) { $ use -> setTraitClass ( substr ( $ use -> getTraitClass ( ) , strlen ( $ tg -> getNamespace ( ) ) + 1 ) ) ; } $ tg -> addTraitUse ( $ use ) ; } // Properties. foreach ( $ reflectionClass -> getOwnProperties ( ) as $ property ) { $ tg -> addProperty ( PropertyGenerator :: fromReflection ( $ property ) ) ; } // Methods. foreach ( $ reflectionClass -> getOwnMethods ( ) as $ method ) { $ tg -> addMethod ( MethodGenerator :: fromReflection ( $ method ) ) ; } return $ tg ; }
Create a new trait from reflection.

@param \Wingu\OctopusCore\Reflection\ReflectionClass $reflectionClass The reflection of the trait.
@return \Wingu\OctopusCore\CodeGenerator\PHP\OOP\TraitGenerator
@throws \Wingu\OctopusCore\CodeGenerator\Exceptions\InvalidArgumentException If the reflected class is not a trait.
Create a new trait from reflection .