MetadataHelper::findMetadata()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 4
c 0
b 0
f 0
nc 2
nop 1
dl 0
loc 11
rs 10
ccs 5
cts 5
cp 1
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace LAG\AdminBundle\Bridge\Doctrine\ORM\Metadata;
6
7
use Doctrine\ORM\EntityManagerInterface;
8
use Doctrine\Persistence\Mapping\ClassMetadata;
9
use Exception;
10
11
class MetadataHelper implements MetadataHelperInterface
12
{
13
    public function __construct(private EntityManagerInterface $entityManager)
14
    {
15 1
    }
16
17 1
    public function findMetadata(string $class): ?ClassMetadata
18 1
    {
19
        try {
20 1
            // We could not use the hasMetadataFor() method as it is not working if the entity is not loaded. But
21
            // the getMetadataFor() method could throw an exception if the class is not found
22 1
            return $this->entityManager->getMetadataFactory()->getMetadataFor($class);
23
        } catch (Exception) {
24
            // If an exception is raised, nothing to do. Extra data from metadata will be not used.
25
        }
26
27 1
        return null;
28 1
    }
29
}
30