Passed
Push — master ( 4a9186...cf0fc9 )
by vistart
03:05
created

Assignment::init()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 8
ccs 6
cts 6
cp 1
rs 9.4285
cc 3
eloc 5
nc 2
nop 0
crap 3
1
<?php
2
3
/**
4
 *  _   __ __ _____ _____ ___  ____  _____
5
 * | | / // // ___//_  _//   ||  __||_   _|
6
 * | |/ // /(__  )  / / / /| || |     | |
7
 * |___//_//____/  /_/ /_/ |_||_|     |_|
8
 * @link https://vistart.me/
9
 * @copyright Copyright (c) 2016 - 2017 vistart
10
 * @license https://vistart.me/license/
11
 */
12
13
namespace rhosocial\user\rbac;
14
15
use rhosocial\user\User;
16
17
/**
18
 * @version 1.0
19
 * @author vistart <[email protected]>
20
 */
21
class Assignment extends \yii\rbac\Assignment
22
{
23
    /**
24
     * @var string|User user ID (see [[\rhosocial\user\User::guid]])
25
     */
26
    public $userGuid;
27
    
28
    /**
29
     * @var string the time of invalidation of this Assignment. (Format: Y-m-d H:i:s) 
30
     */
31
    public $failedAt;
32
    
33 14
    public function init()
34
    {
35 14
        if ($this->failedAt !== null && strtotime($this->failedAt) < strtotime(date('Y-m-d H:i:s'))) {
36 2
            return \Yii::$app->db->createCommand()
37 2
                ->delete(\Yii::$app->authManager->assignmentTable, ['user_guid' => (string) $this->userGuid, 'item_name' => $this->roleName])
38 2
                ->execute() > 0;
39
        }
40
    }
41
}