Passed
Push — master ( 1c4d89...16aad8 )
by Gabor
03:50
created

UserGroupEntityTrait   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 1
lcom 0
cbo 1
dl 0
loc 31
ccs 9
cts 9
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
getNewEntityInstance() 0 1 ?
A createUserGroupEntity() 0 13 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\Coupler\Traits;
13
14
use DateTime;
15
use RuntimeException;
16
use WebHemi\Data\Entity\User\UserGroupEntity;
17
18
/**
19
 * Class UserGroupEntityTrait.
20
 */
21
trait UserGroupEntityTrait
22
{
23
    /**
24
     * Returns a new instance of the required entity.
25
     *
26
     * @param string $entityClassName
27
     * @throws RuntimeException
28
     * @return UserGroupEntity
29
     */
30
    abstract protected function getNewEntityInstance($entityClassName);
31
32
    /**
33
     * Creates a new Policy Entity instance form the data.
34
     *
35
     * @param array $data
36
     * @return UserGroupEntity
37
     */
38 2
    protected function createUserGroupEntity(array $data)
39
    {
40 2
        $entity = $this->getNewEntityInstance(UserGroupEntity::class);
41
42 2
        $entity->setUserGroupId($data['id_user_group'])
43 2
            ->setTitle($data['title'])
44 2
            ->setDescription($data['description'])
45 2
            ->setReadOnly($data['is_read_only'])
46 2
            ->setDateCreated(new DateTime($data['date_created']))
47 2
            ->setDateModified(new DateTime($data['date_created']));
48
49 2
        return $entity;
50
    }
51
}
52