GuidAwareListener   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
c 1
b 0
f 0
dl 0
loc 20
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A prePersist() 0 4 2
A __construct() 0 3 1
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