BaseId   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 4
dl 0
loc 43
ccs 14
cts 14
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A setValue() 0 10 2
A value() 0 4 1
A __toString() 0 4 1
1
<?php
2
3
namespace BaseValueObject\Scalar;
4
5
use Ramsey\Uuid\Uuid;
6
use Webmozart\Assert\Assert;
7
8
/**
9
 * Class BaseId
10
 * @package BaseValueObject\Scalar
11
 */
12
abstract class BaseId extends BaseScalar
13
{
14
    protected $value;
15
16
    /**
17
     * BaseId constructor.
18
     *
19
     * @param null|string $id
20
     */
21 12
    public function __construct(?string $id = null)
22
    {
23 12
        $this->setValue($id);
24 9
    }
25
26 12
    private function setValue(?string $id): void
27
    {
28 12
        if ($id === null) {
29 3
            $this->value = Uuid::uuid4()->toString();
30 3
            return;
31
        }
32
33 9
        Assert::uuid($id);
34 6
        $this->value = $id;
35 6
    }
36
37
    /**
38
     * {@inheritdoc}
39
     *
40
     * @return string
41
     */
42 9
    public function value(): string
43
    {
44 9
        return $this->value;
45
    }
46
47
    /**
48
     * @return string
49
     */
50 3
    public function __toString(): string
51
    {
52 3
        return $this->value();
53
    }
54
}
55