Passed
Push — master ( 9b3fb0...881b80 )
by Jérémy
02:18
created

WorkspaceDto::fromArray()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 10
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 14
rs 9.9332
1
<?php
2
3
declare(strict_types=1);
4
5
namespace JDecool\Clockify\Model;
6
7
class WorkspaceDto
8
{
9
    private $hourlyRate;
10
    private $id;
11
    private $imageUrl;
12
    private $memberships;
13
    private $name;
14
    private $workspaceSettings;
15
16
    public static function fromArray(array $data): self
17
    {
18
        return new self(
19
            HourlyRateDto::fromArray($data['hourlyRate']),
20
            $data['id'],
21
            $data['imageUrl'],
22
            array_map(
23
                static function(array $data): MembershipDto {
24
                    return MembershipDto::fromArray($data);
25
                },
26
                $data['memberships']
27
            ),
28
            $data['name'],
29
            WorkspaceSettingsDto::fromArray($data['workspaceSettings'])
30
        );
31
    }
32
33
    /**
34
     * @param MembershipDto[] $memberships
35
     */
36
    public function __construct(
37
        ?HourlyRateDto $hourlyRate,
38
        string $id,
39
        string $imageUrl,
40
        array $memberships,
41
        string $name,
42
        WorkspaceSettingsDto $workspaceSettings
43
    ) {
44
        $this->hourlyRate = $hourlyRate;
45
        $this->id = $id;
46
        $this->imageUrl = $imageUrl;
47
        $this->memberships = $memberships;
48
        $this->name = $name;
49
        $this->workspaceSettings = $workspaceSettings;
50
    }
51
52
    public function hourlyRate(): ?HourlyRateDto
53
    {
54
        return $this->hourlyRate;
55
    }
56
57
    public function id(): string
58
    {
59
        return $this->id;
60
    }
61
62
    public function imageUrl(): string
63
    {
64
        return $this->imageUrl;
65
    }
66
67
    /**
68
     * @return MembershipDto[]
69
     */
70
    public function memberships()
71
    {
72
        return $this->memberships;
73
    }
74
75
    public function name(): string
76
    {
77
        return $this->name;
78
    }
79
80
    public function workspaceSettings(): WorkspaceSettingsDto
81
    {
82
        return $this->workspaceSettings;
83
    }
84
}
85