FileId   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 2
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 BenGorFile package.
5
 *
6
 * (c) Beñat Espiña <[email protected]>
7
 * (c) Gorka Laucirica <[email protected]>
8
 *
9
 * For the full copyright and license information, please view the LICENSE
10
 * file that was distributed with this source code.
11
 */
12
13
namespace BenGorFile\File\Domain\Model;
14
15
use Ramsey\Uuid\Uuid;
16
17
/**
18
 * File id domain class.
19
 *
20
 * @author Beñat Espiña <[email protected]>
21
 * @author Gorka Laucirica <[email protected]>
22
 */
23
class FileId
24
{
25
    /**
26
     * The id in a primitive type.
27
     *
28
     * @var string|int
29
     */
30
    private $id;
31
32
    /**
33
     * Constructor.
34
     *
35
     * @param string|int|null $anId The id in a primitive type
36
     */
37
    public function __construct($anId = null)
38
    {
39
        $this->id = null === $anId ? Uuid::uuid4()->toString() : $anId;
40
    }
41
42
    /**
43
     * Gets the id.
44
     *
45
     * @return string|int
46
     */
47
    public function id()
48
    {
49
        return $this->id;
50
    }
51
52
    /**
53
     * Method that checks if the id given is equal to the current.
54
     *
55
     * @param FileId $anId The id
56
     *
57
     * @return bool
58
     */
59
    public function equals(FileId $anId)
60
    {
61
        return $this->id() === $anId->id();
62
    }
63
64
    /**
65
     * Magic method that represents the file id in string format.
66
     *
67
     * @return string
68
     */
69
    public function __toString()
70
    {
71
        return $this->id();
72
    }
73
}
74