Completed
Push — issue-182 ( 5772c3 )
by Fèvre
09:31
created

PagesController::terms()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 0
1
<?php
2
namespace App\Controller;
3
4
use Cake\Core\Configure;
5
use Cake\Event\Event;
6
use Cake\Network\Exception\NotFoundException;
7
8
class PagesController extends AppController
9
{
10
11
    /**
12
     * Components.
13
     *
14
     * @var array
15
     */
16
    public $components = [
17
        'RequestHandler'
18
    ];
19
20
    /**
21
     * Beforefilter.
22
     *
23
     * @param Event $event The beforeFilter event that was fired.
24
     *
25
     * @return void
26
     */
27
    public function beforeFilter(Event $event)
28
    {
29
        parent::beforeFilter($event);
30
31
        $this->Auth->allow(['home', 'acceptCookie', 'lang', 'terms']);
32
    }
33
34
    /**
35
     * Home page.
36
     *
37
     * @return void
38
     */
39
    public function home()
40
    {
41
        $this->loadModel('BlogArticles');
42
        $this->loadModel('BlogArticlesComments');
43
44
        $articles = $this->BlogArticles
0 ignored issues
show
Documentation introduced by
The property BlogArticles does not exist on object<App\Controller\PagesController>. 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...
45
            ->find()
46
            ->contain([
47
                'BlogCategories',
48
                'Users'
49
            ])
50
            ->order([
51
                'BlogArticles.created' => 'desc'
52
            ])
53
            ->limit(Configure::read('Home.articles'))
54
            ->where([
55
                'BlogArticles.is_display' => 1
56
            ]);
57
58
        $comments = $this->BlogArticlesComments
0 ignored issues
show
Documentation introduced by
The property BlogArticlesComments does not exist on object<App\Controller\PagesController>. 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...
59
            ->find()
60
            ->contain([
61
                'BlogArticles' => function ($q) {
62
                    return $q
63
                        ->select([
64
                            'title'
65
                        ]);
66
                },
67
                'Users' => function ($q) {
68
                    return $q->find('medium');
69
                }
70
            ])
71
            ->order([
72
                    'BlogArticlesComments.created' => 'desc'
73
            ])
74
            ->limit(Configure::read('Home.comments'))
75
            ->where([
76
                'BlogArticles.is_display' => 1
77
            ]);
78
79
        $this->set(compact('articles', 'comments'));
80
    }
81
82
    /**
83
     * The user accept the use of cookies.
84
     *
85
     * @throws \Cake\Network\Exception\NotFoundException When it's not an AJAX request.
86
     *
87
     * @return void
88
     */
89
    public function acceptCookie()
90
    {
91
        if (!$this->request->is('ajax')) {
92
            throw new NotFoundException();
93
        }
94
95
        $this->Cookie->configKey('allowCookies', [
96
            'expires' => '+1 year',
97
            'httpOnly' => true
98
        ]);
99
        $this->Cookie->write('allowCookies', 'true');
100
101
        $json = [];
102
        $json['message'] = __('Thanks for accepting to use the cookies !');
103
        $this->set(compact('json'));
104
105
        $this->set('_serialize', 'json');
106
    }
107
108
    /**
109
     * Redirect to the referer.
110
     *
111
     * @return void
112
     */
113
    public function lang()
114
    {
115
        $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\Network\Request>; 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...
116
    }
117
118
    /**
119
     * Display the Terms page.
120
     *
121
     * @return void
122
     */
123
    public function terms()
124
    {
125
    }
126
}
127