StatementId::fromUuid()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
/*
4
 * This file is part of the xAPI package.
5
 *
6
 * (c) Christian Flothmann <[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 Xabbuh\XApi\Model;
13
14
/**
15
 * An Experience API {@link https://github.com/adlnet/xAPI-Spec/blob/master/xAPI.md#statement Statement} identifier.
16
 *
17
 * @author Christian Flothmann <[email protected]>
18
 */
19
final class StatementId
20
{
21
    private $uuid;
22
23
    private function __construct()
24
    {
25
    }
26
27
    public static function fromUuid(Uuid $uuid): self
28
    {
29
        $id = new self();
30
        $id->uuid = $uuid;
31
32
        return $id;
33
    }
34
35
    /**
36
     * Creates a statement id based on the given UUID string.
37
     *
38
     * @throws \InvalidArgumentException when the given id is not a well-formed UUID
39
     */
40
    public static function fromString(string $id): self
41
    {
42
        return self::fromUuid(Uuid::fromString($id));
43
    }
44
45
    public function getValue(): string
46
    {
47
        return (string) $this->uuid;
48
    }
49
50
    public function equals(StatementId $id): bool
51
    {
52
        return $this->uuid->equals($id->uuid);
53
    }
54
}
55