Completed
Pull Request — master (#356)
by Luc
05:49
created

GodUserReadRepositoryDecorator::getByName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace CultuurNet\UDB3\Label\ReadModels\JSON\Repository;
4
5
use ValueObjects\Identity\UUID;
6
use ValueObjects\StringLiteral\StringLiteral;
7
8
class GodUserReadRepositoryDecorator implements ReadRepositoryInterface
9
{
10
    /**
11
     * @var ReadRepositoryInterface
12
     */
13
    private $repository;
14
15
    /**
16
     * @var string[]
17
     */
18
    private $godUserIds;
19
20
    /**
21
     * @param ReadRepositoryInterface $readRepository
22
     * @param array $godUserIds
23
     */
24
    public function __construct(ReadRepositoryInterface $readRepository, array $godUserIds)
25
    {
26
        $this->repository = $readRepository;
27
        $this->godUserIds = $godUserIds;
28
    }
29
30
    /**
31
     * @inheritdoc
32
     */
33
    public function getByUuid(UUID $uuid)
34
    {
35
        return $this->repository->getByUuid($uuid);
36
    }
37
38
    /**
39
     * @inheritdoc
40
     */
41
    public function getByName(StringLiteral $name)
42
    {
43
        return $this->repository->getByName($name);
44
    }
45
46
    /**
47
     * @inheritdoc
48
     */
49
    public function canUseLabel(StringLiteral $userId, StringLiteral $name)
50
    {
51
        if (in_array($userId->toNative(), $this->godUserIds)) {
52
            // God users can use any label.
53
            return true;
54
        }
55
56
        return $this->repository->canUseLabel($userId, $name);
57
    }
58
59
    /**
60
     * @inheritdoc
61
     */
62
    public function search(Query $query)
63
    {
64
        return $this->repository->search($query);
65
    }
66
67
    /**
68
     * @inheritdoc
69
     */
70
    public function searchTotalLabels(Query $query)
71
    {
72
        return $this->repository->searchTotalLabels($query);
73
    }
74
}
75