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

EntityLabelTrait::getEntityLabel()   B

Complexity

Conditions 7
Paths 7

Size

Total Lines 20
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 56

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
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 BlueBear\BaseBundle\Entity\Behaviors\Label;
6
use Symfony\Component\PropertyAccess\PropertyAccess;
7
8
trait EntityLabelTrait
9
{
10
    public function getEntityLabel($entity)
11
    {
12
        $label = '';
13
        $accessor = PropertyAccess::createPropertyAccessor();
14
15
        if ($accessor->isReadable($entity, 'label')) {
16
            $label = $entity->getLabel();
17
        } else if ($accessor->isReadable($entity, 'title')) {
18
            $label = $entity->getTitle();
19
        } else if ($accessor->isReadable($entity, 'name')) {
20
            $label = $entity->getName();
21
        } else if ($accessor->isReadable($entity, '__toString')) {
22
            $label = $entity->__toString();
23
        } else if ($accessor->isReadable($entity, 'content')) {
24
            $label = strip_tags(substr($entity->getContent(), 0, 100));
25
        } else if ($accessor->isReadable($entity, 'id')) {
26
            $label = $entity->getId();
27
        }
28
        return $label;
29
    }
30
}
31