Code Duplication    Length = 23-23 lines in 2 locations

Admin/Behaviors/EntityLabel.php 1 location

@@ 7-29 (lines=23) @@
4
5
use Symfony\Component\PropertyAccess\PropertyAccess;
6
7
trait EntityLabel
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

Admin/Behaviors/EntityLabelTrait.php 1 location

@@ 8-30 (lines=23) @@
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