BlogController::beforeFilter()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
namespace App\Controller;
3
4
use App\Event\Badges;
5
use App\Event\Statistics;
6
use Cake\Core\Configure;
7
use Cake\Event\Event;
8
use Cake\Network\Exception\NotFoundException;
9
use Cake\Routing\Router;
10
11
class BlogController extends AppController
12
{
13
14
    /**
15
     * Initialization hook method.
16
     *
17
     * @return void
18
     */
19
    public function initialize()
20
    {
21
        parent::initialize();
22
23
        $this->loadComponent('RequestHandler');
24
    }
25
26
    /**
27
     * BeforeFilter handle.
28
     *
29
     * @param Event $event The beforeFilter event that was fired.
30
     *
31
     * @return void
32
     */
33
    public function beforeFilter(Event $event)
34
    {
35
        parent::beforeFilter($event);
36
37
        $this->Auth->allow(['index', 'category', 'article', 'go', 'archive', 'search']);
38
    }
39
40
    /**
41
     * Display all Articles.
42
     *
43
     * @return void
44
     */
45 View Code Duplication
    public function index()
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...
46
    {
47
        $this->loadModel('BlogArticles');
48
        $this->paginate = [
49
            'maxLimit' => Configure::read('Blog.article_per_page')
50
        ];
51
52
        $articles = $this->BlogArticles
0 ignored issues
show
Documentation introduced by
The property BlogArticles does not exist on object<App\Controller\BlogController>. 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...
53
            ->find()
54
            ->contain([
55
                'BlogCategories',
56
                'Users' => function ($q) {
57
                    return $q->find('short');
58
                },
59
                'Polls',
60
                'BlogAttachments'
61
            ])
62
            ->order([
63
                'BlogArticles.created' => 'desc'
64
            ])
65
            ->where([
66
                'BlogArticles.is_display' => 1
67
            ]);
68
69
        $articles = $this->paginate($articles);
70
71
        $this->set(compact('articles'));
72
    }
73
74
    /**
75
     * Display a specific category with all its articles.
76
     *
77
     * @return \Cake\Network\Response|void
78
     */
79
    public function category()
80
    {
81
        $this->loadModel('BlogCategories');
82
83
        $category = $this->BlogCategories
0 ignored issues
show
Documentation introduced by
The property BlogCategories does not exist on object<App\Controller\BlogController>. 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...
84
            ->find()
85
            ->where([
86
                'BlogCategories.id' => $this->request->id
87
            ])
88
            ->contain([
89
                'BlogArticles'
90
            ])
91
            ->first();
92
93
        //Check if the category is found.
94
        if (empty($category)) {
95
            $this->Flash->error(__('This category doesn\'t exist or has been deleted.'));
96
97
            return $this->redirect(['action' => 'index']);
98
        }
99
100
        //Paginate all Articles.
101
        $this->loadModel('BlogArticles');
102
        $this->paginate = [
103
            'maxLimit' => Configure::read('Blog.article_per_page')
104
        ];
105
106
        $articles = $this->BlogArticles
0 ignored issues
show
Documentation introduced by
The property BlogArticles does not exist on object<App\Controller\BlogController>. 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...
107
            ->find()
108
            ->contain([
109
                'Users' => function ($q) {
110
                    return $q->find('short');
111
                },
112
                'Polls',
113
                'BlogAttachments'
114
            ])
115
            ->where([
116
                'BlogArticles.category_id' => $category->id,
117
                'BlogArticles.is_display' => 1
118
            ])
119
            ->order([
120
                'BlogArticles.created' => 'desc'
121
            ]);
122
123
        $articles = $this->paginate($articles);
124
125
        $this->set(compact('category', 'articles'));
126
    }
127
128
    /**
129
     * Display a specific article.
130
     *
131
     * @return \Cake\Network\Response|void
132
     */
133
    public function article()
134
    {
135
        $this->loadModel('BlogArticles');
136
137
        $article = $this->BlogArticles
0 ignored issues
show
Documentation introduced by
The property BlogArticles does not exist on object<App\Controller\BlogController>. 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...
138
            ->find()
139
            ->where([
140
                'BlogArticles.id' => $this->request->id,
141
                'BlogArticles.is_display' => 1
142
            ])
143
            ->contain([
144
                'BlogCategories',
145
                'BlogAttachments',
146
                'Users' => function ($q) {
147
                    return $q->find('full');
148
                },
149
                'Polls',
150
                'Polls.PollsAnswers',
151
                'Polls.PollsAnswers.Polls' => function ($q) {
152
                    return $q->select(['id', 'user_count']);
153
                },
154
                'Polls.PollsUsers'
155
            ])
156
            ->first();
157
158
        //Check if the article is found.
159
        if (is_null($article)) {
160
            $this->Flash->error(__('This article doesn\'t exist or has been deleted.'));
161
162
            return $this->redirect(['action' => 'index']);
163
        }
164
165
        $this->loadModel('BlogArticlesComments');
166
167
        //A comment has been posted.
168
        if ($this->request->is('post')) {
169
            //Check if the user is connected.
170
            if (!$this->Auth->user()) {
171
                $this->Flash->error(__('You must be connected to post a comment.'));
172
173
                return $this->redirect([
174
                    '_name' => 'blog-article',
175
                    'slug' => h($article->title),
176
                    'id' => $article->id
177
                ]);
178
            }
179
180
            $this->request = $this->request
181
                ->withData('article_id', $article->id)
182
                ->withData('user_id', $this->Auth->user('id'));
183
184
            $newComment = $this->BlogArticlesComments->newEntity($this->request->getParsedBody(), ['validate' => 'create']);
0 ignored issues
show
Documentation introduced by
The property BlogArticlesComments does not exist on object<App\Controller\BlogController>. 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...
185
186
            //Attach Event.
187
            $this->BlogArticlesComments->eventManager()->attach(new Badges($this));
0 ignored issues
show
Documentation introduced by
The property BlogArticlesComments does not exist on object<App\Controller\BlogController>. 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...
188
189
            if ($insertComment = $this->BlogArticlesComments->save($newComment)) {
0 ignored issues
show
Documentation introduced by
The property BlogArticlesComments does not exist on object<App\Controller\BlogController>. 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...
190
                $this->eventManager()->attach(new Statistics());
0 ignored issues
show
Documentation introduced by
new \App\Event\Statistics() is of type object<App\Event\Statistics>, but the function expects a callable.

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...
Deprecated Code introduced by
The method Cake\Event\EventManager::attach() has been deprecated with message: 3.0.0 Use on() 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...
191
                $event = new Event('Model.BlogArticlesComments.new');
192
                $this->eventManager()->dispatch($event);
193
194
                $this->Flash->success(__('Your comment has been posted successfully !'));
195
                //Redirect the user to the last page of the article.
196
                $this->redirect([
197
                    'action' => 'go',
198
                    $insertComment->id
199
                ]);
200
            }
201
        }
202
203
        $this->loadModel('PollsUsers');
204
        $hasVoted = $this->PollsUsers
0 ignored issues
show
Documentation introduced by
The property PollsUsers does not exist on object<App\Controller\BlogController>. 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...
205
            ->find()
206
            ->contain([
207
                'Polls' => function ($q) {
208
                    return $q->select(['id']);
209
                },
210
                'PollsAnswers'
211
            ])
212
            ->where([
213
                'PollsUsers.user_id' => $this->Auth->user('id'),
214
                'Polls.id' => $article->poll ? $article->poll->id : null
215
            ])
216
            ->first();
217
218
        //Paginate all comments related to the article.
219
        $this->paginate = [
220
            'maxLimit' => Configure::read('Blog.comment_per_page')
221
        ];
222
223
        $comments = $this->BlogArticlesComments
0 ignored issues
show
Documentation introduced by
The property BlogArticlesComments does not exist on object<App\Controller\BlogController>. 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...
224
            ->find()
225
            ->where([
226
                'BlogArticlesComments.article_id' => $article->id
227
            ])
228
            ->contain([
229
                'Users' => function ($q) {
230
                    return $q->find('medium');
231
                }
232
            ])
233
            ->order([
234
                'BlogArticlesComments.created' => 'asc'
235
            ]);
236
237
        $comments = $this->paginate($comments);
238
239
        //Select the like for the current auth user.
240
        $this->loadModel('BlogArticlesLikes');
241
        $like = $this->BlogArticlesLikes
0 ignored issues
show
Documentation introduced by
The property BlogArticlesLikes does not exist on object<App\Controller\BlogController>. 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...
242
            ->find()
243
            ->where([
244
                'user_id' => ($this->Auth->user()) ? $this->Auth->user('id') : null,
245
                'article_id' => $article->id
246
            ])
247
            ->first();
248
249
        //Build the newEntity for the comment form.
250
        $formComments = $this->BlogArticlesComments->newEntity();
0 ignored issues
show
Documentation introduced by
The property BlogArticlesComments does not exist on object<App\Controller\BlogController>. 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...
251
252
        //Search related articles
253
        $keywords = preg_split("/([\s,\W])+/", $article->title);
254
255
        $query = $this->BlogArticles->find();
0 ignored issues
show
Documentation introduced by
The property BlogArticles does not exist on object<App\Controller\BlogController>. 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...
256
        $query
257
            ->contain([
258
                'BlogCategories',
259
            ]);
260
261
        foreach ($keywords as $keyword) {
262
            $query->orWhere(function ($exp, $q) use ($keyword) {
0 ignored issues
show
Unused Code introduced by
The parameter $q is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
263
                return $exp->like('BlogArticles.title', '%' . $keyword . '%');
264
            });
265
        }
266
267
        $articles = $query->andWhere([
268
            'BlogArticles.is_display' => 1,
269
            'BlogArticles.id !=' => $article->id
270
        ]);
271
272
        //Current user.
273
        $this->loadModel('Users');
274
        $currentUser = $this->Users
0 ignored issues
show
Documentation introduced by
The property Users does not exist on object<App\Controller\BlogController>. 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...
275
            ->find()
276
            ->contain([
277
                'Groups' => function ($q) {
278
                    return $q->select(['id', 'is_staff']);
279
                }
280
            ])
281
            ->where([
282
                'Users.id' => $this->Auth->user('id')
283
            ])
284
            ->select(['id', 'group_id'])
285
            ->first();
286
287
        $this->set(compact('article', 'formComments', 'comments', 'like', 'articles', 'currentUser', 'hasVoted'));
288
    }
289
290
    /**
291
     * Quote a message.
292
     *
293
     * @param int $articleId Id of the article where is the message to quote.
294
     * @param int $commentId Id of the message to quote.
295
     *
296
     * @throws \Cake\Network\Exception\NotFoundException
297
     *
298
     * @return mixed
299
     */
300
    public function quote($articleId = null, $commentId = null)
301
    {
302
        if (!$this->request->is('ajax')) {
303
            throw new NotFoundException();
304
        }
305
306
        $this->loadModel('BlogArticlesComments');
307
308
        $comment = $this->BlogArticlesComments
0 ignored issues
show
Documentation introduced by
The property BlogArticlesComments does not exist on object<App\Controller\BlogController>. 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...
309
            ->find()
310
            ->where([
311
                'BlogArticlesComments.article_id' => $articleId,
312
                'BlogArticlesComments.id' => $commentId
313
            ])
314
            ->contain([
315
                'Users' => function ($q) {
316
                        return $q->find('short');
317
                }
318
            ])
319
            ->first();
320
321
        $json = [];
322
323
        if (!is_null($comment)) {
324
            $comment->toArray();
325
326
            $url = Router::url(['action' => 'go', $comment->id]);
327
            $text = __("has said :");
328
329
            //Build the quote.
330
            $json['comment'] = <<<EOT
331
<div>
332
     <div>
333
        <a href="{$url}">
334
            <strong>{$comment->user->full_name} {$text}</strong>
335
        </a>
336
    </div>
337
    <blockquote>
338
        $comment->content
339
    </blockquote>
340
</div><p>&nbsp;</p><p>&nbsp;</p>
341
EOT;
342
343
            $json['error'] = false;
344
345
            $this->set(compact('json'));
346
        } else {
347
            $json['comment'] = __("This comment doesn't exist.");
348
            $json['error'] = true;
349
350
            $this->set(compact('json'));
351
        }
352
353
        //Send response in JSON.
354
        $this->set('_serialize', 'json');
355
    }
356
357
    /**
358
     * Redirect an user to an article, page and comment.
359
     *
360
     * @param int $commentId Id of the comment.
361
     *
362
     * @return \Cake\Network\Response
363
     */
364 View Code Duplication
    public function go($commentId = null)
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...
365
    {
366
        $this->loadModel('BlogArticlesComments');
367
368
        $comment = $this->BlogArticlesComments
0 ignored issues
show
Documentation introduced by
The property BlogArticlesComments does not exist on object<App\Controller\BlogController>. 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...
369
            ->find()
370
            ->contain([
371
                'BlogArticles'
372
            ])
373
            ->where([
374
                'BlogArticlesComments.id' => $commentId
375
            ])
376
            ->first();
377
378
        if (is_null($comment)) {
379
            $this->Flash->error(__("This comment doesn't exist or has been deleted."));
380
381
            return $this->redirect(['action' => 'index']);
382
        }
383
384
        $comment->toArray();
385
386
        //Count the number of message before this message.
387
        $messagesBefore = $this->BlogArticlesComments
0 ignored issues
show
Documentation introduced by
The property BlogArticlesComments does not exist on object<App\Controller\BlogController>. 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...
388
            ->find()
389
            ->where([
390
                'BlogArticlesComments.article_id' => $comment->article_id,
391
                'BlogArticlesComments.created <' => $comment->created
392
            ])
393
            ->count();
394
395
        //Get the number of messages per page.
396
        $messagesPerPage = Configure::read('Blog.comment_per_page');
397
398
        //Calculate the page.
399
        $page = floor($messagesBefore / $messagesPerPage) + 1;
400
401
        $page = ($page > 1) ? $page : 1;
402
403
        //Redirect the user.
404
        return $this->redirect([
405
            '_name' => 'blog-article',
406
            'slug' => $comment->blog_article->title,
407
            'id' => $comment->blog_article->id,
408
            '?' => ['page' => $page],
409
            '#' => 'comment-' . $commentId
410
        ]);
411
    }
412
413
    /**
414
     * Get all articles by a date formatted to "m-Y".
415
     *
416
     * @param string $date The date of the archive.
417
     *
418
     * @return void
419
     */
420 View Code Duplication
    public function archive($date = null)
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...
421
    {
422
        $this->loadModel('BlogArticles');
423
424
        $this->paginate = [
425
            'maxLimit' => Configure::read('Blog.article_per_page')
426
        ];
427
428
        $archives = $this->BlogArticles
0 ignored issues
show
Documentation introduced by
The property BlogArticles does not exist on object<App\Controller\BlogController>. 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...
429
            ->find()
430
            ->where([
431
                'DATE_FORMAT(BlogArticles.created,\'%m-%Y\')' => $date,
432
                'BlogArticles.is_display' => 1
433
            ])
434
            ->contain([
435
                'BlogCategories',
436
                'Users' => function ($q) {
437
                        return $q->find('short');
438
                },
439
                'Polls',
440
                'BlogAttachments'
441
            ])
442
            ->order([
443
                'BlogArticles.created' => 'desc'
444
            ]);
445
446
        $articles = $this->paginate($archives);
447
448
        $this->set(compact('articles', 'date'));
449
    }
450
451
    /**
452
     * Search articles.
453
     *
454
     * @return void
455
     */
456
    public function search()
457
    {
458
        $this->loadModel('BlogArticles');
459
460
        //Check the keyword to search. (For pagination)
461 View Code Duplication
        if (!empty($this->request->getData('search'))) {
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...
462
            $keyword = $this->request->getData('search');
463
            $this->request->session()->write('Search.Blog.Keyword', $keyword);
464
        } else {
465
            if ($this->request->session()->read('Search.Blog.Keyword')) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->request->session(...('Search.Blog.Keyword') of type string|null is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
466
                $keyword = $this->request->session()->read('Search.Blog.Keyword');
467
            } else {
468
                $keyword = '';
469
            }
470
        }
471
472
        //Pagination
473
        $this->paginate = [
474
            'maxLimit' => Configure::read('Blog.article_per_page')
475
        ];
476
477
        $articles = $this->BlogArticles
0 ignored issues
show
Documentation introduced by
The property BlogArticles does not exist on object<App\Controller\BlogController>. 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...
478
            ->find()
479
            ->contain([
480
                'Users' => function ($q) {
481
                    return $q->find('short');
482
                },
483
                'Polls',
484
                'BlogAttachments'
485
            ])
486
            ->where([
487
                'BlogArticles.is_display' => 1
488
            ])
489
            ->andWhere(function ($q) use ($keyword) {
490
                return $q
491
                    ->like('title', "%$keyword%");
492
            })
493
            ->order([
494
                'BlogArticles.created' => 'desc'
495
            ]);
496
497
        $articles = $this->paginate($articles);
498
499
        $this->set(compact('articles', 'keyword'));
500
    }
501
502
    /**
503
     * Like an article.
504
     *
505
     * @param int $articleId Id of the article to like.
506
     *
507
     * @throws \Cake\Network\Exception\NotFoundException When it's not an AJAX request.
508
     *
509
     * @return void
510
     */
511
    public function articleLike($articleId = null)
512
    {
513
        if (!$this->request->is('ajax')) {
514
            throw new NotFoundException();
515
        }
516
517
        //Check if the user hasn't already liked this article.
518
        $this->loadModel('BlogArticlesLikes');
519
        $checkLike = $this->BlogArticlesLikes
0 ignored issues
show
Documentation introduced by
The property BlogArticlesLikes does not exist on object<App\Controller\BlogController>. 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...
520
            ->find()
521
            ->where([
522
                'BlogArticlesLikes.user_id' => $this->Auth->user('id'),
523
                'BlogArticlesLikes.article_id' => $articleId
524
            ])
525
            ->first();
526
527
        $json = [];
528
529 View Code Duplication
        if (!is_null($checkLike)) {
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...
530
            $json['message'] = __('You already like this article !');
531
            $json['error'] = true;
532
533
            $this->set(compact('json'));
534
535
            $this->set('_serialize', 'json');
536
537
            return;
538
        }
539
540
        //Check if the article exist.
541
        $this->loadModel('BlogArticles');
542
        $checkArticle = $this->BlogArticles
0 ignored issues
show
Documentation introduced by
The property BlogArticles does not exist on object<App\Controller\BlogController>. 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...
543
            ->find()
544
            ->where([
545
                'BlogArticles.id' => $articleId,
546
                'BlogArticles.is_display' => 1
547
            ])
548
            ->first();
549
550 View Code Duplication
        if (is_null($checkArticle)) {
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...
551
            $json['message'] = __("This article doesn't exist !");
552
            $json['error'] = true;
553
554
            $this->set(compact('json'));
555
            $this->set('_serialize', 'json');
556
557
            return;
558
        }
559
560
        //Prepare data to be saved.
561
        $data = [];
562
        $data['BlogArticlesLikes']['user_id'] = $this->Auth->user('id');
563
        $data['BlogArticlesLikes']['article_id'] = $articleId;
564
565
        $like = $this->BlogArticlesLikes->newEntity($data);
0 ignored issues
show
Documentation introduced by
The property BlogArticlesLikes does not exist on object<App\Controller\BlogController>. 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...
566
567
        if ($this->BlogArticlesLikes->save($like)) {
0 ignored issues
show
Documentation introduced by
The property BlogArticlesLikes does not exist on object<App\Controller\BlogController>. 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...
568
            //Update the Statistics
569
            $this->eventManager()->attach(new Statistics());
0 ignored issues
show
Documentation introduced by
new \App\Event\Statistics() is of type object<App\Event\Statistics>, but the function expects a callable.

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...
Deprecated Code introduced by
The method Cake\Event\EventManager::attach() has been deprecated with message: 3.0.0 Use on() 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...
570
            $event = new Event('Model.BlogArticlesLikes.new');
571
            $this->eventManager()->dispatch($event);
572
573
            $json['message'] = __('Thanks for {0} this article ! ', "<i class='fa fa-heart text-danger'></i>");
574
            $json['title'] = __('You {0} this article.', "<i class='fa fa-heart text-danger'></i>");
575
            $json['url'] = Router::url(
576
                [
577
                    'action' => 'articleUnlike',
578
                    $articleId
579
                ]
580
            );
581
            $json['error'] = false;
582
        } else {
583
            $json['message'] = __('An error occurred, please try again later.');
584
            $json['error'] = true;
585
        }
586
587
        $this->set(compact('json'));
588
589
        $this->set('_serialize', 'json');
590
    }
591
592
    /**
593
     * Unlike an article.
594
     *
595
     * @param int|null $articleId Id of the article to like.
596
     *
597
     * @throws \Cake\Network\Exception\NotFoundException When it's not an AJAX request.
598
     *
599
     * @return void
600
     */
601
    public function articleUnlike($articleId = null)
602
    {
603
        if (!$this->request->is('ajax')) {
604
            throw new NotFoundException();
605
        }
606
607
        //Check if the user like this article.
608
        $this->loadModel('BlogArticlesLikes');
609
        $like = $this->BlogArticlesLikes
0 ignored issues
show
Documentation introduced by
The property BlogArticlesLikes does not exist on object<App\Controller\BlogController>. 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...
610
            ->find()
611
            ->contain([
612
                'BlogArticles'
613
            ])
614
            ->where([
615
                'BlogArticlesLikes.user_id' => $this->Auth->user('id'),
616
                'BlogArticlesLikes.article_id' => $articleId,
617
                'BlogArticles.is_display' => 1
618
            ])
619
            ->first();
620
621
        $json = [];
622
623 View Code Duplication
        if (is_null($like)) {
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...
624
            $json['message'] = __("You don't like this article !");
625
            $json['error'] = true;
626
627
            $this->set(compact('json'));
628
629
            $this->set('_serialize', 'json');
630
631
            return;
632
        }
633
634
        if ($this->BlogArticlesLikes->delete($like)) {
0 ignored issues
show
Documentation introduced by
The property BlogArticlesLikes does not exist on object<App\Controller\BlogController>. 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...
635
            //Update the Statistics
636
            $this->eventManager()->attach(new Statistics());
0 ignored issues
show
Documentation introduced by
new \App\Event\Statistics() is of type object<App\Event\Statistics>, but the function expects a callable.

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...
Deprecated Code introduced by
The method Cake\Event\EventManager::attach() has been deprecated with message: 3.0.0 Use on() 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...
637
            $event = new Event('Model.BlogArticlesLikes.new');
638
            $this->eventManager()->dispatch($event);
639
640
            $json['url'] = Router::url([
641
                                'action' => 'articleLike',
642
                                $articleId
643
                            ]);
644
            $json['title'] = __('Like {0}', "<i class='fa fa-heart text-danger'></i>");
645
            $json['error'] = false;
646
        } else {
647
            $json['message'] = __('An error occurred, please try again later.');
648
            $json['error'] = true;
649
        }
650
651
        $this->set(compact('json'));
652
653
        $this->set('_serialize', 'json');
654
    }
655
656
    /**
657
     * Delete a comment.
658
     *
659
     * @param int $id Id of the comment to delete.
660
     *
661
     * @return \Cake\Network\Response
662
     */
663
    public function deleteComment($id = null)
664
    {
665
        $this->loadModel('BlogArticlesComments');
666
667
        $comment = $this->BlogArticlesComments
0 ignored issues
show
Documentation introduced by
The property BlogArticlesComments does not exist on object<App\Controller\BlogController>. 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...
668
            ->find()
669
            ->contain([
670
                'BlogArticles'
671
            ])
672
            ->where([
673
                'BlogArticlesComments.id' => $id
674
            ])
675
            ->first();
676
677
        if (is_null($comment)) {
678
            $this->Flash->error(__("This comment doesn't exist or has been deleted !"));
679
680
            return $this->redirect($this->referer());
0 ignored issues
show
Bug introduced by
It seems like $this->referer() targeting Cake\Controller\Controller::referer() can also be of type object<Cake\Http\ServerRequest>; however, Cake\Controller\Controller::redirect() does only seem to accept string|array, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
681
        }
682
683
        //Current user.
684
        $this->loadModel('Users');
685
        $currentUser = $this->Users
0 ignored issues
show
Documentation introduced by
The property Users does not exist on object<App\Controller\BlogController>. 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...
686
            ->find()
687
            ->contain([
688
                'Groups' => function ($q) {
689
                    return $q->select(['id', 'is_staff']);
690
                }
691
            ])
692
            ->where([
693
                'Users.id' => $this->Auth->user('id')
694
            ])
695
            ->select(['id', 'group_id'])
696
            ->first();
697
698
        if ($comment->user_id != $this->Auth->user('id') && !$currentUser->group->is_staff) {
699
            $this->Flash->error(__("You don't have the authorization to delete this comment !"));
700
701
            return $this->redirect($this->referer());
0 ignored issues
show
Bug introduced by
It seems like $this->referer() targeting Cake\Controller\Controller::referer() can also be of type object<Cake\Http\ServerRequest>; however, Cake\Controller\Controller::redirect() does only seem to accept string|array, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
702
        }
703
704
        if ($this->BlogArticlesComments->delete($comment)) {
0 ignored issues
show
Documentation introduced by
The property BlogArticlesComments does not exist on object<App\Controller\BlogController>. 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...
705
            $this->eventManager()->attach(new Statistics());
0 ignored issues
show
Documentation introduced by
new \App\Event\Statistics() is of type object<App\Event\Statistics>, but the function expects a callable.

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...
Deprecated Code introduced by
The method Cake\Event\EventManager::attach() has been deprecated with message: 3.0.0 Use on() 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...
706
            $event = new Event('Model.BlogArticlesComments.new');
707
            $this->eventManager()->dispatch($event);
708
709
            $this->Flash->success(__("This comment has been deleted successfully !"));
710
        }
711
712
        return $this->redirect(['_name' => 'blog-article', 'slug' => $comment->blog_article->title, 'id' => $comment->blog_article->id, '?' => ['page' => $comment->blog_article->last_page]]);
713
    }
714
715
    /**
716
     * Get the form to edit a comment.
717
     *
718
     * @throws \Cake\Network\Exception\NotFoundException When it's not an AJAX request.
719
     *
720
     * @return void
721
     */
722
    public function getEditComment()
723
    {
724
        if (!$this->request->is('ajax')) {
725
            throw new NotFoundException();
726
        }
727
728
        $this->loadModel('BlogArticlesComments');
729
        $comment = $this->BlogArticlesComments
0 ignored issues
show
Documentation introduced by
The property BlogArticlesComments does not exist on object<App\Controller\BlogController>. 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...
730
            ->find()
731
            ->where([
732
                'BlogArticlesComments.id' => $this->request->getData('id')
733
            ])
734
            ->first();
735
736
        $json = [
737
            'error' => false,
738
            'errorMessage' => ''
739
        ];
740
741 View Code Duplication
        if (is_null($comment)) {
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...
742
            $json['error'] = true;
743
            $json['errorMessage'] = __("This comment doesn't exist or has been deleted !");
744
745
            $this->set(compact('json'));
746
747
            return;
748
        }
749
750
        //Current user.
751
        $this->loadModel('Users');
752
        $currentUser = $this->Users
0 ignored issues
show
Documentation introduced by
The property Users does not exist on object<App\Controller\BlogController>. 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...
753
            ->find()
754
            ->contain([
755
                'Groups' => function ($q) {
756
                    return $q->select(['id', 'is_staff']);
757
                }
758
            ])
759
            ->where([
760
                'Users.id' => $this->Auth->user('id')
761
            ])
762
            ->select(['id', 'group_id'])
763
            ->first();
764
765
        if ($comment->user_id != $this->Auth->user('id') && !$currentUser->group->is_staff) {
766
            $json['error'] = true;
767
            $json['errorMessage'] = __("You don't have the authorization to edit this comment !");
768
769
            $this->set(compact('json'));
770
771
            return;
772
        }
773
774
        $this->set(compact('json', 'comment'));
775
    }
776
777
    /**
778
     * Edit a comment.
779
     *
780
     * @param int $id Id of the comment.
781
     *
782
     * @throws \Cake\Network\Exception\NotFoundException When it's not a POST request.
783
     *
784
     * @return \Cake\Network\Response
785
     */
786
    public function editComment($id = null)
787
    {
788
        if (!$this->request->is('post')) {
789
            throw new NotFoundException();
790
        }
791
792
        $this->loadModel('BlogArticlesComments');
793
794
        $comment = $this->BlogArticlesComments
0 ignored issues
show
Documentation introduced by
The property BlogArticlesComments does not exist on object<App\Controller\BlogController>. 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...
795
            ->find()
796
            ->contain([
797
                'BlogArticles'
798
            ])
799
            ->where([
800
                'BlogArticlesComments.id' => $id
801
            ])
802
            ->first();
803
804
        if (is_null($comment)) {
805
            $this->Flash->error(__("This comment doesn't exist or has been deleted !"));
806
807
            return $this->redirect($this->referer());
0 ignored issues
show
Bug introduced by
It seems like $this->referer() targeting Cake\Controller\Controller::referer() can also be of type object<Cake\Http\ServerRequest>; however, Cake\Controller\Controller::redirect() does only seem to accept string|array, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
808
        }
809
810
        //Current user.
811
        $this->loadModel('Users');
812
        $currentUser = $this->Users
0 ignored issues
show
Documentation introduced by
The property Users does not exist on object<App\Controller\BlogController>. 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...
813
            ->find()
814
            ->contain([
815
                'Groups' => function ($q) {
816
                    return $q->select(['id', 'is_staff']);
817
                }
818
            ])
819
            ->where([
820
                'Users.id' => $this->Auth->user('id')
821
            ])
822
            ->select(['id', 'group_id'])
823
            ->first();
824
825
        if ($comment->user_id != $this->Auth->user('id') && !$currentUser->group->is_staff) {
826
            $this->Flash->error(__("You don't have the authorization to edit this comment !"));
827
828
            return $this->redirect($this->referer());
0 ignored issues
show
Bug introduced by
It seems like $this->referer() targeting Cake\Controller\Controller::referer() can also be of type object<Cake\Http\ServerRequest>; however, Cake\Controller\Controller::redirect() does only seem to accept string|array, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
829
        }
830
831
        $this->BlogArticlesComments->patchEntity($comment, $this->request->getParsedBody());
0 ignored issues
show
Documentation introduced by
The property BlogArticlesComments does not exist on object<App\Controller\BlogController>. 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...
832
        if ($this->BlogArticlesComments->save($comment)) {
0 ignored issues
show
Documentation introduced by
The property BlogArticlesComments does not exist on object<App\Controller\BlogController>. 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...
833
            $this->Flash->success(__("This comment has been edited successfully !"));
834
        }
835
836
        return $this->redirect(['action' => 'go', $comment->id]);
837
    }
838
}
839