Completed
Push — impl-EZP-26000-permission-look... ( 500ba3 )
by
unknown
26:49
created

Aggregate::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 6
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 6
loc 6
cc 2
eloc 3
nc 2
nop 1
rs 9.4285
1
<?php
2
3
/**
4
 * @copyright Copyright (C) eZ Systems AS. All rights reserved.
5
 * @license For full copyright and license information view LICENSE file distributed with this source code.
6
 */
7
namespace eZ\Publish\Core\Repository\PermissionResolver\PermissionInfoMapper;
8
9
use eZ\Publish\API\Repository\Exceptions\NotImplementedException;
10
use eZ\Publish\API\Repository\Values\User\UserReference;
11
use eZ\Publish\API\Repository\Values\ValueObject;
12
use eZ\Publish\Core\Repository\PermissionResolver\PermissionInfoMapper;
13
14
/**
15
 * todo
16
 */
17 View Code Duplication
class Aggregate extends PermissionInfoMapper
0 ignored issues
show
Duplication introduced by
This class 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...
18
{
19
    /**
20
     * @var \eZ\Publish\Core\Repository\PermissionResolver\PermissionInfoMapper[]
21
     */
22
    private $mappers;
23
24
    /**
25
     * @param \eZ\Publish\Core\Repository\PermissionResolver\PermissionInfoMapper[] $mappers
26
     */
27
    public function __construct(array $mappers = [])
28
    {
29
        foreach ($mappers as $mapper) {
30
            $this->addMapper($mapper);
31
        }
32
    }
33
34
    /**
35
     * @param \eZ\Publish\Core\Repository\PermissionResolver\PermissionInfoMapper $mapper
36
     */
37
    public function addMapper(PermissionInfoMapper $mapper)
38
    {
39
        $this->mappers[] = $mapper;
40
    }
41
42
    public function canMap(ValueObject $object)
43
    {
44
        return true;
45
    }
46
47
    public function map(ValueObject $object, UserReference $userReference)
48
    {
49
        foreach ($this->mappers as $mapper) {
50
            if ($mapper->canMap($object)) {
51
                return $mapper->map($object, $userReference);
52
            }
53
        }
54
55
        throw new NotImplementedException(
56
            'No mapper available for: ' . get_class($object)
57
        );
58
    }
59
}
60