GuidAwareListener::prePersist()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 2
nc 2
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace PiouPiou\RibsAdminBundle\EventListener;
4
5
use Symfony\Component\DependencyInjection\ContainerInterface;
6
use Ramsey\Uuid\Uuid;
7
8
class GuidAwareListener
9
{
10
    /**
11
     * @var ContainerInterface
12
     */
13
    private $container;
14
15
    /**
16
     * GuidAwareListener constructor.
17
     * @param ContainerInterface $container
18
     */
19
    public function __construct(ContainerInterface $container)
20
    {
21
        $this->container = $container;
22
    }
23
24
    public function prePersist($entity)
25
    {
26
        if ($entity->getGuid() === null) {
27
            $entity->setGuid((string)Uuid::uuid4());
28
        }
29
    }
30
}
31