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

AdminTrait::getPager()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

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