Completed
Push — refonte ( 758c88...ee8395 )
by Arnaud
02:27
created

MetadataTrait::findMetadata()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 12
rs 9.8666
c 0
b 0
f 0
cc 2
nc 2
nop 1
1
<?php
2
3
namespace LAG\AdminBundle\Bridge\Doctrine\ORM\Helper;
4
5
use Doctrine\ORM\EntityManagerInterface;
6
use Exception;
7
8
trait MetadataTrait
9
{
10
    /**
11
     * @var EntityManagerInterface
12
     */
13
    protected $entityManager;
14
15
    /**
16
     * Return the Doctrine metadata of the given class.
17
     *
18
     * @param $class
19
     *
20
     * @return \Doctrine\Common\Persistence\Mapping\ClassMetadata|null
21
     */
22
    protected function findMetadata($class)
23
    {
24
        $metadata = null;
25
26
        try {
27
            // We could not use the hasMetadataFor() method as it is not working if the entity is not loaded. But
28
            // the getMetadataFor() method could throw an exception if the class is not found
29
            $metadata = $this->entityManager->getMetadataFactory()->getMetadataFor($class);
30
        } catch (Exception $exception) {}
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
31
32
        return $metadata;
33
    }
34
}
35