Completed
Push — master ( 73b08b...9131b2 )
by Laurens
02:28
created

Category::getCreateData()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 4
cts 4
cp 1
rs 9.6666
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 0
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace LauLamanApps\IzettleApi\API\Product;
6
7
use DateTime;
8
use LauLamanApps\IzettleApi\API\Universal\IzettlePostable;
9
use Ramsey\Uuid\Uuid;
10
use Ramsey\Uuid\UuidInterface;
11
12
final class Category implements IzettlePostable
13
{
14
    private $uuid;
15
    private $name;
16
    private $etag;
17
    private $updatedAt;
18
    private $updatedBy;
19
    private $createdAt;
20
21 4
    public static function create(
22
        UuidInterface $uuid,
23
        string $name,
24
        string $etag = null,
25
        DateTime $updatedAt = null,
26
        UuidInterface $updatedBy = null,
27
        DateTime $createdAt = null
28
    ): self {
29 4
        return new self(
30 4
            $uuid,
31 4
            $name,
32 4
            $etag,
33 4
            $updatedAt,
34 4
            $updatedBy,
35 4
            $createdAt
36
        );
37
    }
38
39 3
    public static function new(string $name): self
40
    {
41 3
        return new self(
42 3
            Uuid::uuid1(),
43 3
            $name
44
        );
45
    }
46
47 6
    public function getUuid(): UuidInterface
48
    {
49 6
        return $this->uuid;
50
    }
51
52 4
    public function getName(): string
53
    {
54 4
        return $this->name;
55
    }
56
57 4
    public function getEtag(): ?string
58
    {
59 4
        return $this->etag;
60
    }
61
62 4
    public function getUpdatedAt(): ?DateTime
63
    {
64 4
        return $this->updatedAt;
65
    }
66
67 4
    public function getUpdatedBy(): ?UuidInterface
68
    {
69 4
        return $this->updatedBy;
70
    }
71
72 4
    public function getCreatedAt(): ?DateTime
73
    {
74 4
        return $this->createdAt;
75
    }
76
77
78 1
    public function getPostBodyData(): string
79
    {
80
        $data = [
81 1
            'uuid' => $this->uuid,
82 1
            'name' => $this->name,
83
        ];
84
85 1
        return json_encode($data);
86
    }
87
88 7
    private function __construct(
89
        UuidInterface $uuid,
90
        string $name,
91
        ?string $etag = null,
92
        ?DateTime $updatedAt = null,
93
        ?UuidInterface $updatedBy = null,
94
        ?DateTime $createdAt = null
95
    ) {
96 7
        $this->uuid = $uuid;
97 7
        $this->name = $name;
98 7
        $this->etag = $etag;
99 7
        $this->updatedAt = $updatedAt;
100 7
        $this->updatedBy = $updatedBy;
101 7
        $this->createdAt = $createdAt;
102 7
    }
103
}
104