src/Entity/DataTransferObjects/DtoFactory.php
private function addNestedRequiredDtos(DataTransferObjectInterface $dto): void
    {
        $entityFqn         = $dto::getEntityFqn();
        $dsm               = $this->getDsmFromEntityFqn($entityFqn);
        $requiredRelations = $dsm->getRequiredRelationProperties();
        foreach ($requiredRelations as $propertyName => $types) {
            $numTypes = count($types);
            if (1 !== $numTypes) {
                throw new \RuntimeException('Unexpected number of types, only expecting 1: ' . print_r($types, true));
            }
            $entityInterfaceFqn = $types[0];
            $getter             = 'get' . $propertyName;
            if ('[]' === substr($entityInterfaceFqn, -2)) {
                if ($dto->$getter()->count() > 0) {
                    continue;
                }
                $entityInterfaceFqn = substr($entityInterfaceFqn, 0, -2);
                $this->addNestedDtoToCollection($dto, $propertyName, $entityInterfaceFqn);
                continue;
            }
            $issetAsDtoMethod    = 'isset' . $propertyName . 'AsDto';
            $issetAsEntityMethod = 'isset' . $propertyName . 'AsEntity';
            if (true === $dto->$issetAsDtoMethod() || true === $dto->$issetAsEntityMethod()) {
                continue;
            }
            $this->addNestedDto($dto, $propertyName, $entityInterfaceFqn);
        }
    }
private function addNestedRequiredDtos(DataTransferObjectInterface $dto): void
    {
        $entityFqn         = $dto::getEntityFqn();
        $dsm               = $this->getDsmFromEntityFqn($entityFqn);
        $requiredRelations = $dsm->getRequiredRelationProperties();
        foreach ($requiredRelations as $propertyName => $types) {
            $numTypes = count($types);
            if (1 !== $numTypes) {
                throw new \RuntimeException('Unexpected number of types, only expecting 1: ' . print_r($types, true));
            }
            $entityInterfaceFqn = $types[0];
            $getter             = 'get' . $propertyName;
            if ('[]' === substr($entityInterfaceFqn, -2)) {
                if ($dto->$getter()->count() > 0) {
                    continue;
                }
                $entityInterfaceFqn = substr($entityInterfaceFqn, 0, -2);
                $this->addNestedDtoToCollection($dto, $propertyName, $entityInterfaceFqn);
                continue;
            }
            $issetAsDtoMethod    = 'isset' . $propertyName . 'AsDto';
            $issetAsEntityMethod = 'isset' . $propertyName . 'AsEntity';
            if (true === $dto->$issetAsDtoMethod() || true === $dto->$issetAsEntityMethod()) {
                continue;
            }
            $this->addNestedDto($dto, $propertyName, $entityInterfaceFqn);
        }
    }
private function addNestedRequiredDtos ( DataTransferObjectInterface $ dto ) : void { $ entityFqn = $ dto :: getEntityFqn ( ) ; $ dsm = $ this -> getDsmFromEntityFqn ( $ entityFqn ) ; $ requiredRelations = $ dsm -> getRequiredRelationProperties ( ) ; foreach ( $ requiredRelations as $ propertyName => $ types ) { $ numTypes = count ( $ types ) ; if ( 1 !== $ numTypes ) { throw new \ RuntimeException ( 'Unexpected number of types, only expecting 1: ' . print_r ( $ types , true ) ) ; } $ entityInterfaceFqn = $ types [ 0 ] ; $ getter = 'get' . $ propertyName ; if ( '[]' === substr ( $ entityInterfaceFqn , - 2 ) ) { if ( $ dto -> $ getter ( ) -> count ( ) > 0 ) { continue ; } $ entityInterfaceFqn = substr ( $ entityInterfaceFqn , 0 , - 2 ) ; $ this -> addNestedDtoToCollection ( $ dto , $ propertyName , $ entityInterfaceFqn ) ; continue ; } $ issetAsDtoMethod = 'isset' . $ propertyName . 'AsDto' ; $ issetAsEntityMethod = 'isset' . $ propertyName . 'AsEntity' ; if ( true === $ dto -> $ issetAsDtoMethod ( ) || true === $ dto -> $ issetAsEntityMethod ( ) ) { continue ; } $ this -> addNestedDto ( $ dto , $ propertyName , $ entityInterfaceFqn ) ; } }
Take the DTO for a defined EntityFqn and then parse the required relations and create nested DTOs for them

Checks if the required relation is already set and if so, does nothing

@param DataTransferObjectInterface $dto

@throws \ReflectionException
@throws \EdmondsCommerce\DoctrineStaticMeta\Exception\DoctrineStaticMetaException
Take the DTO for a defined EntityFqn and then parse the required relations and create nested DTOs for them