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

Aggregate   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 43
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 43
loc 43
rs 10
wmc 7
lcom 1
cbo 2

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 6 6 2
A addMapper() 4 4 1
A canMap() 4 4 1
A map() 12 12 3

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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