| Total Complexity | 6 |
| Total Lines | 48 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 13 | class RepositoryFactory |
||
| 14 | { |
||
| 15 | |||
| 16 | /** @var EntityManagerInterface $entityManager */ |
||
| 17 | protected $entityManager; |
||
| 18 | |||
| 19 | /** @var array $entities */ |
||
| 20 | protected $entities; |
||
| 21 | |||
| 22 | /** |
||
| 23 | * RepositoryFactory constructor. |
||
| 24 | * @param EntityManagerInterface $entityManager |
||
| 25 | * @param array $entities |
||
| 26 | */ |
||
| 27 | public function __construct(EntityManagerInterface $entityManager, array $entities) |
||
| 31 | } |
||
| 32 | |||
| 33 | /** |
||
| 34 | * @param string $tableName |
||
| 35 | * @return RepositoryInterface|null |
||
| 36 | */ |
||
| 37 | public function create(string $tableName): ?RepositoryInterface |
||
| 38 | { |
||
| 39 | $entityClass = $this->getEntityClass($tableName); |
||
| 40 | if ($entityClass) { |
||
| 41 | $repository = $this->entityManager->getRepository($entityClass); |
||
| 42 | if ($repository instanceof RepositoryInterface) { |
||
| 43 | return $repository; |
||
| 44 | } |
||
| 45 | } |
||
| 46 | |||
| 47 | return null; |
||
| 48 | } |
||
| 49 | |||
| 50 | /** |
||
| 51 | * @param string $tableName |
||
| 52 | * @return string|null |
||
| 53 | */ |
||
| 54 | public function getEntityClass(string $tableName): ?string |
||
| 61 | } |
||
| 62 | } |
||
| 63 |