Completed
Push — dev ( e5bbcf...4306de )
by Arnaud
05:15
created

AdminTrait::getEntityLabel()   B

Complexity

Conditions 7
Paths 7

Size

Total Lines 21
Code Lines 17

Duplication

Lines 21
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 56

Importance

Changes 7
Bugs 2 Features 1
Metric Value
c 7
b 2
f 1
dl 21
loc 21
ccs 0
cts 17
cp 0
rs 7.551
cc 7
eloc 17
nc 7
nop 0
crap 56
1
<?php
2
3
namespace LAG\AdminBundle\Admin\Behaviors;
4
5
use Pagerfanta\Pagerfanta;
6
7
trait AdminTrait
8
{
9
    use EntityLabelTrait {
10
        getEntityLabel as parentEntityLabel;
11
    }
12
13
    /**
14
     * @var Pagerfanta
15
     */
16
    protected $pager;
17
18
    /**
19
     * @return object
20
     */
21
    public abstract function getUniqueEntity();
22
23
    /**
24
     * @return Pagerfanta
25
     */
26
    public function getPager()
27
    {
28
        return $this->pager;
29
    }
30
31
    /**
32
     * Try to find a property to get a label from an entity. If found, it returns the property value through the
33
     * property accessor.
34
     *
35
     * @return string
36
     */
37
    public function getEntityLabel()
38
    {
39
        $entity = $this->getUniqueEntity();
40
        $label = $this->parentEntityLabel($entity);
0 ignored issues
show
Bug introduced by
It seems like parentEntityLabel() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
41
42
        return $label;
43
    }
44
}
45