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

UserRole   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Test Coverage

Coverage 40%

Importance

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

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 2
    public function initialize(): void
31
    {
32 2
        parent::initialize();
33
34 2
        $this->hasOne('userId', User::class, 'id', ['alias' => 'UserEntity']);
35 2
        $this->hasOne('roleId', Role::class, 'id', ['alias' => 'RoleEntity']);
36
    }
37
38
    public function validation(): bool
39
    {
40
        $validator = $this->genericValidation();
41
        
42
        $validator->add('userId', new PresenceOf(['message' => $this->_('required')]));
43
        $validator->add('roleId', new PresenceOf(['message' => $this->_('required')]));
44
        $validator->add(['userId', 'roleId'], new Uniqueness(['message' => $this->_('not-unique')]));
45
46
        return $this->validate($validator);
47
    }
48
}
49