Test Failed
Push — master ( ed7d3a...1e1c10 )
by Dominik
02:15
created

Document   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 116
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 116
rs 10
c 0
b 0
f 0
wmc 9
lcom 1
cbo 1

9 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A create() 0 7 1
A fromPersistence() 0 10 1
A toPersistence() 0 9 1
A getId() 0 4 1
A getName() 0 4 1
A setName() 0 6 1
A getUrl() 0 4 1
A setUrl() 0 6 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Chubbyphp\ApiSkeleton\Model;
6
7
use Chubbyphp\Model\ModelInterface;
8
use Ramsey\Uuid\Uuid;
9
10
final class Document implements ModelInterface
11
{
12
    /**
13
     * @var string
14
     */
15
    private $id;
16
17
    /**
18
     * @var string
19
     */
20
    private $courseId;
21
22
    /**
23
     * @var string
24
     */
25
    private $name;
26
27
    /**
28
     * @var string
29
     */
30
    private $url;
31
32
    private function __construct()
33
    {
34
    }
35
36
    /**
37
     * @param string|null $id
38
     *
39
     * @return self
40
     */
41
    public static function create(string $id = null): self
42
    {
43
        $self = new self();
44
        $self->id = $id ?? (string) Uuid::uuid4();
45
46
        return $self;
47
    }
48
49
    /**
50
     * @param array $data
51
     *
52
     * @return self|ModelInterface
53
     */
54
    public static function fromPersistence(array $data): ModelInterface
55
    {
56
        $self = new self();
57
        $self->id = $data['id'];
58
        $self->courseId = $data['courseId'];
59
        $self->name = $data['name'];
60
        $self->url = $data['url'];
61
62
        return $self;
63
    }
64
65
    /**
66
     * @return array
67
     */
68
    public function toPersistence(): array
69
    {
70
        return [
71
            'id' => $this->id,
72
            'courseId' => $this->courseId,
73
            'name' => $this->name,
74
            'url' => $this->url,
75
        ];
76
    }
77
78
    /**
79
     * @return string
80
     */
81
    public function getId(): string
82
    {
83
        return $this->id;
84
    }
85
86
    /**
87
     * @return string
88
     */
89
    public function getName(): string
90
    {
91
        return $this->name;
92
    }
93
94
    /**
95
     * @param string $name
96
     *
97
     * @return self
98
     */
99
    public function setName(string $name): self
100
    {
101
        $this->name = $name;
102
103
        return $this;
104
    }
105
106
    /**
107
     * @return string
108
     */
109
    public function getUrl(): string
110
    {
111
        return $this->url;
112
    }
113
114
    /**
115
     * @param string $url
116
     *
117
     * @return self
118
     */
119
    public function setUrl(string $url): self
120
    {
121
        $this->url = $url;
122
123
        return $this;
124
    }
125
}
126