Finder   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Test Coverage

Coverage 91.67%

Importance

Changes 0
Metric Value
eloc 11
dl 0
loc 25
ccs 11
cts 12
cp 0.9167
rs 10
c 0
b 0
f 0
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getClassNameFromEntityName() 0 15 4
A __construct() 0 3 1
1
<?php
2
3
namespace Cdf\BiCoreBundle\Utils\Entity;
4
5
use Doctrine\ORM\EntityManagerInterface;
6
use Exception;
7
use function count;
8
9
class Finder
10
{
11
12
    private EntityManagerInterface $em;
13
14 14
    public function __construct(EntityManagerInterface $em)
15
    {
16 14
        $this->em = $em;
17
    }
18
19 14
    public function getClassNameFromEntityName(string $entityname): string
20
    {
21 14
        $entities = $this->em->getConfiguration()->getMetadataDriverImpl()->getAllClassNames();
22 14
        $entityclassname = '';
23 14
        foreach ($entities as $entity) {
24 14
            $parti = explode('\\', $entity);
25 14
            if ($parti[count($parti) - 1] == $entityname) {
26 14
                $entityclassname = $entity;
27
            }
28
        }
29 14
        if (!$entityclassname) {
30
            throw new Exception("Non riesco a trovare l'entità '" . $entityname . "', è stata generata?");
31
        }
32
33 14
        return $entityclassname;
34
    }
35
}
36