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.
Completed
Push — master ( 20a803...a4a304 )
by Pavel
38:30
created

JsonBehavior::encodeValidate()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 9
Code Lines 5

Duplication

Lines 9
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 9
loc 9
ccs 0
cts 0
cp 0
rs 9.2
cc 4
eloc 5
nc 3
nop 0
crap 20
1
<?php
2
namespace paulzi\jsonBehavior;
3
4
use yii\base\Behavior;
5
use yii\db\ActiveRecord;
6
7
/**
8
 *  @property ActiveRecord $owner
9
 */
10
class JsonBehavior extends Behavior
11
{
12
    /**
13
     * @var array
14
     */
15
    public $attributes = [];
16
17
18
    /**
19
     * @inheritdoc
20
     */
21
    public function events()
22
    {
23
        return [
24
            ActiveRecord::EVENT_INIT            => function () { $this->initialization(); },
25
            ActiveRecord::EVENT_AFTER_FIND      => function () { $this->decode(); },
26
            ActiveRecord::EVENT_BEFORE_VALIDATE => function () { $this->encodeValidate(); },
27
            ActiveRecord::EVENT_BEFORE_INSERT   => function () { $this->encode(); },
28
            ActiveRecord::EVENT_BEFORE_UPDATE   => function () { $this->encode(); },
29
            ActiveRecord::EVENT_AFTER_VALIDATE  => function () { $this->decode(); },
30 5
            ActiveRecord::EVENT_AFTER_INSERT    => function () { $this->decode(); },
31
            ActiveRecord::EVENT_AFTER_UPDATE    => function () { $this->decode(); },
32
        ];
33
    }
34
35 5
    /**
36
     */
37 5
    protected function initialization()
38 5
    {
39 5
        foreach ($this->attributes as $attribute) {
40 5
            $this->owner->setAttribute($attribute, new JsonField());
41
        }
42
    }
43
44 4
    /**
45
     */
46 4 View Code Duplication
    protected function decode()
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...
47 4
    {
48 4
        foreach ($this->attributes as $attribute) {
49 4
            $value = $this->owner->getAttribute($attribute);
50 4
            if (!$value instanceof JsonField) {
51 4
                $value = new JsonField($value);
52 4
            }
53 4
            $this->owner->setAttribute($attribute, $value);
54
        }
55
    }
56
57 4
    /**
58
     */
59 4 View Code Duplication
    protected function encode()
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...
60 4
    {
61 4
        foreach ($this->attributes as $attribute) {
62
            $field = $this->owner->getAttribute($attribute);
63
            if (!$field instanceof JsonField) {
64 4
                $field = new JsonField($field);
65 4
            }
66 4
            $this->owner->setAttribute($attribute, (string)$field ?: null);
67
        }
68
    }
69
70
    /**
71
     */
72 View Code Duplication
    protected function encodeValidate()
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...
73
    {
74
        foreach ($this->attributes as $attribute) {
75
            $field = $this->owner->getAttribute($attribute);
76
            if ($field instanceof JsonField) {
77
                $this->owner->setAttribute($attribute, (string)$field ?: null);
78
            }
79
        }
80
    }
81
}
82