Completed
Push — dev ( 5c06f5...dcd39b )
by Arnaud
09:19
created

AdminTrait   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 7
Bugs 2 Features 2
Metric Value
wmc 6
c 7
b 2
f 2
lcom 0
cbo 0
dl 0
loc 41
ccs 0
cts 15
cp 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
getUniqueEntity() 0 1 ?
A getPager() 0 4 1
B getEntityLabel() 0 17 5
1
<?php
2
3
namespace LAG\AdminBundle\Admin\Behaviors;
4
5
use LAG\AdminBundle\Admin\Configuration\AdminConfiguration;
6
use Pagerfanta\Pagerfanta;
7
8
trait AdminTrait
9
{
10
    /**
11
     * @var Pagerfanta
12
     */
13
    protected $pager;
14
15
    /**
16
     * @return object
17
     */
18
    public abstract function getUniqueEntity();
19
20
    /**
21
     * @return Pagerfanta
22
     */
23
    public function getPager()
24
    {
25
        return $this->pager;
26
    }
27
28
    /**
29
     * @return string
30
     */
31
    public function getEntityLabel()
32
    {
33
        $label = '';
34
        $entity = $this->getUniqueEntity();
35
36
        if (method_exists($entity, 'getLabel')) {
37
            $label = $entity->getLabel();
38
        } elseif (method_exists($entity, 'getTitle')) {
39
            $label = $entity->getTitle();
40
        } elseif (method_exists($entity, 'getName')) {
41
            $label = $entity->getName();
42
        } elseif (method_exists($entity, '__toString')) {
43
            $label = $entity->__toString();
44
        }
45
46
        return $label;
47
    }
48
}
49