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.

Submission   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 159
Duplicated Lines 6.29 %

Coupling/Cohesion

Components 1
Dependencies 8

Importance

Changes 0
Metric Value
wmc 11
lcom 1
cbo 8
dl 10
loc 159
rs 10
c 0
b 0
f 0

9 Methods

Rating   Name   Duplication   Size   Complexity  
A getSubject() 0 16 1
A setSubject() 0 4 1
A tableName() 0 4 1
A rules() 0 25 1
A behaviors() 0 11 1
A attributeLabels() 0 25 1
A search() 0 26 3
A getForm() 0 4 1
A getStatuses() 10 10 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace app\models;
4
5
use app\properties\AbstractModel;
6
use app\properties\HasProperties;
7
use Yii;
8
use yii\data\ActiveDataProvider;
9
use yii\helpers\ArrayHelper;
10
11
/**
12
 * This is the model class for table "submission".
13
 * @property integer $id
14
 * @property integer $form_id
15
 * @property string $date_received
16
 * @property string $ip
17
 * @property string $user_agent
18
 * @property string $piwik_visitor_id
19
 * @property string $additional_information
20
 * @property string $date_viewed
21
 * @property string $date_processed
22
 * @property integer $processed_by_user_id
23
 * @property integer $processed
24
 * @property string $internal_comment
25
 * @property string $submission_referrer
26
 * @property string $visitor_referrer
27
 * @property string $visitor_landing
28
 * @property string $visit_start_date
29
 * @property integer $form_fill_time
30
 * @property integer $is_deleted
31
 * @property bool $spam
32
 * @property int $sending_status
33
 * @property AbstractModel $abstractModel
34
 * @property Form $form
35
 */
