Classes/Pattern/Presentation/Model/ModelFactory.php
/**
     * @param \ReflectionClass<object> $modelReflection
     * @return Model
     */
@param \ReflectionClass $modelReflection
@return Model
@param \ ReflectionClass $modelReflection @return Model
public function fromExistingModel(\ReflectionClass $modelReflection): Model
    {
        list($packageKey, $name) = explode('\\Presentation\\', $modelReflection->getName());
        $packageKey = ltrim($packageKey, '\\');
        $packageKey = str_replace('\\', '.', $packageKey);
        $distributionPackage = $this->distributionPackageResolver->resolve($packageKey);
        $presentation = Presentation::fromDistributionPackage($distributionPackage);
        $signature = $this->signatureFactory->forDistributionPackage($distributionPackage);
        $importCollectionBuilder = new ImportCollectionBuilder();
        $properties = [];
        foreach ($modelReflection->getMethods(\ReflectionMethod::IS_PUBLIC) as $methodReflection) {
            if (GetterSpecification::isSatisfiedByReflectionMethod($methodReflection)) {
                $property = $this->propertyFactory->fromReflectionGetterMethod($methodReflection);
                $fullyQualifiedTypeName = (string) $methodReflection->getReturnType();
                if (class_exists($fullyQualifiedTypeName) || interface_exists($fullyQualifiedTypeName)) {
                    $import = new Import($fullyQualifiedTypeName, $property->getType()->getName());
                    $import = $importCollectionBuilder->addImport($import);
                    $property = $property->withType(
                        $property->getType()
                            ->withNativeName('\\' . $import->getFullyQualifiedName())
                            ->withAlias($import->getName())
                    );
                }
                $properties[] = $property;
            }
        }
        $imports = $importCollectionBuilder->build();
        return new Model($presentation, $name, $signature, $imports, $properties);
    }
public function fromExistingModel ( \ ReflectionClass $ modelReflection ) : Model { list ( $ packageKey , $ name ) = explode ( '\\Presentation\\' , $ modelReflection -> getName ( ) ) ; $ packageKey = ltrim ( $ packageKey , '\\' ) ; $ packageKey = str_replace ( '\\' , '.' , $ packageKey ) ; $ distributionPackage = $ this -> distributionPackageResolver -> resolve ( $ packageKey ) ; $ presentation = Presentation :: fromDistributionPackage ( $ distributionPackage ) ; $ signature = $ this -> signatureFactory -> forDistributionPackage ( $ distributionPackage ) ; $ importCollectionBuilder = new ImportCollectionBuilder ( ) ; $ properties = [ ] ; foreach ( $ modelReflection -> getMethods ( \ ReflectionMethod :: IS_PUBLIC ) as $ methodReflection ) { if ( GetterSpecification :: isSatisfiedByReflectionMethod ( $ methodReflection ) ) { $ property = $ this -> propertyFactory -> fromReflectionGetterMethod ( $ methodReflection ) ; $ fullyQualifiedTypeName = ( string ) $ methodReflection -> getReturnType ( ) ; if ( class_exists ( $ fullyQualifiedTypeName ) || interface_exists ( $ fullyQualifiedTypeName ) ) { $ import = new Import ( $ fullyQualifiedTypeName , $ property -> getType ( ) -> getName ( ) ) ; $ import = $ importCollectionBuilder -> addImport ( $ import ) ; $ property = $ property -> withType ( $ property -> getType ( ) -> withNativeName ( '\\' . $ import -> getFullyQualifiedName ( ) ) -> withAlias ( $ import -> getName ( ) ) ) ; } $ properties [ ] = $ property ; } } $ imports = $ importCollectionBuilder -> build ( ) ; return new Model ( $ presentation , $ name , $ signature , $ imports , $ properties ) ; }
@param \ReflectionClass<object> $modelReflection
 @return Model
@param \ ReflectionClass<object > $modelReflection @return Model