Passed
Push — master ( 6df11d...8e8817 )
by Julien
05:21
created

Role   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 16
c 0
b 0
f 0
dl 0
loc 29
ccs 15
cts 15
cp 1
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A initialize() 0 11 1
A validation() 0 11 1
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 Phalcon\Filter\Validation\Validator\PresenceOf;
14
use Phalcon\Filter\Validation\Validator\StringLength\Max;
15
use Zemit\Models\Abstracts\AbstractRole;
16
use Zemit\Models\Interfaces\RoleInterface;
17
18
/**
19
 * @property UserRole[] $UserNode
20
 * @property User[] $UserList
21
 * @property Group[] $GroupList
22
 * @property GroupRole[] $GroupNode
23
 *
24
 * @method UserRole[] getUserNode(?array $params = null)
25
 * @method User[] getUserList(?array $params = null)
26
 * @method GroupRole[] getGroupNode(?array $params = null)
27
 * @method Group[] getGroupList(?array $params = null)
28
 */
29
class Role extends AbstractRole implements RoleInterface
30
{
31
    protected $position = 0;
32
    protected $deleted = self::NO;
33
34 4
    public function initialize(): void
35
    {
36 4
        parent::initialize();
37
38 4
        $this->hasMany('id', UserRole::class, 'roleId', ['alias' => 'UserNode']);
39 4
        $this->hasManyToMany('id', UserRole::class, 'roleId',
40 4
            'userId', User::class, 'id', ['alias' => 'UserList']);
41
42 4
        $this->hasMany('id', GroupRole::class, 'roleId', ['alias' => 'GroupNode']);
43 4
        $this->hasManyToMany('id', GroupRole::class, 'roleId',
44 4
            'groupId', Group::class, 'id', ['alias' => 'GroupList']);
45
    }
46
47 2
    public function validation(): bool
48
    {
49 2
        $validator = $this->genericValidation();
50
51 2
        $validator->add('index', new PresenceOf(['message' => $this->_('required')]));
52 2
        $validator->add('index', new Max(['max' => 50, 'message' => $this->_('length-exceeded')]));
53
54 2
        $validator->add('label', new PresenceOf(['message' => $this->_('required')]));
55 2
        $validator->add('label', new Max(['max' => 100, 'message' => $this->_('length-exceeded')]));
56
57 2
        return $this->validate($validator);
58
    }
59
}
60