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

UserEntityTrait::createUserEntity()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 16
ccs 12
cts 12
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 12
nc 1
nop 1
crap 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\UserEntity;
17
18
/**
19
 * Class UserEntityTrait.
20
 */
21
trait UserEntityTrait
22
{
23
    /**
24
     * Returns a new instance of the required entity.
25
     *
26
     * @param string $entityClassName
27
     * @throws RuntimeException
28
     * @return UserEntity
29
     */
30
    abstract protected function getNewEntityInstance($entityClassName);
31
32
    /**
33
     * Creates a new User Entity instance form the data.
34
     *
35
     * @param array $data
36
     * @return UserEntity
37
     */
38 2
    protected function createUserEntity(array $data)
39
    {
40 2
        $entity = $this->getNewEntityInstance(UserEntity::class);
41
42 2
        $entity->setUserId($data['id_user'])
43 2
            ->setUserName($data['username'])
44 2
            ->setEmail($data['email'])
45 2
            ->setPassword($data['password'])
46 2
            ->setHash($data['hash'])
47 2
            ->setActive($data['is_active'])
48 2
            ->setEnabled($data['is_enabled'])
49 2
            ->setDateCreated(new DateTime($data['date_created']))
50 2
            ->setDateModified(new DateTime($data['date_modified']));
51
52 2
        return $entity;
53
    }
54
}
55