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

EntityLabelTrait   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 1 Features 0
Metric Value
wmc 7
c 1
b 1
f 0
lcom 0
cbo 2
dl 0
loc 23
ccs 0
cts 19
cp 0
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B getEntityLabel() 0 20 7
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