Completed
Push — master ( 21b23e...04c0e6 )
by Christian
04:03
created

StatementId   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
lcom 1
cbo 1
dl 0
loc 43
rs 10
c 1
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A fromUuid() 0 7 1
A fromString() 0 4 1
A getValue() 0 4 1
A equals() 0 4 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
use Rhumsaa\Uuid\Uuid;
15
16
/**
17
 * An Experience API {@link https://github.com/adlnet/xAPI-Spec/blob/master/xAPI.md#statement Statement} identifier.
18
 *
19
 * @author Christian Flothmann <[email protected]>
20
 */
21
final class StatementId
22
{
23
    /**
24
     * @var Uuid
25
     */
26
    private $uuid;
27
28
    private function __construct()
29
    {
30
    }
31
32
    public static function fromUuid(Uuid $uuid)
33
    {
34
        $id = new self();
35
        $id->uuid = $uuid;
36
37
        return $id;
38
    }
39
40
    /**
41
     * Creates a statement id based on the given UUID string.
42
     *
43
     * @param string $id
44
     *
45
     * @return StatementId
46
     *
47
     * @throws \InvalidArgumentException when the given id is not a well-formed UUID
48
     */
49
    public static function fromString($id)
50
    {
51
        return self::fromUuid(Uuid::fromString($id));
52
    }
53
54
    public function getValue()
55
    {
56
        return $this->uuid->toString();
57
    }
58
59
    public function equals(StatementId $id)
60
    {
61
        return $this->uuid->equals($id->uuid);
62
    }
63
}
64