Id   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 2
dl 0
loc 32
c 0
b 0
f 0
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A generate() 0 4 1
A __construct() 0 7 4
A id() 0 4 1
A equals() 0 4 1
A __toString() 0 4 1
1
<?php
2
3
/*
4
 * This file is part of the Shared Kernel library.
5
 *
6
 * Copyright (c) 2016-present LIN3S <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace LIN3S\SharedKernel\Domain\Model\Identity;
15
16
/**
17
 * @author Beñat Espiña <[email protected]>
18
 */
19
abstract class Id implements BaseId
20
{
21
    protected $id;
22
23
    public static function generate($id = null)
24
    {
25
        return new static($id);
26
    }
27
28
    protected function __construct($id = null)
29
    {
30
        if (null !== $id && !is_scalar($id)) {
31
            throw new InvalidIdException();
32
        }
33
        $this->id = null === $id ? Uuid::generate() : $id;
34
    }
35
36
    public function id() : string
37
    {
38
        return (string) $this->id;
39
    }
40
41
    public function equals(self $id) : bool
42
    {
43
        return $this->id() === $id->id();
44
    }
45
46
    public function __toString() : string
47
    {
48
        return (string) $this->id;
49
    }
50
}
51