Passed
Push — master ( 02a4a5...734a7e )
by Mihail
05:36
created

Comments   B

Complexity

Total Complexity 38

Size/Duplication

Total Lines 281
Duplicated Lines 38.79 %

Coupling/Cohesion

Components 1
Dependencies 15

Importance

Changes 9
Bugs 6 Features 0
Metric Value
c 9
b 6
f 0
dl 109
loc 281
rs 7.7
wmc 38
lcom 1
cbo 15

7 Methods

Rating   Name   Duplication   Size   Complexity  
A actionRead() 0 13 3
C actionEdit() 0 32 7
B actionIndex() 26 26 1
C actionDelete() 18 45 12
C actionPublish() 18 44 11
B actionAnswerlist() 26 26 1
A actionSettings() 21 21 3

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 Apps\Controller\Admin;
4
5
6
use Apps\ActiveRecord\CommentAnswer;
7
use Apps\ActiveRecord\CommentPost;
8
use Apps\Model\Admin\Comments\FormSettings;
9
use Extend\Core\Arch\AdminController;
10
use Ffcms\Core\App;
11
use Ffcms\Core\Exception\NotFoundException;
12
use Ffcms\Core\Helper\HTML\SimplePagination;
13
use Ffcms\Core\Helper\Type\Arr;
14
use Apps\Model\Admin\Comments\FormCommentUpdate;
15
use Ffcms\Core\Helper\Type\Obj;
16
use Apps\Model\Admin\Comments\FormCommentDelete;
17
use Apps\Model\Admin\Comments\FormCommentModerate;
18
19
/**
20
 * Class Comments. Admin controller for management user comments.
21
 * This class provide general admin implementation of control for user comments and its settings.
22
 * @package Apps\Controller\Admin
23
 */
