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

Role   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Test Coverage

Coverage 53.33%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A validation() 0 11 1
A initialize() 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 2
    public function initialize(): void
35
    {
36 2
        parent::initialize();
37
38 2
        $this->hasMany('id', UserRole::class, 'roleId', ['alias' => 'UserNode']);
39 2
        $this->hasManyToMany('id', UserRole::class, 'roleId',
40 2
            'userId', User::class, 'id', ['alias' => 'UserList']);
41
42 2
        $this->hasMany('id', GroupRole::class, 'roleId', ['alias' => 'GroupNode']);
43 2
        $this->hasManyToMany('id', GroupRole::class, 'roleId',
44 2
            'groupId', Group::class, 'id', ['alias' => 'GroupList']);
45
    }
46
47
    public function validation(): bool
48
    {
49
        $validator = $this->genericValidation();
50
51
        $validator->add('index', new PresenceOf(['message' => $this->_('required')]));
52
        $validator->add('index', new Max(['max' => 50, 'message' => $this->_('length-exceeded')]));
53
54
        $validator->add('label', new PresenceOf(['message' => $this->_('required')]));
55
        $validator->add('label', new Max(['max' => 100, 'message' => $this->_('length-exceeded')]));
56
57
        return $this->validate($validator);
58
    }
59
}
60