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

ResourceStorage::populateEntity()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 8

Duplication

Lines 11
Ratio 100 %

Code Coverage

Tests 9
CRAP Score 1

Importance

Changes 0
Metric Value
dl 11
loc 11
ccs 9
cts 9
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 8
nc 1
nop 2
crap 1
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\AccessManagement;
13
14
use DateTime;
15
use WebHemi\Data\Entity\DataEntityInterface;
16
use WebHemi\Data\Entity\AccessManagement\ResourceEntity;
17
use WebHemi\Data\Storage\AbstractDataStorage;
18
19
/**
20
 * Class ResourceStorage.
21
 */
22 View Code Duplication
class ResourceStorage 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_am_resource';
26
    /** @var string */
27
    protected $idKey = 'id_am_resource';
28
    /** @var string */
29
    private $name = 'name';
30
    /** @var string */
31
    private $title = 'title';
32
    /** @var string */
33
    private $description = 'description';
34
    /** @var string */
35
    private $isReadOnly = 'is_read_only';
36
    /** @var string */
37
    private $dateCreated = 'date_created';
38
    /** @var string */
39
    private $dateModified = 'date_modified';
40
41
    /**
42
     * Populates an entity with storage data.
43
     *
44
     * @param DataEntityInterface $entity
45
     * @param array               $data
46
     */
47 1
    protected function populateEntity(DataEntityInterface &$entity, array $data)
48
    {
49
        /* @var ResourceEntity $entity */
50 1
        $entity->setResourceId($data[$this->idKey])
51 1
            ->setName($data[$this->name])
52 1
            ->setTitle($data[$this->title])
53 1
            ->setDescription($data[$this->description])
54 1
            ->setReadOnly($data[$this->isReadOnly])
55 1
            ->setDateCreated(new DateTime($data[$this->dateCreated]))
56 1
            ->setDateModified(new DateTime($data[$this->dateModified]));
57 1
    }
58
59
    /**
60
     * Returns a Resource entity identified by (unique) ID.
61
     *
62
     * @param int $identifier
63
     *
64
     * @return bool|ResourceEntity
65
     */
66 1
    public function getResourceById($identifier)
67
    {
68 1
        $entity = false;
69 1
        $data = $this->getDataAdapter()->getData($identifier);
70
71 1
        if (!empty($data)) {
72 1
            $entity = $this->createEntity();
73 1
            $this->populateEntity($entity, $data);
74 1
        }
75
76 1
        return $entity;
77
    }
78
}
79