Test Failed
Push — master ( 741545...e25e21 )
by Julien
11:23
created

GroupRole   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
eloc 11
c 1
b 0
f 0
dl 0
loc 23
ccs 0
cts 10
cp 0
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A initialize() 0 6 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 Zemit\Models\Base\AbstractGroupRole;
14
use Phalcon\Validation\Validator\PresenceOf;
15
use Phalcon\Validation\Validator\Uniqueness;
16
17
/**
18
 * Class GroupRole
19
 *
20
 * @property Group $Group
21
 * @property Role $Role
22
 * @property Group $GroupEntity
23
 * @property Role $RoleEntity
24
 *
25
 * @method Group getGroup($params = null)
26
 * @method Role getRole($params = null)
27
 * @method Group getGroupEntity($params = null)
28
 * @method Role getRoleEntity($params = null)
29
 *
30
 * @package Zemit\Models
31
 */
32
class GroupRole extends AbstractGroupRole
33
{
34
    protected $deleted = self::NO;
35
    protected $position = self::NO;
36
37
    public function initialize()
38
    {
39
        parent::initialize();
40
41
        $this->hasOne('groupId', Group::class, 'id', ['alias' => 'GroupEntity']);
42
        $this->hasOne('roleId', Role::class, 'id', ['alias' => 'RoleEntity']);
43
    }
44
45
    public function validation()
46
    {
47
        $validator = $this->genericValidation();
48
49
        $validator->add('groupId', new PresenceOf(['message' => $this->_('required')]));
50
        $validator->add('roleId', new PresenceOf(['message' => $this->_('required')]));
51
        $validator->add(['groupId', 'roleId'], new Uniqueness(['message' => $this->_('not-unique')]));
52
53
        return $this->validate($validator);
54
    }
55
}
56