Completed
Push — master ( 4714f7...5c9972 )
by Fèvre
11s
created

PagesController::maintenance()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 6
rs 9.4285
cc 2
eloc 3
nc 2
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
     * Initialization hook method.
13
     *
14
     * @return void
15
     */
16
    public function initialize()
17
    {
18
        parent::initialize();
19
20
        $this->loadComponent('RequestHandler');
21
    }
22
23
    /**
24
     * Beforefilter.
25
     *
26
     * @param Event $event The beforeFilter event that was fired.
27
     *
28
     * @return void
29
     */
30
    public function beforeFilter(Event $event)
31
    {
32
        parent::beforeFilter($event);
33
34
        $this->Auth->allow(['home', 'maintenance', 'acceptCookie', 'lang', 'terms']);
35
    }
36
37
    /**
38
     * Home page.
39
     *
40
     * @return void
41
     */
42
    public function home()
43
    {
44
        $this->loadModel('BlogArticles');
45
        $this->loadModel('BlogArticlesComments');
46
47
        $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...
48
            ->find()
49
            ->contain([
50
                'BlogCategories',
51
                'Users'
52
            ])
53
            ->order([
54
                'BlogArticles.created' => 'desc'
55
            ])
56
            ->limit(Configure::read('Home.articles'))
57
            ->where([
58
                'BlogArticles.is_display' => 1
59
            ]);
60
61
        $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...
62
            ->find()
63
            ->contain([
64
                'BlogArticles' => function ($q) {
65
                    return $q
66
                        ->select([
67
                            'title'
68
                        ]);
69
                },
70
                'Users' => function ($q) {
71
                    return $q->find('medium');
72
                }
73
            ])
74
            ->order([
75
                    'BlogArticlesComments.created' => 'desc'
76
            ])
77
            ->limit(Configure::read('Home.comments'))
78
            ->where([
79
                'BlogArticles.is_display' => 1
80
            ]);
81
82
        $this->set(compact('articles', 'comments'));
83
    }
84
85
    /**
86
     * The user accept the use of cookies.
87
     *
88
     * @throws \Cake\Network\Exception\NotFoundException When it's not an AJAX request.
89
     *
90
     * @return void
91
     */
92
    public function acceptCookie()
93
    {
94
        if (!$this->request->is('ajax')) {
95
            throw new NotFoundException();
96
        }
97
98
        $this->Cookie->configKey('allowCookies', [
99
            'expires' => '+1 year',
100
            'httpOnly' => true
101
        ]);
102
        $this->Cookie->write('allowCookies', 'true');
103
104
        $json = [];
105
        $json['message'] = __('Thanks for accepting to use the cookies !');
106
        $this->set(compact('json'));
107
108
        $this->set('_serialize', 'json');
109
    }
110
111
    /**
112
     * Redirect to the referer.
113
     *
114
     * @return void
115
     */
116
    public function lang()
117
    {
118
        $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...
119
    }
120
121
    /**
122
     * Display the maintenance page or a 404 if the site isn't in maintenance.
123
     *
124
     * @return void
125
     */
126
    public function maintenance()
127
    {
128
        if (Configure::read('Site.maintenance') === false) {
129
            throw new NotFoundException();
130
        }
131
    }
132
133
    /**
134
     * Display the Terms page.
135
     *
136
     * @return void
137
     */
138
    public function terms()
139
    {
140
    }
141
}
142