AbstractEntity   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 6
c 1
b 0
f 1
lcom 0
cbo 3
dl 0
loc 35
ccs 14
cts 14
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 12 4
A __clone() 0 11 2
1
<?php
2
/**
3
 * @author Stefano Torresi (http://stefanotorresi.it)
4
 * @license See the file LICENSE.txt for copying permission.
5
 * ************************************************
6
 */
7
8
namespace Thorr\Persistence\Entity;
9
10
use Ramsey\Uuid\Uuid;
11
12
abstract class AbstractEntity implements UuidProviderInterface
13
{
14
    use UuidProviderTrait;
15
16
    /**
17
     * @param Uuid|string $uuid
18
     */
19 4
    public function __construct($uuid = null)
20
    {
21 4
        if ($uuid !== null && ! $uuid instanceof Uuid) {
22 1
            $uuid = Uuid::fromString($uuid);
23 1
        }
24
25 4
        if ($uuid === null) {
26 2
            $uuid = Uuid::uuid4();
27 2
        }
28
29 4
        $this->uuid = $uuid->toString();
30 4
    }
31
32
    /**
33
     * ensure uuid changes on cloning
34
     */
35 2
    public function __clone()
36
    {
37 2
        if (! $this->uuid) {
38
            /*
39
             * ensure doctrine proxies compatibility
40
             * @see http://doctrine-orm.readthedocs.io/en/latest/cookbook/implementing-wakeup-or-clone.html
41
             */
42 1
            return;
43
        }
44 1
        $this->uuid = Uuid::uuid4()->toString();
45 1
    }
46
}
47