MetadataHelper::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 0
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 2
rs 10
ccs 0
cts 0
cp 0
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