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

PolicyEntityTrait::createPolicyEntity()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 17
Code Lines 12

Duplication

Lines 17
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 17
loc 17
ccs 0
cts 14
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 12
nc 1
nop 1
crap 2
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