Passed
Push — master ( b96172...42f4b0 )
by Gabor
04:04
created

UserToGroupCoupler   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 39
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 3
dl 39
loc 39
ccs 0
cts 6
cp 0
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A getDependingEntity() 6 6 2

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
 * WebHemi.
4
 *
5
 * PHP version 5.6
6
 *
7
 * @copyright 2012 - 2016 Gixx-web (http://www.gixx-web.com)
8
 * @license   https://opensource.org/licenses/MIT The MIT License (MIT)
9
 *
10
 * @link      http://www.gixx-web.com
11
 */
12
namespace WebHemi\Data\Coupler;
13
14
use WebHemi\Data\Coupler\Traits\UserEntityTrait;
15
use WebHemi\Data\Coupler\Traits\UserGroupEntityTrait;
16
use WebHemi\Data\Entity\DataEntityInterface;
17
use WebHemi\Data\Entity\User\UserEntity;
18
use WebHemi\Data\Entity\User\UserGroupEntity;
19
20
/**
21
 * Class UserToPolicyCoupler.
22
 */
23 View Code Duplication
class UserToGroupCoupler extends AbstractDataCoupler
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...
24
{
25
    /** @var string */
26
    protected $connectorIdKey = 'id_user_to_user_group';
27
    /** @var string */
28
    protected $connectorDataGroup = 'webhemi_user_to_user_group';
29
    /** @var array */
30
    protected $dependentDataGroups = [
31
        UserEntity::class => [
32
            'source_key' => 'fk_user',
33
            'connector_key' => 'fk_user_group',
34
            'depending_group' => 'webhemi_user_group',
35
            'depending_id_key' => 'id_user_group',
36
        ],
37
        UserGroupEntity::class => [
38
            'source_key' => 'fk_user_group',
39
            'connector_key' => 'fk_user',
40
            'depending_group' => 'webhemi_user',
41
            'depending_id_key' => 'id_user',
42
        ]
43
    ];
44
45
    use UserEntityTrait;
46
    use UserGroupEntityTrait;
47
48
    /**
49
     * Gets a DataEntityInterface instance from the provided data according to the reference entity.
50
     *
51
     * @param DataEntityInterface $referenceEntity
52
     * @param array               $entityData
53
     * @return DataEntityInterface
54
     */
55
    protected function getDependingEntity(DataEntityInterface $referenceEntity, array $entityData)
56
    {
57
        return $referenceEntity instanceof UserEntity
58
            ? $this->createUserGroupEntity($entityData)
59
            : $this->createUserEntity($entityData);
60
    }
61
}
62