24
class Comments extends AdminController
25
{
26
    const VERSION = 0.1;
27
    const ITEM_PER_PAGE = 10;
28
29
    const TYPE_COMMENT = 'comment';
30
    const TYPE_ANSWER = 'answer';
31
32
    public $type = 'widget';
33
34
    /**
35
     * List user comments with pagination
36
     * @return string
37
     * @throws \Ffcms\Core\Exception\NativeException
38
     * @throws \Ffcms\Core\Exception\SyntaxException
39
     */
40 View Code Duplication
    public function actionIndex()
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...
41
    {
42
        // set current page and offset
43
        $page = (int)$this->request->query->get('page');
0 ignored issues
show
Documentation introduced by
The property request does not exist on object<Apps\Controller\Admin\Comments>. Since you implemented __get, maybe consider adding a @property annotation.

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.

<?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.

Loading history...
44
        $offset = $page * self::ITEM_PER_PAGE;
45
46
        // initialize active record model
47
        $query = new CommentPost();
48
49
        // make pagination
50
        $pagination = new SimplePagination([
51
            'url' => ['comments/index'],
52
            'page' => $page,
53
            'step' => self::ITEM_PER_PAGE,
54
            'total' => $query->count()
55
        ]);
56
57
        // get result as active records object with offset
58
        $records = $query->orderBy('id', 'desc')->skip($offset)->take(self::ITEM_PER_PAGE)->get();
59
60
        // render output view
61
        return $this->view->render('index', [
0 ignored issues
show
Documentation introduced by
The property view does not exist on object<Apps\Controller\Admin\Comments>. Since you implemented __get, maybe consider adding a @property annotation.

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.

<?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.

Loading history...
62
            'records' => $records,
63
            'pagination' => $pagination
64
        ]);
65
    }
66
67
    /**
68
     * List comment - read comment and list answers
69
     * @param int $id
70
     * @return string
71
     * @throws \Ffcms\Core\Exception\NativeException
72
     * @throws NotFoundException
73
     * @throws \Ffcms\Core\Exception\SyntaxException
74
     */
75
    public function actionRead($id)
76
    {
77
        // find object in active record model
78
        $record = CommentPost::find($id);
79
        if ($record === null || $record === false) {
80
            throw new NotFoundException(__('Comment is not founded'));
81
        }
82
83
        // render response
84
        return $this->view->render('comment_read', [
0 ignored issues
show
Documentation introduced by
The property view does not exist on object<Apps\Controller\Admin\Comments>. Since you implemented __get, maybe consider adding a @property annotation.

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.

<?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.

Loading history...
85
            'record' => $record
86
        ]);
87
    }
88
89
    /**
90
     * Commentaries and answers edit action
91
     * @param string $type
92
     * @param int $id
93
     * @throws NotFoundException
94
     * @return string
95
     * @throws \Ffcms\Core\Exception\SyntaxException
96
     * @throws \Ffcms\Core\Exception\NativeException
97
     */
98
    public function actionEdit($type, $id)
99
    {
100
        // get active record by type and id from active records
101
        $record = null;
102
        switch ($type) {
103
            case static::TYPE_COMMENT:
104
                $record = CommentPost::find($id);
105
                break;
106
            case static::TYPE_ANSWER:
107
                $record = CommentAnswer::find($id);
108
                break;
109
        }
110
111
        // check if response is not empty
112
        if ($record === null || $record === false) {
113
            throw new NotFoundException(__('Comment is not founded'));
114
        }
115
116
        // init edit model
117
        $model = new FormCommentUpdate($record, $type);
0 ignored issues
show
Documentation introduced by
$record is of type object<Ffcms\Core\Arch\ActiveModel>, but the function expects a object<Apps\Model\Admin\...veRecord\CommentAnswer>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
118
119
        // check if data is submited and validated
120
        if ($model->send() && $model->validate()) {
121
            $model->make();
122
            App::$Session->getFlashBag()->add('success', __('Comment or answer is successful updated'));
123
        }
124
125
        // render view
126
        return $this->view->render('edit', [
0 ignored issues
show
Documentation introduced by
The property view does not exist on object<Apps\Controller\Admin\Comments>. Since you implemented __get, maybe consider adding a @property annotation.

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.

<?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.

Loading history...
127
            'model' => $model->filter()
128
        ]);
129
    }
130
131
    /**
132
     * Delete comments and answers single or multiply items
133
     * @param string $type
134
     * @param int $id
135
     * @return string
136
     * @throws NotFoundException
137
     * @throws \Ffcms\Core\Exception\SyntaxException
138
     * @throws \Ffcms\Core\Exception\NativeException
139
     */
140
    public function actionDelete($type, $id = 0)
141
    {
142
        // sounds like a multiply delete definition
143 View Code Duplication
        if ($id === 0 || (int)$id < 1) {
0 ignored issues
show
Duplication introduced by
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.

Loading history...
144
            $ids = $this->request->query->get('selected');
0 ignored issues
show
Documentation introduced by
The property request does not exist on object<Apps\Controller\Admin\Comments>. Since you implemented __get, maybe consider adding a @property annotation.

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.

<?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.

Loading history...
145
            if (Obj::isArray($ids) && Arr::onlyNumericValues($ids)) {
146
                $id = $ids;
147
            } else {
148
                throw new NotFoundException('Bad conditions');
149
            }
150
        } else {
151
            $id = [$id];
152
        }
153
154
        // prepare query to db
155
        $query = null;
156
        switch ($type) {
157
            case self::TYPE_COMMENT:
158
                $query = CommentPost::whereIn('id', $id);
159
                break;
160
            case self::TYPE_ANSWER:
161
                $query = CommentAnswer::whereIn('id', $id);
162
                break;
163
        }
164
165
        // check if result is not empty
166 View Code Duplication
        if ($query === null || $query->count() < 1) {
0 ignored issues
show
Duplication introduced by
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.

Loading history...
167
            throw new NotFoundException(__('No comments found for this condition'));
168
        }
169
170
        // initialize model
171
        $model = new FormCommentDelete($query, $type);
172
173
        // check if delete is submited
174 View Code Duplication
        if ($model->send() && $model->validate()) {
0 ignored issues
show
Duplication introduced by
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.

Loading history...
175
            $model->make();
176
            App::$Session->getFlashBag()->add('success', __('Comments or answers are successful deleted!'));
177
            $this->response->redirect('comments/' . ($type === 'answer' ? 'answerlist' : 'index'));
0 ignored issues
show
Bug introduced by
The method redirect cannot be called on $this->response (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
178
        }
179
180
        // render view
181
        return $this->view->render('delete', [
0 ignored issues
show
Documentation introduced by
The property view does not exist on object<Apps\Controller\Admin\Comments>. Since you implemented __get, maybe consider adding a @property annotation.

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.

<?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.

Loading history...
182
            'model' => $model
183
        ]);
184
    }
185
186
    /**
187
     * Moderate guest comments and answer - make it publish
188
     * @param string $type
189
     * @param int $id
190
     * @return string
191
     * @throws NotFoundException
192
     * @throws \Ffcms\Core\Exception\SyntaxException
193
     * @throws \Ffcms\Core\Exception\NativeException
194
     */
195
    public function actionPublish($type, $id = 0)
196
    {
197
        // check if it multiple accept ids
198 View Code Duplication
        if ($id === 0 || (int)$id < 1) {
0 ignored issues
show
Duplication introduced by
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.

Loading history...
199
            $ids = $this->request->query->get('selected');
0 ignored issues
show
Documentation introduced by
The property request does not exist on object<Apps\Controller\Admin\Comments>. Since you implemented __get, maybe consider adding a @property annotation.

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.

<?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.

Loading history...
200
            if (Obj::isArray($ids) && Arr::onlyNumericValues($ids)) {
201
                $id = $ids;
202
            } else {
203
                throw new NotFoundException('Bad conditions');
204
            }
205
        } else {
206
            $id = [$id];
207
        }
208
209
        // build query
210
        $query = null;
211
        switch ($type) {
212
            case static::TYPE_COMMENT:
213
                $query = CommentPost::whereIn('id', $id)->where('moderate', '=', 1);
214
                break;
215
            case static::TYPE_ANSWER:
216
                $query = CommentAnswer::whereIn('id', $id)->where('moderate', '=', 1);
217
                break;
218
        }
219
220
        // check if result is not empty
221 View Code Duplication
        if ($query === null || $query->count() < 1) {
0 ignored issues
show
Duplication introduced by
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.

Loading history...
222
            throw new NotFoundException(__('No comments found for this condition'));
223
        }
224
225
        // initialize moderation model
226
        $model = new FormCommentModerate($query, $type);
227
228
        // check if form is submited
229 View Code Duplication
        if ($model->send()) {
0 ignored issues
show
Duplication introduced by
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.

Loading history...
230
            $model->make();
231
            App::$Session->getFlashBag()->add('success', __('Comments or answers are successful published'));
232
            $this->response->redirect('comments/' . ($type === 'answer' ? 'answerlist' : 'index'));
0 ignored issues
show
Bug introduced by
The method redirect cannot be called on $this->response (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
233
        }
234
235
        return $this->view->render('publish', [
0 ignored issues
show
Documentation introduced by
The property view does not exist on object<Apps\Controller\Admin\Comments>. Since you implemented __get, maybe consider adding a @property annotation.

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.

<?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.

Loading history...
236
            'model' => $model
237
        ]);
238
    }
239
240
    /**
241
     * List answers
242
     * @return string
243
     * @throws \Ffcms\Core\Exception\SyntaxException
244
     * @throws \Ffcms\Core\Exception\NativeException
245
     */
246 View Code Duplication
    public function actionAnswerlist()
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...
247
    {
248
        // set current page and offset
249
        $page = (int)$this->request->query->get('page');
0 ignored issues
show
Documentation introduced by
The property request does not exist on object<Apps\Controller\Admin\Comments>. Since you implemented __get, maybe consider adding a @property annotation.

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.

<?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.

Loading history...
250
        $offset = $page * self::ITEM_PER_PAGE;
251
252
        // initialize ar answers model
253
        $query = new CommentAnswer();
254
255
        // build pagination list
256
        $pagination = new SimplePagination([
257
            'url' => ['comments/answerlist'],
258
            'page' => $page,
259
            'step' => self::ITEM_PER_PAGE,
260
            'total' => $query->count()
261
        ]);
262
263
        // get result as active records object with offset
264
        $records = $query->orderBy('id', 'desc')->skip($offset)->take(self::ITEM_PER_PAGE)->get();
265
266
        // render output view
267
        return $this->view->render('answer_list', [
0 ignored issues
show
Documentation introduced by
The property view does not exist on object<Apps\Controller\Admin\Comments>. Since you implemented __get, maybe consider adding a @property annotation.

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.

<?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.

Loading history...
268
            'records' => $records,
269
            'pagination' => $pagination
270
        ]);
271
    }
272
273
    /**
274
     * Comment widget global settings
275
     * @return string
276
     * @throws \Ffcms\Core\Exception\NativeException
277
     * @throws \Ffcms\Core\Exception\SyntaxException
278
     */
279 View Code Duplication
    public function actionSettings()
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...
280
    {
281
        // initialize settings model
282
        $model = new FormSettings($this->getConfigs());
283
284
        // check if form is send
285
        if ($model->send()) {
286
            if ($model->validate()) {
287
                $this->setConfigs($model->getAllProperties());
288
                App::$Session->getFlashBag()->add('success', __('Settings is successful updated'));
289
                $this->response->redirect('comments/index');
0 ignored issues
show
Bug introduced by
The method redirect cannot be called on $this->response (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
290
            } else {
291
                App::$Session->getFlashBag()->add('error', __('Form validation is failed'));
292
            }
293
        }
294
295
        // render view
296
        return $this->view->render('settings', [
0 ignored issues
show
Documentation introduced by
The property view does not exist on object<Apps\Controller\Admin\Comments>. Since you implemented __get, maybe consider adding a @property annotation.

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.

<?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.

Loading history...
297
            'model' => $model->filter()
298
        ]);
299
    }
300
301
302
303
304
}