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

ApplicationStorage::getApplicationById()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 7

Duplication

Lines 12
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 6

Importance

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