Test Failed
Push — master ( 513669...a14d6b )
by Julien
09:38 queued 04:28
created

User::beforeSave()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
/**
3
 * This file is part of the Zemit Framework.
4
 *
5
 * (c) Zemit Team <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE.txt
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Zemit\Models;
12
13
use Zemit\Models\Abstracts\AbstractUser;
14
use Zemit\Models\Interfaces\UserInterface;
15
16
/**
17
 * @property File[] $Files
18
 * @method File[] getFiles(?array $params = null)
19
 *
20
 * @property UserGroup[] $GroupNode
21
 * @method UserGroup[] getGroupNode(?array $params = null)
22
 *
23
 * @property Group[] $Groups
24
 * @method Group[] getGroups(?array $params = null)
25
 *
26
 * @property UserRole[] $RoleNode
27
 * @method UserRole[] getRoleNode(?array $params = null)
28
 *
29
 * @property Role[] $Roles
30
 * @method Role[] getRoles(?array $params = null)
31
 *
32
 * @property UserType[] $TypeNode
33
 * @method UserType[] getTypeNode(?array $params = null)
34
 *
35
 * @property Type[] $Types
36
 * @method Type[] getTypes(?array $params = null)
37
 *
38
 * @property UserFeature[] $FeatureNode
39
 * @method UserFeature[] getFeatureNode(?array $params = null)
40
 *
41
 * @property Feature[] $Features
42
 * @method Feature[] getFeatures(?array $params = null)
43
 */
44
class User extends AbstractUser implements UserInterface
45
{
46
    protected $deleted = self::NO;
47
    
48 2
    public function initialize(): void
49
    {
50 2
        parent::initialize();
51
        
52 2
        $this->hasMany('id', File::Class, 'userId', ['alias' => 'Files']);
0 ignored issues
show
Bug introduced by
The constant Zemit\Models\File::Class was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
53
        
54 2
        $this->hasMany('id', UserGroup::class, 'userId', ['alias' => 'GroupNodes']);
55 2
        $this->hasManyToMany(
56 2
            'id',
57 2
            UserGroup::Class,
0 ignored issues
show
Bug introduced by
The constant Zemit\Models\UserGroup::Class was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
58 2
            'userId',
59 2
            'groupId',
60 2
            Group::class,
61 2
            'id',
62 2
            ['alias' => 'Groups']
63 2
        );
64
        
65 2
        $this->hasMany('id', UserRole::class, 'userId', ['alias' => 'RoleNodes']);
66 2
        $this->hasManyToMany(
67 2
            'id',
68 2
            UserRole::Class,
0 ignored issues
show
Bug introduced by
The constant Zemit\Models\UserRole::Class was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
69 2
            'userId',
70 2
            'roleId',
71 2
            Role::class,
72 2
            'id',
73 2
            ['alias' => 'Roles']
74 2
        );
75
        
76 2
        $this->hasMany('id', UserType::class, 'userId', ['alias' => 'TypeNodes']);
77 2
        $this->hasManyToMany(
78 2
            'id',
79 2
            UserType::Class,
0 ignored issues
show
Bug introduced by
The constant Zemit\Models\UserType::Class was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
80 2
            'userId',
81 2
            'typeId',
82 2
            Type::class,
83 2
            'id',
84 2
            ['alias' => 'Types']
85 2
        );
86
        
87 2
        $this->hasMany('id', UserFeature::class, 'userId', ['alias' => 'FeatureNodes']);
88 2
        $this->hasManyToMany(
89 2
            'id',
90 2
            UserFeature::Class,
0 ignored issues
show
Bug introduced by
The constant Zemit\Models\UserFeature::Class was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
91 2
            'userId',
92 2
            'featureId',
93 2
            Feature::class,
94 2
            'id',
95 2
            ['alias' => 'Features']
96 2
        );
97
    }
98
    
99 2
    public function validation(): bool
100
    {
101 2
        $validator = $this->genericValidation();
102
        
103 2
        $this->addEmailValidation($validator, 'email', false);
104
        
105 2
        return $this->validate($validator);
106
    }
107
    
108
    /**
109
     * @param string|null $password
110
     *
111
     * @return bool If the hash is valid or not
112
     */
113
    public function checkPassword(string $password = null): bool
114
    {
115
        return $password && $this->checkHash($this->getPassword(), $password);
116
    }
117
}
118