Completed
Push — dev ( 5504ea...330909 )
by Arnaud
02:52
created

EntityLabel::getEntityLabel()   B

Complexity

Conditions 7
Paths 7

Size

Total Lines 20
Code Lines 16

Duplication

Lines 20
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 56

Importance

Changes 2
Bugs 1 Features 0
Metric Value
c 2
b 1
f 0
dl 20
loc 20
ccs 0
cts 19
cp 0
rs 8.2222
cc 7
eloc 16
nc 7
nop 1
crap 56
1
<?php
2
3
namespace LAG\AdminBundle\Admin\Behaviors;
4
5
use Symfony\Component\PropertyAccess\PropertyAccess;
6
7 View Code Duplication
trait EntityLabel
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
8
{
9
    public function getEntityLabel($entity)
10
    {
11
        $label = '';
12
        $accessor = PropertyAccess::createPropertyAccessor();
13
14
        if ($accessor->isReadable($entity, 'label')) {
15
            $label = $entity->getLabel();
16
        } else if ($accessor->isReadable($entity, 'title')) {
17
            $label = $entity->getTitle();
18
        } else if ($accessor->isReadable($entity, 'name')) {
19
            $label = $entity->getName();
20
        } else if ($accessor->isReadable($entity, '__toString')) {
21
            $label = $entity->__toString();
22
        } else if ($accessor->isReadable($entity, 'content')) {
23
            $label = strip_tags(substr($entity->getContent(), 0, 100));
24
        } else if ($accessor->isReadable($entity, 'id')) {
25
            $label = $entity->getId();
26
        }
27
        return $label;
28
    }
29
}
30