Code Duplication    Length = 53-53 lines in 2 locations

src/WebHemi/Data/Coupler/UserGroupToPolicyCoupler.php 1 location

@@ 24-76 (lines=53) @@
21
/**
22
 * Class UserToPolicyCoupler.
23
 */
24
class UserGroupToPolicyCoupler extends AbstractDataCoupler
25
{
26
    /** @var string */
27
    protected $connectorIdKey = 'id_user_group_to_am_policy';
28
    /** @var string */
29
    protected $connectorDataGroup = 'webhemi_user_group_to_am_policy';
30
    /** @var array */
31
    protected $dependentDataGroups = [
32
        UserGroupEntity::class => [
33
            'source_key' => 'fk_user_group',
34
            'connector_key' => 'fk_am_policy',
35
            'depending_group' => 'webhemi_am_policy',
36
            'depending_id_key' => 'id_am_policy',
37
        ],
38
        PolicyEntity::class => [
39
            'source_key' => 'fk_am_policy',
40
            'connector_key' => 'fk_user_group',
41
            'depending_group' => 'webhemi_user_group',
42
            'depending_id_key' => 'id_user_group',
43
        ]
44
    ];
45
46
    use UserGroupEntityTrait;
47
    use PolicyEntityTrait;
48
49
    /**
50
     * Gets all the entities those are depending from the given entity.
51
     *
52
     * @param DataEntityInterface $entity
53
     * @throws RuntimeException
54
     * @return array<DataEntityInterface>
55
     */
56
    public function getEntityDependencies(DataEntityInterface $entity)
57
    {
58
        $entityClass = get_class($entity);
59
        if (!isset($this->dataEntityPrototypes[$entityClass])) {
60
            throw new RuntimeException(
61
                sprintf('Cannot use this coupler class to find dependencies for %s.', $entityClass)
62
            );
63
        }
64
65
        $entityList = [];
66
        $dataList = $this->getEntityDataSet($entity);
67
68
        foreach ($dataList as $entityData) {
69
            $entityList[] = $entity instanceof UserGroupEntity
70
                ? $this->createPolicyEntity($entityData)
71
                : $this->createUserGroupEntity($entityData);
72
        }
73
74
        return $entityList;
75
    }
76
}
77

src/WebHemi/Data/Coupler/UserToPolicyCoupler.php 1 location

@@ 24-76 (lines=53) @@
21
/**
22
 * Class UserToPolicyCoupler.
23
 */
24
class UserToPolicyCoupler extends AbstractDataCoupler
25
{
26
    /** @var string */
27
    protected $connectorIdKey = 'id_user_to_am_policy';
28
    /** @var string */
29
    protected $connectorDataGroup = 'webhemi_user_to_am_policy';
30
    /** @var array */
31
    protected $dependentDataGroups = [
32
        UserEntity::class => [
33
            'source_key' => 'fk_user',
34
            'connector_key' => 'fk_am_policy',
35
            'depending_group' => 'webhemi_am_policy',
36
            'depending_id_key' => 'id_am_policy',
37
        ],
38
        PolicyEntity::class => [
39
            'source_key' => 'fk_am_policy',
40
            'connector_key' => 'fk_user',
41
            'depending_group' => 'webhemi_user',
42
            'depending_id_key' => 'id_user',
43
        ]
44
    ];
45
46
    use UserEntityTrait;
47
    use PolicyEntityTrait;
48
49
    /**
50
     * Gets all the entities those are depending from the given entity.
51
     *
52
     * @param DataEntityInterface $entity
53
     * @throws RuntimeException
54
     * @return array<DataEntityInterface>
55
     */
56
    public function getEntityDependencies(DataEntityInterface $entity)
57
    {
58
        $entityClass = get_class($entity);
59
        if (!isset($this->dataEntityPrototypes[$entityClass])) {
60
            throw new RuntimeException(
61
                sprintf('Cannot use this coupler class to find dependencies for %s.', $entityClass)
62
            );
63
        }
64
65
        $entityList = [];
66
        $dataList = $this->getEntityDataSet($entity);
67
68
        foreach ($dataList as $entityData) {
69
            $entityList[] = $entity instanceof UserEntity
70
                ? $this->createPolicyEntity($entityData)
71
                : $this->createUserEntity($entityData);
72
        }
73
74
        return $entityList;
75
    }
76
}
77