Finder::getClassNameFromEntityName()   A
last analyzed

Complexity

Conditions 4
Paths 6

Size

Total Lines 15
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 4.016

Importance

Changes 0
Metric Value
cc 4
eloc 9
nc 6
nop 1
dl 0
loc 15
ccs 9
cts 10
cp 0.9
crap 4.016
rs 9.9666
c 0
b 0
f 0
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