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

UserRole   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A validation() 0 9 1
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\Abstracts\AbstractUserRole;
14
use Phalcon\Filter\Validation\Validator\PresenceOf;
15
use Phalcon\Filter\Validation\Validator\Uniqueness;
16
use Zemit\Models\Interfaces\UserRoleInterface;
17
18
/**
19
 * @property User $UserEntity
20
 * @property Role $RoleEntity
21
 *
22
 * @method User getUserEntity(?array $params = null)
23
 * @method Role getRoleEntity(?array $params = null)
24
 */
25
class UserRole extends AbstractUserRole implements UserRoleInterface
26
{
27
    protected $deleted = self::NO;
28
    protected $position = self::NO;
29
30 4
    public function initialize(): void
31
    {
32 4
        parent::initialize();
33
34 4
        $this->hasOne('userId', User::class, 'id', ['alias' => 'UserEntity']);
35 4
        $this->hasOne('roleId', Role::class, 'id', ['alias' => 'RoleEntity']);
36
    }
37
38 2
    public function validation(): bool
39
    {
40 2
        $validator = $this->genericValidation();
41
        
42 2
        $validator->add('userId', new PresenceOf(['message' => $this->_('required')]));
43 2
        $validator->add('roleId', new PresenceOf(['message' => $this->_('required')]));
44 2
        $validator->add(['userId', 'roleId'], new Uniqueness(['message' => $this->_('not-unique')]));
45
46 2
        return $this->validate($validator);
47
    }
48
}
49