Completed
Pull Request — master (#400)
by
unknown
05:58
created

ImportLabels::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
1
<?php
2
3
namespace CultuurNet\UDB3\Organizer\Commands;
4
5
use CultuurNet\UDB3\Model\ValueObject\Taxonomy\Label\Label;
6
use CultuurNet\UDB3\Model\ValueObject\Taxonomy\Label\Labels;
7
use CultuurNet\UDB3\Offer\Commands\AuthorizableCommandInterface;
8
use CultuurNet\UDB3\Role\ValueObjects\Permission;
9
use CultuurNet\UDB3\Security\LabelSecurityInterface;
10
use ValueObjects\StringLiteral\StringLiteral;
11
12
class ImportLabels extends AbstractOrganizerCommand implements AuthorizableCommandInterface, LabelSecurityInterface
13
{
14
    /**
15
     * @var Labels
16
     */
17
    private $labels;
18
19
    /**
20
     * @var Labels
21
     */
22
    private $labelsToKeepIfAlreadyOnOrganizer;
23
24
    /**
25
     * @param string $organizerId
26
     * @param Labels $label
27
     */
28
    public function __construct(
29
        $organizerId,
30
        Labels $label
31
    ) {
32
        parent::__construct($organizerId);
33
        $this->labels = $label;
34
        $this->labelsToKeepIfAlreadyOnOrganizer = new Labels();
35
    }
36
37
    public function withLabelsToKeepIfAlreadyOnOrganizer(Labels $labels): self
38
    {
39
        $c = clone $this;
40
        $c->labelsToKeepIfAlreadyOnOrganizer = $labels;
41
        return $c;
42
    }
43
44
    public function getLabelsToKeepIfAlreadyOnOrganizer(): Labels
45
    {
46
        return $this->labelsToKeepIfAlreadyOnOrganizer;
47
    }
48
49
    /**
50
     * @return Labels
51
     */
52
    public function getLabels()
53
    {
54
        return $this->labels;
55
    }
56
57
    /**
58
     * @inheritdoc
59
     */
60
    public function getItemId()
61
    {
62
        return $this->getOrganizerId();
63
    }
64
65
    /**
66
     * @inheritdoc
67
     */
68
    public function getPermission()
69
    {
70
        return Permission::AANBOD_BEWERKEN();
71
    }
72
73
    /**
74
     * @inheritdoc
75
     */
76
    public function getNames()
77
    {
78
        return array_map(
79
            function (Label $label) {
80
                return new StringLiteral($label->getName()->toString());
81
            },
82
            $this->getLabels()->toArray()
83
        );
84
    }
85
}
86