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

UserGroupStorage::getUserGroupById()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 7

Duplication

Lines 12
Ratio 100 %

Code Coverage

Tests 8
CRAP Score 2

Importance

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