GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

LockedBehavior::lock()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10

Duplication

Lines 10
Ratio 100 %

Importance

Changes 0
Metric Value
dl 10
loc 10
rs 9.9332
c 0
b 0
f 0
cc 2
nc 2
nop 0
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: vadim
5
 * Date: 05.02.16
6
 * Time: 12:57
7
 */
8
9
namespace sibds\components;
10
11
12
use yii\base\Behavior;
13
use yii\base\Exception;
14
15
class LockedBehavior extends Behavior
16
{
17
    public $lockedAttribute;
18
19
    public $valueLock = true;
20
    public $valueUnlock = false;
21
22
    public function events()
23
    {
24
        return [
25
            ActiveRecord::EVENT_BEFORE_INSERT => 'getDefaultValue',
26
        ];
27
    }
28
29
    public function getDefaultValue($event)
0 ignored issues
show
Unused Code introduced by
The parameter $event is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
30
    {
31
        $owner = $this->owner;
32
        if ($owner->hasAttribute($this->lockedAttribute)) {
33
            if (empty($owner->{$this->lockedAttribute}) || is_null($owner->{$this->lockedAttribute})) {
34
                $owner->{$this->lockedAttribute} = $this->valueUnlock;
35
            }
36
        }
37
    }
38
39 View Code Duplication
    public function lock()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
40
    {
41
        /* @var $owner ActiveRecord */
42
        $owner = $this->owner;
43
44
        $owner->{$this->lockedAttribute} = $this->valueLock;
45
        if(!$owner->validate())
46
            throw new \yii\db\Exception('Error saving model! Validating not comlete: ' . implode('; ', $owner->firstErrors));
47
        $owner->save();
48
    }
49
50 View Code Duplication
    public function unlock()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
51
    {
52
        /* @var $owner ActiveRecord */
53
        $owner = $this->owner;
54
55
        $owner->{$this->lockedAttribute} = $this->valueUnlock;
56
        if(!$owner->validate())
57
            throw new \yii\db\Exception('Error saving model! Validating not comlete: ' . implode('; ', $owner->firstErrors));
58
59
        $owner->save();
60
    }
61
}
62