Completed
Push — master ( be7a44...a89c67 )
by Filipe
01:07 queued 10s
created

EventId::__construct()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.9332
c 0
b 0
f 0
cc 3
nc 4
nop 1
1
<?php
2
3
/**
4
 * This file is part of slick/event package
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
namespace Slick\Event\Domain;
11
12
use InvalidArgumentException;
13
use Ramsey\Uuid\Uuid;
14
15
/**
16
 * EventId
17
 *
18
 * @package Slick\Event\Domain
19
 */
20
final class EventId
21
{
22
    /**
23
     * @var string
24
     */
25
    private $identifier;
26
27
28
    /**
29
     * Creates a EventId
30
     *
31
     * @param string $identifier
32
     */
33
    public function __construct(string $identifier = null)
34
    {
35
        $identifier = $identifier ?: Uuid::uuid4()->toString();
36
        if (!Uuid::isValid($identifier)) {
37
            throw new InvalidArgumentException(
38
                "Invalid event identifier."
39
            );
40
        }
41
        $this->identifier = $identifier;
42
    }
43
44
    /**
45
     * Event identifier as a string
46
     *
47
     * @return string
48
     */
49
    public function __toString()
50
    {
51
        return $this->identifier;
52
    }
53
54
}
55