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

MetadataTrait   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 0
dl 0
loc 27
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A findMetadata() 0 12 2
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