Completed
Push — master ( 664c38...4ed7d3 )
by Jonas
19s queued 12s
created

getLabelsToRemoveWhenOnOffer()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace CultuurNet\UDB3\Offer\Commands;
4
5
use CultuurNet\UDB3\Model\ValueObject\Taxonomy\Label\Label;
6
use CultuurNet\UDB3\Model\ValueObject\Taxonomy\Label\Labels;
7
use CultuurNet\UDB3\Security\LabelSecurityInterface;
8
use ValueObjects\StringLiteral\StringLiteral;
9
10
abstract class AbstractImportLabels extends AbstractCommand implements LabelSecurityInterface
11
{
12
    /**
13
     * @var Labels
14
     */
15
    private $labels;
16
17
    /**
18
     * @var Labels
19
     */
20
    private $labelsToKeepIfAlreadyOnOffer;
21
22
    /**
23
     * @var Labels
24
     */
25
    private $labelsToRemoveWhenOnOffer;
26
27
    /**
28
     * @param string $itemId
29
     * @param Labels $labels
30
     */
31
    public function __construct($itemId, Labels $labels)
32
    {
33
        parent::__construct($itemId);
34
        $this->labels = $labels;
35
        $this->labelsToKeepIfAlreadyOnOffer = new Labels();
36
        $this->labelsToRemoveWhenOnOffer = new Labels();
37
    }
38
39
    public function withLabelsToKeepIfAlreadyOnOffer(Labels $labels): self
40
    {
41
        $c = clone $this;
42
        $c->labelsToKeepIfAlreadyOnOffer = $labels;
43
        return $c;
44
    }
45
46
    public function getLabelsToKeepIfAlreadyOnOffer(): Labels
47
    {
48
        return $this->labelsToKeepIfAlreadyOnOffer;
49
    }
50
51
    public function withLabelsToRemoveWhenOnOffer(Labels $labels): self
52
    {
53
        $c = clone $this;
54
        $c->labelsToRemoveWhenOnOffer = $labels;
55
        return $c;
56
    }
57
58
    public function getLabelsToRemoveWhenOnOffer(): Labels
59
    {
60
        return $this->labelsToRemoveWhenOnOffer;
61
    }
62
63
    /**
64
     * @return Labels
65
     */
66 View Code Duplication
    public function getLabelsToImport()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
67
    {
68
        $labelNamesToKeep = array_map(
69
            function (Label $label) {
70
                return $label->getName();
71
            },
72
            $this->labelsToKeepIfAlreadyOnOffer->toArray()
73
        );
74
75
        return $this->labels->filter(
76
            function (Label $label) use ($labelNamesToKeep) {
77
                return !in_array($label->getName(), $labelNamesToKeep);
78
            }
79
        );
80
    }
81
82
    /**
83
     * @inheritdoc
84
     */
85
    public function getNames()
86
    {
87
        return array_map(
88
            function (Label $label) {
89
                return new StringLiteral($label->getName()->toString());
90
            },
91
            $this->getLabelsToImport()->toArray()
92
        );
93
    }
94
}
95