| Total Complexity | 6 |
| Total Lines | 39 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 10 | class EntitiesArgumentConverter |
||
| 11 | { |
||
| 12 | /** |
||
| 13 | * @throws \Exception |
||
| 14 | */ |
||
| 15 | public function convertToEntitiesSource( |
||
| 16 | iterable $entities, |
||
| 17 | ?string $entityClass, |
||
| 18 | MetadataAdapterProvider $metadataAdapterProvider |
||
| 19 | ): EntitySource { |
||
| 20 | $entities = $this->convertEntitiesToArrayCollection($entities); |
||
| 21 | |||
| 22 | if ($entities->isEmpty()) { |
||
| 23 | return new EntitySource($entities); |
||
| 24 | } |
||
| 25 | |||
| 26 | if (!$entityClass) { |
||
| 27 | $entityClass = $metadataAdapterProvider->getClassNameForEntities($entities); |
||
| 28 | } |
||
| 29 | $entityClassMetadataAdapter = $metadataAdapterProvider->getClassMetadataAdapterByClassName($entityClass); |
||
| 30 | |||
| 31 | $entitySource = new EntitySource($entities, $entityClass); |
||
| 32 | $entitySource->setClassMetadataAdapter($entityClassMetadataAdapter); |
||
| 33 | |||
| 34 | return $entitySource; |
||
| 35 | } |
||
| 36 | |||
| 37 | public function convertEntitiesToArrayCollection(iterable $entities): ArrayCollection |
||
| 49 | } |
||
| 50 | } |
||
| 51 |