Completed
Pull Request — master (#13)
by Arnaud
07:28 queued 04:37
created

AdminTrait::getEntityLabel()   B

Complexity

Conditions 5
Paths 5

Size

Total Lines 17
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 6
Bugs 1 Features 1
Metric Value
c 6
b 1
f 1
dl 0
loc 17
rs 8.8571
cc 5
eloc 12
nc 5
nop 0
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