Passed
Branch master (0828fa)
by Gabor
03:19
created

UserGroupEntityTrait   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

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

2 Methods

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