Passed
Branch master (41990d)
by Gabor
03:31
created

UserGroupStorage   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 54
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 3
dl 54
loc 54
ccs 16
cts 16
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A populateEntity() 10 10 1
A getUserGroupById() 12 12 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\Storage\User;
13
14
use DateTime;
15
use WebHemi\Data\Entity\DataEntityInterface;
16
use WebHemi\Data\Entity\User\UserGroupEntity;
17
use WebHemi\Data\Storage\AbstractDataStorage;
18
19
/**
20
 * Class UserGroupStorage.
21
 */
22 View Code Duplication
class UserGroupStorage extends AbstractDataStorage
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...
23
{
24
    /** @var string */
25
    protected $dataGroup = 'webhemi_user_group';
26
    /** @var string */
27
    protected $idKey = 'id_user_group';
28
    /** @var string */
29
    private $title = 'title';
30
    /** @var string */
31
    private $description = 'description';
32
    /** @var string */
33
    private $isReadOnly = 'is_read_only';
34
    /** @var string */
35
    private $dateCreated = 'date_created';
36
    /** @var string */
37
    private $dateModified = 'date_modified';
38
39
    /**
40
     * Populates an entity with storage data.
41
     *
42
     * @param DataEntityInterface $entity
43
     * @param array               $data
44
     */
45 1
    protected function populateEntity(DataEntityInterface &$entity, array $data)
46
    {
47
        /* @var UserGroupEntity $entity */
48 1
        $entity->setUserGroupId($data[$this->idKey])
49 1
            ->setTitle($data[$this->title])
50 1
            ->setDescription($data[$this->description])
51 1
            ->setReadOnly($data[$this->isReadOnly])
52 1
            ->setDateCreated(new DateTime($data[$this->dateCreated]))
53 1
            ->setDateModified(new DateTime($data[$this->dateModified]));
54 1
    }
55
56
    /**
57
     * Returns a User Group entity identified by (unique) ID.
58
     *
59
     * @param int $identifier
60
     *
61
     * @return bool|UserGroupEntity
62
     */
63 1
    public function getUserGroupById($identifier)
64
    {
65 1
        $entity = false;
66 1
        $data = $this->getDataAdapter()->getData($identifier);
67
68 1
        if (!empty($data)) {
69 1
            $entity = $this->createEntity();
70 1
            $this->populateEntity($entity, $data);
71 1
        }
72
73 1
        return $entity;
74
    }
75
}
76