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

ApplicationStorage   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 57
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A populateEntity() 11 11 1
A getApplicationById() 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;
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