Completed
Push — master ( b1dd66...3d1870 )
by Beñat
04:18 queued 01:05
created

Id   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 8
c 1
b 0
f 0
lcom 1
cbo 2
dl 0
loc 32
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-2017 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
namespace LIN3S\SharedKernel\Domain\Model\Identity;
13
14
/**
15
 * @author Beñat Espiña <[email protected]>
16
 */
17
abstract class Id implements BaseId
18
{
19
    protected $id;
20
21
    public static function generate($id = null)
22
    {
23
        return new static($id);
24
    }
25
26
    protected function __construct($id = null)
27
    {
28
        if ($id !== null && !is_scalar($id)) {
29
            throw new InvalidIdException();
30
        }
31
        $this->id = null === $id ? Uuid::generate() : $id;
32
    }
33
34
    public function id()
35
    {
36
        return $this->id;
37
    }
38
39
    public function equals(Id $id)
40
    {
41
        return $this->id === $id->id();
42
    }
43
44
    public function __toString()
45
    {
46
        return (string)$this->id;
47
    }
48
}
49