Code Duplication    Length = 54-57 lines in 3 locations

src/WebHemi/Data/Storage/AccessManagement/ResourceStorage.php 1 location

@@ 22-78 (lines=57) @@
19
/**
20
 * Class ResourceStorage.
21
 */
22
class ResourceStorage extends AbstractDataStorage
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
    protected function populateEntity(DataEntityInterface &$entity, array $data)
48
    {
49
        /* @var ResourceEntity $entity */
50
        $entity->setResourceId($data[$this->idKey])
51
            ->setName($data[$this->name])
52
            ->setTitle($data[$this->title])
53
            ->setDescription($data[$this->description])
54
            ->setReadOnly($data[$this->isReadOnly])
55
            ->setDateCreated(new DateTime($data[$this->dateCreated]))
56
            ->setDateModified(new DateTime($data[$this->dateModified]));
57
    }
58
59
    /**
60
     * Returns a Resource entity identified by (unique) ID.
61
     *
62
     * @param int $identifier
63
     *
64
     * @return bool|ResourceEntity
65
     */
66
    public function getResourceById($identifier)
67
    {
68
        $entity = false;
69
        $data = $this->getDataAdapter()->getData($identifier);
70
71
        if (!empty($data)) {
72
            $entity = $this->createEntity();
73
            $this->populateEntity($entity, $data);
74
        }
75
76
        return $entity;
77
    }
78
}
79

src/WebHemi/Data/Storage/ApplicationStorage.php 1 location

@@ 21-77 (lines=57) @@
18
/**
19
 * Class ApplicationStorage.
20
 */
21
class ApplicationStorage extends AbstractDataStorage
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

src/WebHemi/Data/Storage/User/UserGroupStorage.php 1 location

@@ 22-75 (lines=54) @@
19
/**
20
 * Class UserGroupStorage.
21
 */
22
class UserGroupStorage extends AbstractDataStorage
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
    protected function populateEntity(DataEntityInterface &$entity, array $data)
46
    {
47
        /* @var UserGroupEntity $entity */
48
        $entity->setUserGroupId($data[$this->idKey])
49
            ->setTitle($data[$this->title])
50
            ->setDescription($data[$this->description])
51
            ->setReadOnly($data[$this->isReadOnly])
52
            ->setDateCreated(new DateTime($data[$this->dateCreated]))
53
            ->setDateModified(new DateTime($data[$this->dateModified]));
54
    }
55
56
    /**
57
     * Returns a User Group entity identified by (unique) ID.
58
     *
59
     * @param int $identifier
60
     *
61
     * @return bool|UserGroupEntity
62
     */
63
    public function getUserGroupById($identifier)
64
    {
65
        $entity = false;
66
        $data = $this->getDataAdapter()->getData($identifier);
67
68
        if (!empty($data)) {
69
            $entity = $this->createEntity();
70
            $this->populateEntity($entity, $data);
71
        }
72
73
        return $entity;
74
    }
75
}
76