36
class Submission extends \yii\db\ActiveRecord
37
{
38
    const STATUS_NEW = 0;
39
    const STATUS_SUCCESS = 1;
40
    const STATUS_ERROR = -1;
41
    const STATUS_HOPELESS_ERROR = -2;
42
    const STATUS_FATAL_ERROR = -3;
43
44
    protected $subject = null;
45
46
    /**
47
     * @return null
0 ignored issues
show
Documentation introduced by
Should the return type not be string?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
48
     */
49
    public function getSubject()
50
    {
51
        $message = $this->form->subject_template;
52
        $params = array_reduce(
53
            array_keys($this->abstractModel->getAttributes()),
54
            function ($arr, $i) {
55
                $arr['{'.$i.'}'] = $this->property($i);
0 ignored issues
show
Bug introduced by
The method property() does not exist on app\models\Submission. Did you maybe mean canGetProperty()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
56
                return $arr;
57
            },
58
            []
59
        );
60
        $params['{id}'] = $this->id;
61
        $params['{form_name}'] = $this->form->name;
62
        return strtr($message, $params);
63
64
    }
65
66
    /**
67
     * @param null $subject
68
     */
69
    public function setSubject($subject)
70
    {
71
        $this->subject = $subject;
72
    }
73
74
    /**
75
     * @inheritdoc
76
     */
77
    public static function tableName()
78
    {
79
        return '{{%submission}}';
80
    }
81
82
    /**
83
     * @inheritdoc
84
     */
85
    public function rules()
86
    {
87
        return [
88
            [['form_id'], 'required'],
89
            [
90
                ['form_id', 'processed_by_user_id', 'processed', 'form_fill_time', 'is_deleted', 'sending_status'],
91
                'integer'
92
            ],
93
            [['date_received', 'date_viewed', 'date_processed', 'visit_start_date'], 'safe'],
94
            [
95
                [
96
                    'ip',
97
                    'user_agent',
98
                    'piwik_visitor_id',
99
                    'additional_information',
100
                    'internal_comment',
101
                    'submission_referrer',
102
                    'visitor_referrer',
103
                    'visitor_landing'
104
                ],
105
                'string'
106
            ],
107
            [['spam'], 'integer']
108
        ];
109
    }
110
111
    public function behaviors()
112
    {
113
        return [
114
            [
115
                'class' => HasProperties::className(),
0 ignored issues
show
Deprecated Code introduced by
The method yii\base\BaseObject::className() has been deprecated with message: since 2.0.14. On PHP >=5.5, use `::class` instead.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
116
            ],
117
            [
118
                'class' => \devgroup\TagDependencyHelper\ActiveRecordHelper::className(),
0 ignored issues
show
Deprecated Code introduced by
The method yii\base\BaseObject::className() has been deprecated with message: since 2.0.14. On PHP >=5.5, use `::class` instead.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
119
            ],
120
        ];
121
    }
122
123
    /**
124
     * @inheritdoc
125
     */
126
    public function attributeLabels()
127
    {
128
        return [
129
            'id' => Yii::t('app', 'ID'),
130
            'form_id' => Yii::t('app', 'Form ID'),
131
            'date_received' => Yii::t('app', 'Date Received'),
132
            'ip' => Yii::t('app', 'Ip'),
133
            'user_agent' => Yii::t('app', 'User Agent'),
134
            'piwik_visitor_id' => Yii::t('app', 'Piwik Visitor ID'),
135
            'additional_information' => Yii::t('app', 'Additional Information'),
136
            'date_viewed' => Yii::t('app', 'Date Viewed'),
137
            'date_processed' => Yii::t('app', 'Date Processed'),
138
            'processed_by_user_id' => Yii::t('app', 'Processed By User ID'),
139
            'processed' => Yii::t('app', 'Processed'),
140
            'internal_comment' => Yii::t('app', 'Internal Comment'),
141
            'submission_referrer' => Yii::t('app', 'Submission Referrer'),
142
            'visitor_referrer' => Yii::t('app', 'Visitor Referrer'),
143
            'visitor_landing' => Yii::t('app', 'Visitor Landing'),
144
            'visit_start_date' => Yii::t('app', 'Visit Start Date'),
145
            'form_fill_time' => Yii::t('app', 'Form Fill Time'),
146
            'spam' => Yii::t('app', 'Spam Info'),
147
            'is_deleted' => Yii::t('app', 'Is deleted'),
148
            'sending_status' => Yii::t('app', 'Sending status'),
149
        ];
150
    }
151
152
    public function search($params, $form_id = null, $show_deleted = 0)
153
    {
154
        /* @var $query \yii\db\ActiveQuery */
155
        $query = self::find();
156
        if ($form_id != null) {
157
            $query->andWhere('form_id = :form_id', [':form_id' => $form_id]);
158
        }
159
160
        $query->andFilterWhere(['is_deleted' => $show_deleted]);
161
162
        $dataProvider = new ActiveDataProvider(
163
            [
164
                'query' => $query,
165
                'pagination' => [
166
                    'pageSize' => 10,
167
                ],
168
            ]
169
        );
170
        if (!($this->load($params))) {
171
            return $dataProvider;
172
        }
173
        $query->andFilterWhere(['id' => $this->id]);
174
        $query->andFilterWhere(['like', 'ip', $this->ip]);
175
        $query->andFilterWhere(['like', 'user_agent', $this->user_agent]);
176
        return $dataProvider;
177
    }
178
179
    public function getForm()
180
    {
181
        return $this->hasOne(Form::className(), ['id' => 'form_id']);
0 ignored issues
show
Deprecated Code introduced by
The method yii\base\BaseObject::className() has been deprecated with message: since 2.0.14. On PHP >=5.5, use `::class` instead.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
182
    }
183
184 View Code Duplication
    public static function getStatuses()
185
    {
186
        return [
187
            self::STATUS_NEW => Yii::t('app', 'New'),
188
            self::STATUS_SUCCESS => Yii::t('app', 'Success'),
189
            self::STATUS_ERROR => Yii::t('app', 'Error'),
190
            self::STATUS_FATAL_ERROR => Yii::t('app', 'Fatal error'),
191
            self::STATUS_HOPELESS_ERROR => Yii::t('app', 'Hopeless error'),
192
        ];
193
    }
194
}
195