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.
Passed
Pull Request — master (#191)
by Herbert
10:39
created

AuditTrail   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 5

Test Coverage

Coverage 87.1%

Importance

Changes 0
Metric Value
dl 0
loc 68
ccs 27
cts 31
cp 0.871
rs 10
c 0
b 0
f 0
wmc 8
lcom 2
cbo 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A tableName() 0 4 1
A attributeLabels() 0 15 1
A getEntry() 0 4 1
A getDiffHtml() 0 15 3
A getParent() 0 6 2
1
<?php
2
3
namespace bedezign\yii2\audit\models;
4
5
use bedezign\yii2\audit\components\db\ActiveRecord;
6
use Yii;
7
8
/**
9
 * AuditTrail
10
 *
11
 * @property integer $id
12
 * @property integer $entry_id
13
 * @property integer $user_id
14
 * @property string  $action
15
 * @property string  $model
16
 * @property string  $model_id
17
 * @property string  $field
18
 * @property string  $new_value
19
 * @property string  $old_value
20
 * @property string  $created
21
 *
22
 * @property AuditEntry    $entry
23
 */
24
class AuditTrail extends ActiveRecord
25
{
26
27
    /**
28
     * @inheritdoc
29
     */
30 52
    public static function tableName()
31
    {
32 52
        return '{{%audit_trail}}';
33
    }
34
35
    /**
36
     * @return array customized attribute labels (name=>label)
37
     */
38 8
    public function attributeLabels()
39
    {
40
        return [
41 8
            'id'        => Yii::t('audit', 'ID'),
42 8
            'entry_id'  => Yii::t('audit', 'Entry ID'),
43 8
            'user_id'   => Yii::t('audit', 'User ID'),
44 8
            'action'    => Yii::t('audit', 'Action'),
45 8
            'model'     => Yii::t('audit', 'Type'),
46 8
            'model_id'  => Yii::t('audit', 'Model ID'),
47 8
            'field'     => Yii::t('audit', 'Field'),
48 8
            'old_value' => Yii::t('audit', 'Old Value'),
49 8
            'new_value' => Yii::t('audit', 'New Value'),
50 8
            'created'   => Yii::t('audit', 'Created'),
51 8
        ];
52
    }
53
54
    /**
55
     * @return \yii\db\ActiveQuery
56
     */
57 2
    public function getEntry()
58
    {
59 2
        return $this->hasOne(AuditEntry::className(), ['id' => 'entry_id']);
60
    }
61
62
    /**
63
     * @return mixed
64
     */
65 8
    public function getDiffHtml()
66
    {
67 8
        $old = explode("\n", $this->old_value);
68 8
        $new = explode("\n", $this->new_value);
69
70 8
        foreach ($old as $i => $line) {
71 8
            $old[$i] = rtrim($line, "\r\n");
72 8
        }
73 8
        foreach ($new as $i => $line) {
74 8
            $new[$i] = rtrim($line, "\r\n");
75 8
        }
76
77 8
        $diff = new \Diff($old, $new);
78 8
        return $diff->render(new \Diff_Renderer_Html_Inline);
79
    }
80
81
    /**
82
     * @return ActiveRecord|bool
83
     */
84
    public function getParent()
85
    {
86
        $parentModel = new $this->model;
87
        $parent = $parentModel::findOne($this->model_id);
88
        return $parent ? $parent : $parentModel;
89
    }
90
    
91
}
92