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\controllers; |
||
4 | |||
5 | use Yii; |
||
6 | use yii\helpers\Url; |
||
7 | use yii\web\Response; |
||
8 | use yii\widgets\ActiveForm; |
||
9 | use yii\filters\VerbFilter; |
||
10 | use yii\filters\AccessControl; |
||
11 | use yii\filters\ContentNegotiator; |
||
12 | use yii\caching\TagDependency; |
||
13 | use ogheo\comments\models\CommentsRating; |
||
14 | use ogheo\comments\helpers\CommentsHelper; |
||
15 | use ogheo\comments\models\Comments as CommentsModel; |
||
16 | |||
17 | /** |
||
18 | * Class DefaultController for the `comments` module |
||
19 | * @package ogheo\comments\controllers |
||
20 | */ |
||
21 | class DefaultController extends \yii\web\Controller |
||
22 | { |
||
23 | /** |
||
24 | * @inheritdoc |
||
25 | */ |
||
26 | public function behaviors() |
||
27 | { |
||
28 | return [ |
||
29 | 'verbs' => [ |
||
30 | 'class' => VerbFilter::className(), |
||
31 | 'actions' => [ |
||
32 | 'rate' => ['post'], |
||
33 | 'create' => ['post'], |
||
34 | 'validate' => ['post'] |
||
35 | ], |
||
36 | ], |
||
37 | 'contentNegotiator' => [ |
||
38 | 'class' => ContentNegotiator::className(), |
||
39 | 'only' => ['rate', 'create', 'validate'], |
||
40 | 'formats' => [ |
||
41 | 'application/json' => Response::FORMAT_JSON, |
||
42 | ], |
||
43 | ], |
||
44 | 'access' => [ |
||
45 | 'class' => AccessControl::className(), |
||
46 | 'only' => ['rate', 'create', 'validate'], |
||
47 | 'rules' => [ |
||
48 | [ |
||
49 | 'allow' => true, |
||
50 | 'actions' => ['create', 'validate'], |
||
51 | 'roles' => ['?', '@'], |
||
52 | ], |
||
53 | [ |
||
54 | 'allow' => true, |
||
55 | 'actions' => ['rate'], |
||
56 | 'roles' => ['@'], |
||
57 | ], |
||
58 | ], |
||
59 | ], |
||
60 | ]; |
||
61 | } |
||
62 | |||
63 | /** |
||
64 | * Create new comment |
||
65 | * @param $data |
||
66 | * @return string |
||
67 | */ |
||
68 | public function actionCreate($data) |
||
69 | { |
||
70 | if (Yii::$app->request->isAjax && Yii::$app->request->isPost) { |
||
71 | $comment = new CommentsModel( |
||
72 | array_merge( |
||
73 | CommentsHelper::decryptData($data), |
||
74 | [ |
||
75 | 'scenario' => Yii::$app->user->isGuest ? |
||
76 | CommentsModel::SCENARIO_GUEST : CommentsModel::SCENARIO_USER |
||
77 | ] |
||
78 | ) |
||
79 | ); |
||
80 | |||
81 | if (Yii::$app->user->isGuest && ($comment->username === null && $comment->email === null)) { |
||
82 | $comment->username = CommentsHelper::getUsername(); |
||
83 | $comment->email = CommentsHelper::getEmail(); |
||
84 | } |
||
85 | |||
86 | if ($comment->load(Yii::$app->request->post()) && $comment->validate()) { |
||
87 | if ($comment->save()) { |
||
88 | if ($comment->username !== null && $comment->email !== null) { |
||
89 | CommentsHelper::setUsername($comment->username); |
||
90 | CommentsHelper::setEmail($comment->email); |
||
91 | } |
||
92 | |||
93 | TagDependency::invalidate( |
||
94 | Yii::$app->cache, |
||
95 | Url::previous(Yii::$app->controller->module->urlCacheSessionKey) |
||
96 | ); |
||
97 | |||
98 | return [ |
||
99 | 'status' => 'success', |
||
100 | 'message' => Yii::t('comments', 'Comment has been added successfully.') |
||
101 | ]; |
||
102 | } |
||
103 | } else { |
||
104 | return [ |
||
105 | 'status' => 'error', |
||
106 | 'errors' => $comment->errors |
||
107 | ]; |
||
108 | } |
||
109 | } |
||
110 | |||
111 | return [ |
||
112 | 'status' => 'error', |
||
113 | 'message' => Yii::t('comments', 'Sorry, something went wrong. Please try again later.') |
||
114 | ]; |
||
115 | } |
||
116 | |||
117 | /** |
||
118 | * Validate new comment |
||
119 | * @throws \yii\base\ExitException |
||
120 | */ |
||
121 | public function actionValidate() |
||
122 | { |
||
123 | $model = new CommentsModel([ |
||
124 | 'scenario' => Yii::$app->user->isGuest ? |
||
125 | CommentsModel::SCENARIO_GUEST : CommentsModel::SCENARIO_USER |
||
126 | ]); |
||
127 | |||
128 | if (Yii::$app->request->isAjax && $model->load(Yii::$app->request->post())) { |
||
129 | Yii::$app->response->data = ActiveForm::validate($model); |
||
130 | Yii::$app->response->send(); |
||
131 | Yii::$app->end(); |
||
132 | } |
||
133 | } |
||
134 | |||
135 | /** |
||
136 | * Rate comments |
||
137 | * @return array |
||
138 | */ |
||
139 | public function actionRate() |
||
140 | { |
||
141 | if (Yii::$app->request->isAjax && Yii::$app->request->isPost) { |
||
142 | $newRating = new CommentsRating(['scenario' => CommentsRating::SCENARIO_SAVE]); |
||
143 | if ($newRating->load(Yii::$app->request->post()) && $newRating->validate()) { |
||
144 | |||
145 | $oldRating = CommentsRating::findOne([ |
||
146 | 'comment_id' => CommentsHelper::decodeId($newRating->comment_id), |
||
0 ignored issues
–
show
|
|||
147 | 'created_by' => Yii::$app->getUser()->getId() |
||
0 ignored issues
–
show
The method
getUser does only exist in yii\web\Application , but not in yii\console\Application .
It seems like the method you are trying to call exists only in some of the possible types. Let’s take a look at an example: class A
{
public function foo() { }
}
class B extends A
{
public function bar() { }
}
/**
* @param A|B $x
*/
function someFunction($x)
{
$x->foo(); // This call is fine as the method exists in A and B.
$x->bar(); // This method only exists in B and might cause an error.
}
Available Fixes
![]() |
|||
148 | ]); |
||
149 | |||
150 | if ($oldRating) { |
||
151 | if ($oldRating->status == $newRating->status) { |
||
0 ignored issues
–
show
The property
status does not exist on object<ogheo\comments\models\CommentsRating> . Since you implemented __get , maybe consider adding a @property annotation.
Since your code implements the magic getter <?php
/**
* @property int $x
* @property int $y
* @property string $text
*/
class MyLabel
{
private $properties;
private $allowedProperties = array('x', 'y', 'text');
public function __get($name)
{
if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
return $properties[$name];
} else {
return null;
}
}
public function __set($name, $value)
{
if (in_array($name, $this->allowedProperties)) {
$properties[$name] = $value;
} else {
throw new \LogicException("Property $name is not defined.");
}
}
}
If the property has read access only, you can use the @property-read annotation instead. Of course, you may also just have mistyped another name, in which case you should fix the error. See also the PhpDoc documentation for @property. ![]() |
|||
152 | $oldRating->scenario = CommentsRating::SCENARIO_DELETE; |
||
153 | View Code Duplication | if ($oldRating->delete()) { |
|
0 ignored issues
–
show
The expression
$oldRating->delete() of type false|integer is loosely compared to true ; this is ambiguous if the integer can be zero. You might want to explicitly use !== null instead.
In PHP, under loose comparison (like For 0 == false // true
0 == null // true
123 == false // false
123 == null // false
// It is often better to use strict comparison
0 === false // false
0 === null // false
![]() 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. ![]() |
|||
154 | if ($oldRating->status == 1) { |
||
0 ignored issues
–
show
The property
status does not exist on object<ogheo\comments\models\CommentsRating> . Since you implemented __get , maybe consider adding a @property annotation.
Since your code implements the magic getter <?php
/**
* @property int $x
* @property int $y
* @property string $text
*/
class MyLabel
{
private $properties;
private $allowedProperties = array('x', 'y', 'text');
public function __get($name)
{
if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
return $properties[$name];
} else {
return null;
}
}
public function __set($name, $value)
{
if (in_array($name, $this->allowedProperties)) {
$properties[$name] = $value;
} else {
throw new \LogicException("Property $name is not defined.");
}
}
}
If the property has read access only, you can use the @property-read annotation instead. Of course, you may also just have mistyped another name, in which case you should fix the error. See also the PhpDoc documentation for @property. ![]() |
|||
155 | CommentsHelper::deleteUprated($oldRating->comment_id); |
||
0 ignored issues
–
show
The property
comment_id does not exist on object<ogheo\comments\models\CommentsRating> . Since you implemented __get , maybe consider adding a @property annotation.
Since your code implements the magic getter <?php
/**
* @property int $x
* @property int $y
* @property string $text
*/
class MyLabel
{
private $properties;
private $allowedProperties = array('x', 'y', 'text');
public function __get($name)
{
if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
return $properties[$name];
} else {
return null;
}
}
public function __set($name, $value)
{
if (in_array($name, $this->allowedProperties)) {
$properties[$name] = $value;
} else {
throw new \LogicException("Property $name is not defined.");
}
}
}
If the property has read access only, you can use the @property-read annotation instead. Of course, you may also just have mistyped another name, in which case you should fix the error. See also the PhpDoc documentation for @property. ![]() |
|||
156 | } elseif ($oldRating->status == 2) { |
||
0 ignored issues
–
show
The property
status does not exist on object<ogheo\comments\models\CommentsRating> . Since you implemented __get , maybe consider adding a @property annotation.
Since your code implements the magic getter <?php
/**
* @property int $x
* @property int $y
* @property string $text
*/
class MyLabel
{
private $properties;
private $allowedProperties = array('x', 'y', 'text');
public function __get($name)
{
if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
return $properties[$name];
} else {
return null;
}
}
public function __set($name, $value)
{
if (in_array($name, $this->allowedProperties)) {
$properties[$name] = $value;
} else {
throw new \LogicException("Property $name is not defined.");
}
}
}
If the property has read access only, you can use the @property-read annotation instead. Of course, you may also just have mistyped another name, in which case you should fix the error. See also the PhpDoc documentation for @property. ![]() |
|||
157 | CommentsHelper::deleteDownrated($oldRating->comment_id); |
||
0 ignored issues
–
show
The property
comment_id does not exist on object<ogheo\comments\models\CommentsRating> . Since you implemented __get , maybe consider adding a @property annotation.
Since your code implements the magic getter <?php
/**
* @property int $x
* @property int $y
* @property string $text
*/
class MyLabel
{
private $properties;
private $allowedProperties = array('x', 'y', 'text');
public function __get($name)
{
if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
return $properties[$name];
} else {
return null;
}
}
public function __set($name, $value)
{
if (in_array($name, $this->allowedProperties)) {
$properties[$name] = $value;
} else {
throw new \LogicException("Property $name is not defined.");
}
}
}
If the property has read access only, you can use the @property-read annotation instead. Of course, you may also just have mistyped another name, in which case you should fix the error. See also the PhpDoc documentation for @property. ![]() |
|||
158 | } |
||
159 | |||
160 | TagDependency::invalidate( |
||
161 | Yii::$app->cache, |
||
162 | Url::previous(Yii::$app->controller->module->urlCacheSessionKey) |
||
163 | ); |
||
164 | |||
165 | return [ |
||
166 | 'status' => 'success', |
||
167 | 'action' => 'unrated', |
||
168 | 'message' => Yii::t('comments', 'Comment rating has been updated successfully.') |
||
169 | ]; |
||
170 | } |
||
171 | } else { |
||
172 | $oldRating->status = $newRating->status; |
||
0 ignored issues
–
show
The property
status does not exist on object<ogheo\comments\models\CommentsRating> . Since you implemented __set , maybe consider adding a @property annotation.
Since your code implements the magic setter <?php
/**
* @property int $x
* @property int $y
* @property string $text
*/
class MyLabel
{
private $properties;
private $allowedProperties = array('x', 'y', 'text');
public function __get($name)
{
if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
return $properties[$name];
} else {
return null;
}
}
public function __set($name, $value)
{
if (in_array($name, $this->allowedProperties)) {
$properties[$name] = $value;
} else {
throw new \LogicException("Property $name is not defined.");
}
}
}
Since the property has write access only, you can use the @property-write annotation instead. Of course, you may also just have mistyped another name, in which case you should fix the error. See also the PhpDoc documentation for @property. ![]() |
|||
173 | $oldRating->scenario = CommentsRating::SCENARIO_UPDATE; |
||
174 | if ($oldRating->update()) { |
||
0 ignored issues
–
show
The expression
$oldRating->update() of type false|integer is loosely compared to true ; this is ambiguous if the integer can be zero. You might want to explicitly use !== null instead.
In PHP, under loose comparison (like For 0 == false // true
0 == null // true
123 == false // false
123 == null // false
// It is often better to use strict comparison
0 === false // false
0 === null // false
![]() |
|||
175 | if ($oldRating->status == 1) { |
||
0 ignored issues
–
show
The property
status does not exist on object<ogheo\comments\models\CommentsRating> . Since you implemented __get , maybe consider adding a @property annotation.
Since your code implements the magic getter <?php
/**
* @property int $x
* @property int $y
* @property string $text
*/
class MyLabel
{
private $properties;
private $allowedProperties = array('x', 'y', 'text');
public function __get($name)
{
if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
return $properties[$name];
} else {
return null;
}
}
public function __set($name, $value)
{
if (in_array($name, $this->allowedProperties)) {
$properties[$name] = $value;
} else {
throw new \LogicException("Property $name is not defined.");
}
}
}
If the property has read access only, you can use the @property-read annotation instead. Of course, you may also just have mistyped another name, in which case you should fix the error. See also the PhpDoc documentation for @property. ![]() |
|||
176 | CommentsHelper::deleteDownrated($oldRating->comment_id); |
||
0 ignored issues
–
show
The property
comment_id does not exist on object<ogheo\comments\models\CommentsRating> . Since you implemented __get , maybe consider adding a @property annotation.
Since your code implements the magic getter <?php
/**
* @property int $x
* @property int $y
* @property string $text
*/
class MyLabel
{
private $properties;
private $allowedProperties = array('x', 'y', 'text');
public function __get($name)
{
if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
return $properties[$name];
} else {
return null;
}
}
public function __set($name, $value)
{
if (in_array($name, $this->allowedProperties)) {
$properties[$name] = $value;
} else {
throw new \LogicException("Property $name is not defined.");
}
}
}
If the property has read access only, you can use the @property-read annotation instead. Of course, you may also just have mistyped another name, in which case you should fix the error. See also the PhpDoc documentation for @property. ![]() |
|||
177 | CommentsHelper::setUprated($oldRating->comment_id); |
||
0 ignored issues
–
show
The property
comment_id does not exist on object<ogheo\comments\models\CommentsRating> . Since you implemented __get , maybe consider adding a @property annotation.
Since your code implements the magic getter <?php
/**
* @property int $x
* @property int $y
* @property string $text
*/
class MyLabel
{
private $properties;
private $allowedProperties = array('x', 'y', 'text');
public function __get($name)
{
if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
return $properties[$name];
} else {
return null;
}
}
public function __set($name, $value)
{
if (in_array($name, $this->allowedProperties)) {
$properties[$name] = $value;
} else {
throw new \LogicException("Property $name is not defined.");
}
}
}
If the property has read access only, you can use the @property-read annotation instead. Of course, you may also just have mistyped another name, in which case you should fix the error. See also the PhpDoc documentation for @property. ![]() |
|||
178 | } elseif ($oldRating->status == 2) { |
||
0 ignored issues
–
show
The property
status does not exist on object<ogheo\comments\models\CommentsRating> . Since you implemented __get , maybe consider adding a @property annotation.
Since your code implements the magic getter <?php
/**
* @property int $x
* @property int $y
* @property string $text
*/
class MyLabel
{
private $properties;
private $allowedProperties = array('x', 'y', 'text');
public function __get($name)
{
if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
return $properties[$name];
} else {
return null;
}
}
public function __set($name, $value)
{
if (in_array($name, $this->allowedProperties)) {
$properties[$name] = $value;
} else {
throw new \LogicException("Property $name is not defined.");
}
}
}
If the property has read access only, you can use the @property-read annotation instead. Of course, you may also just have mistyped another name, in which case you should fix the error. See also the PhpDoc documentation for @property. ![]() |
|||
179 | CommentsHelper::deleteUprated($oldRating->comment_id); |
||
0 ignored issues
–
show
The property
comment_id does not exist on object<ogheo\comments\models\CommentsRating> . Since you implemented __get , maybe consider adding a @property annotation.
Since your code implements the magic getter <?php
/**
* @property int $x
* @property int $y
* @property string $text
*/
class MyLabel
{
private $properties;
private $allowedProperties = array('x', 'y', 'text');
public function __get($name)
{
if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
return $properties[$name];
} else {
return null;
}
}
public function __set($name, $value)
{
if (in_array($name, $this->allowedProperties)) {
$properties[$name] = $value;
} else {
throw new \LogicException("Property $name is not defined.");
}
}
}
If the property has read access only, you can use the @property-read annotation instead. Of course, you may also just have mistyped another name, in which case you should fix the error. See also the PhpDoc documentation for @property. ![]() |
|||
180 | CommentsHelper::setDownrated($oldRating->comment_id); |
||
0 ignored issues
–
show
The property
comment_id does not exist on object<ogheo\comments\models\CommentsRating> . Since you implemented __get , maybe consider adding a @property annotation.
Since your code implements the magic getter <?php
/**
* @property int $x
* @property int $y
* @property string $text
*/
class MyLabel
{
private $properties;
private $allowedProperties = array('x', 'y', 'text');
public function __get($name)
{
if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
return $properties[$name];
} else {
return null;
}
}
public function __set($name, $value)
{
if (in_array($name, $this->allowedProperties)) {
$properties[$name] = $value;
} else {
throw new \LogicException("Property $name is not defined.");
}
}
}
If the property has read access only, you can use the @property-read annotation instead. Of course, you may also just have mistyped another name, in which case you should fix the error. See also the PhpDoc documentation for @property. ![]() |
|||
181 | } |
||
182 | |||
183 | TagDependency::invalidate( |
||
184 | Yii::$app->cache, |
||
185 | Url::previous(Yii::$app->controller->module->urlCacheSessionKey) |
||
186 | ); |
||
187 | |||
188 | return [ |
||
189 | 'status' => 'success', |
||
190 | 'action' => $oldRating->status == 1 ? 'updated+' : 'updated-', |
||
0 ignored issues
–
show
The property
status does not exist on object<ogheo\comments\models\CommentsRating> . Since you implemented __get , maybe consider adding a @property annotation.
Since your code implements the magic getter <?php
/**
* @property int $x
* @property int $y
* @property string $text
*/
class MyLabel
{
private $properties;
private $allowedProperties = array('x', 'y', 'text');
public function __get($name)
{
if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
return $properties[$name];
} else {
return null;
}
}
public function __set($name, $value)
{
if (in_array($name, $this->allowedProperties)) {
$properties[$name] = $value;
} else {
throw new \LogicException("Property $name is not defined.");
}
}
}
If the property has read access only, you can use the @property-read annotation instead. Of course, you may also just have mistyped another name, in which case you should fix the error. See also the PhpDoc documentation for @property. ![]() |
|||
191 | 'message' => Yii::t('comments', 'Comment rating has been updated successfully.') |
||
192 | ]; |
||
193 | } |
||
194 | } |
||
195 | View Code Duplication | } else { |
|
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. ![]() |
|||
196 | if ($newRating->save()) { |
||
197 | if ($newRating->status == 1) { |
||
0 ignored issues
–
show
The property
status does not exist on object<ogheo\comments\models\CommentsRating> . Since you implemented __get , maybe consider adding a @property annotation.
Since your code implements the magic getter <?php
/**
* @property int $x
* @property int $y
* @property string $text
*/
class MyLabel
{
private $properties;
private $allowedProperties = array('x', 'y', 'text');
public function __get($name)
{
if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
return $properties[$name];
} else {
return null;
}
}
public function __set($name, $value)
{
if (in_array($name, $this->allowedProperties)) {
$properties[$name] = $value;
} else {
throw new \LogicException("Property $name is not defined.");
}
}
}
If the property has read access only, you can use the @property-read annotation instead. Of course, you may also just have mistyped another name, in which case you should fix the error. See also the PhpDoc documentation for @property. ![]() |
|||
198 | CommentsHelper::setUprated($newRating->comment_id); |
||
0 ignored issues
–
show
The property
comment_id does not exist on object<ogheo\comments\models\CommentsRating> . Since you implemented __get , maybe consider adding a @property annotation.
Since your code implements the magic getter <?php
/**
* @property int $x
* @property int $y
* @property string $text
*/
class MyLabel
{
private $properties;
private $allowedProperties = array('x', 'y', 'text');
public function __get($name)
{
if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
return $properties[$name];
} else {
return null;
}
}
public function __set($name, $value)
{
if (in_array($name, $this->allowedProperties)) {
$properties[$name] = $value;
} else {
throw new \LogicException("Property $name is not defined.");
}
}
}
If the property has read access only, you can use the @property-read annotation instead. Of course, you may also just have mistyped another name, in which case you should fix the error. See also the PhpDoc documentation for @property. ![]() |
|||
199 | } elseif ($newRating->status == 2) { |
||
0 ignored issues
–
show
The property
status does not exist on object<ogheo\comments\models\CommentsRating> . Since you implemented __get , maybe consider adding a @property annotation.
Since your code implements the magic getter <?php
/**
* @property int $x
* @property int $y
* @property string $text
*/
class MyLabel
{
private $properties;
private $allowedProperties = array('x', 'y', 'text');
public function __get($name)
{
if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
return $properties[$name];
} else {
return null;
}
}
public function __set($name, $value)
{
if (in_array($name, $this->allowedProperties)) {
$properties[$name] = $value;
} else {
throw new \LogicException("Property $name is not defined.");
}
}
}
If the property has read access only, you can use the @property-read annotation instead. Of course, you may also just have mistyped another name, in which case you should fix the error. See also the PhpDoc documentation for @property. ![]() |
|||
200 | CommentsHelper::setDownrated($newRating->comment_id); |
||
0 ignored issues
–
show
The property
comment_id does not exist on object<ogheo\comments\models\CommentsRating> . Since you implemented __get , maybe consider adding a @property annotation.
Since your code implements the magic getter <?php
/**
* @property int $x
* @property int $y
* @property string $text
*/
class MyLabel
{
private $properties;
private $allowedProperties = array('x', 'y', 'text');
public function __get($name)
{
if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
return $properties[$name];
} else {
return null;
}
}
public function __set($name, $value)
{
if (in_array($name, $this->allowedProperties)) {
$properties[$name] = $value;
} else {
throw new \LogicException("Property $name is not defined.");
}
}
}
If the property has read access only, you can use the @property-read annotation instead. Of course, you may also just have mistyped another name, in which case you should fix the error. See also the PhpDoc documentation for @property. ![]() |
|||
201 | } |
||
202 | |||
203 | TagDependency::invalidate( |
||
204 | Yii::$app->cache, |
||
205 | Url::previous(Yii::$app->controller->module->urlCacheSessionKey) |
||
206 | ); |
||
207 | |||
208 | return [ |
||
209 | 'status' => 'success', |
||
210 | 'action' => 'rated', |
||
211 | 'message' => Yii::t('comments', 'Comment rating has been updated successfully.') |
||
212 | ]; |
||
213 | } |
||
214 | } |
||
215 | } else { |
||
216 | return [ |
||
217 | 'status' => 'error', |
||
218 | 'errors' => $newRating->errors |
||
219 | ]; |
||
220 | } |
||
221 | } |
||
222 | |||
223 | return [ |
||
224 | 'status' => 'error', |
||
225 | 'message' => Yii::t('comments', 'Sorry, something went wrong. Please try again later.') |
||
226 | ]; |
||
227 | } |
||
228 | } |
||
229 |
Since your code implements the magic getter
_get
, this function will be called for any read access on an undefined variable. You can add the@property
annotation to your class or interface to document the existence of this variable.If the property has read access only, you can use the @property-read annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.