This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace ogheo\comments\models; |
||
4 | |||
5 | use Yii; |
||
6 | use yii\db\ActiveRecord; |
||
7 | use yii\behaviors\BlameableBehavior; |
||
8 | use yii\behaviors\TimestampBehavior; |
||
9 | use ogheo\comments\helpers\CommentsHelper; |
||
10 | use ogheo\comments\Module as CommentsModule; |
||
11 | |||
12 | /** |
||
13 | * This is the model class for table "comments_rating". |
||
14 | * |
||
15 | * @property $id |
||
16 | * @property $comment_id |
||
17 | * @property $created_by |
||
18 | * @property $updated_by |
||
19 | * @property $created_at |
||
20 | * @property $updated_at |
||
21 | * @property $ip |
||
22 | * @property $status |
||
23 | * |
||
24 | * @package ogheo\comments\models |
||
25 | */ |
||
26 | class CommentsRating extends \yii\db\ActiveRecord |
||
27 | { |
||
28 | /** |
||
29 | * Statuses |
||
30 | */ |
||
31 | const STATUS_LIKE = 1; |
||
32 | const STATUS_DISLIKE = 2; |
||
33 | |||
34 | /** |
||
35 | * Scenarios |
||
36 | */ |
||
37 | const SCENARIO_SAVE = 'save'; |
||
38 | const SCENARIO_UPDATE = 'update'; |
||
39 | const SCENARIO_DELETE = 'delete'; |
||
40 | |||
41 | /** |
||
42 | * @var string |
||
43 | */ |
||
44 | public static $commentRatingQueryModelClass = 'ogheo\comments\models\CommentsRatingQuery'; |
||
45 | |||
46 | /** |
||
47 | * @inheritdoc |
||
48 | */ |
||
49 | public static function tableName() |
||
50 | { |
||
51 | return 'comments_rating'; |
||
52 | } |
||
53 | |||
54 | /** |
||
55 | * @inheritdoc |
||
56 | */ |
||
57 | View Code Duplication | public function behaviors() |
|
0 ignored issues
–
show
|
|||
58 | { |
||
59 | return [ |
||
60 | 'blameable' => [ |
||
61 | 'class' => BlameableBehavior::className(), |
||
62 | 'createdByAttribute' => 'created_by', |
||
63 | 'updatedByAttribute' => 'updated_by', |
||
64 | ], |
||
65 | 'timestamp' => [ |
||
66 | 'class' => TimestampBehavior::className(), |
||
67 | 'attributes' => [ |
||
68 | ActiveRecord::EVENT_BEFORE_INSERT => ['created_at', 'updated_at'], |
||
69 | ActiveRecord::EVENT_BEFORE_UPDATE => ['updated_at'], |
||
70 | ] |
||
71 | ] |
||
72 | ]; |
||
73 | } |
||
74 | |||
75 | /** |
||
76 | * @inheritdoc |
||
77 | */ |
||
78 | public function scenarios() |
||
79 | { |
||
80 | $scenarios = parent::scenarios(); |
||
81 | |||
82 | $scenarios[self::SCENARIO_SAVE] = ['comment_id', 'status']; |
||
83 | $scenarios[self::SCENARIO_UPDATE] = ['comment_id', 'status']; |
||
84 | $scenarios[self::SCENARIO_DELETE] = ['comment_id', 'status']; |
||
85 | |||
86 | return $scenarios; |
||
87 | } |
||
88 | |||
89 | /** |
||
90 | * @inheritdoc |
||
91 | */ |
||
92 | public function rules() |
||
93 | { |
||
94 | return [ |
||
95 | [['comment_id', 'status'], 'required'], |
||
96 | [['created_by', 'updated_by', 'created_at', 'updated_at', 'status'], 'integer'], |
||
97 | [['comment_id'], function ($attribute, $params, $validator) { |
||
0 ignored issues
–
show
|
|||
98 | if ($this->scenario === self::SCENARIO_UPDATE) { |
||
99 | $comment_id = $this->$attribute; |
||
100 | } else { |
||
101 | $comment_id = CommentsHelper::decodeId($this->$attribute); |
||
102 | } |
||
103 | $commentClass = CommentsModule::getInstance()->commentModelClass; |
||
104 | View Code Duplication | if ((!intval($comment_id)) || (!$commentClass::find()->where(['id' => $comment_id])->exists())) { |
|
0 ignored issues
–
show
This code seems to be duplicated across 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. ![]() |
|||
105 | $this->addError( |
||
106 | $attribute, Yii::t('comments', 'Sorry, something went wrong. Please try again later.') |
||
107 | ); |
||
108 | } |
||
109 | }], |
||
110 | [['ip'], 'ip'], |
||
111 | [['ip'], 'string', 'max' => 46] |
||
112 | ]; |
||
113 | } |
||
114 | |||
115 | /** |
||
116 | * @inheritdoc |
||
117 | */ |
||
118 | public function beforeSave($insert) |
||
119 | { |
||
120 | if (parent::beforeSave($insert)) { |
||
121 | View Code Duplication | if ($this->hasAttribute('ip')) { |
|
0 ignored issues
–
show
This code seems to be duplicated across 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. ![]() |
|||
122 | if ($this->getAttribute('ip') === null) { |
||
123 | $this->setAttribute('ip', Yii::$app->request->getUserIP()); |
||
124 | } |
||
125 | } |
||
126 | |||
127 | if ($this->hasAttribute('comment_id')) { |
||
128 | $comment_id = $this->getAttribute('comment_id'); |
||
129 | if ($comment_id !== null) { |
||
130 | if ($this->scenario === self::SCENARIO_UPDATE) { |
||
131 | $this->setAttribute('comment_id', $comment_id); |
||
132 | } else { |
||
133 | $this->setAttribute('comment_id', CommentsHelper::decodeId($comment_id)); |
||
134 | } |
||
135 | } |
||
136 | } |
||
137 | |||
138 | return true; |
||
139 | } else { |
||
140 | return false; |
||
141 | } |
||
142 | } |
||
143 | |||
144 | /** |
||
145 | * @inheritdoc |
||
146 | * @return object CommentsRatingQuery the active query used by this AR class. |
||
147 | */ |
||
148 | public static function find() |
||
149 | { |
||
150 | return Yii::createObject(self::$commentRatingQueryModelClass, [get_called_class()]); |
||
151 | } |
||
152 | } |
||
153 |
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.