Passed
Push — master ( 64ab61...b96172 )
by Gabor
09:36
created

PolicyEntityTrait   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 26
Duplicated Lines 65.38 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 1
lcom 0
cbo 1
dl 17
loc 26
ccs 0
cts 14
cp 0
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A createPolicyEntity() 17 17 1

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\Traits;
13
14
use DateTime;
15
use WebHemi\Data\Entity\AccessManagement\PolicyEntity;
16
17
/**
18
 * Class PolicyEntityTrait.
19
 */
20
trait PolicyEntityTrait
21
{
22
    /**
23
     * Creates a new Policy Entity instance form the data.
24
     *
25
     * @param array $data
26
     * @return PolicyEntity
27
     */
28 View Code Duplication
    protected function createPolicyEntity(array $data)
0 ignored issues
show
Duplication introduced by
This method 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...
29
    {
30
        /* @var PolicyEntity $entity */
31
        $entity = parent::getNewEntityInstance(PolicyEntity::class);
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (getNewEntityInstance() instead of createPolicyEntity()). Are you sure this is correct? If so, you might want to change this to $this->getNewEntityInstance().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
32
33
        $entity->setPolicyId($data['id_am_policy'])
34
            ->setResourceId($data['fk_am_resource'])
35
            ->setApplicationId($data['fk_application'])
36
            ->setTitle($data['title'])
37
            ->setDescription($data['description'])
38
            ->setReadOnly($data['is_read_only'])
39
            ->setAllowed($data['is_allowed'])
40
            ->setDateCreated(new DateTime($data['date_created']))
41
            ->setDateModified(new DateTime($data['date_created']));
42
43
        return $entity;
44
    }
45
}
46