Completed
Pull Request — master (#220)
by Fèvre
74:39 queued 63:40
created

PollsController   A

Complexity

Total Complexity 20

Size/Duplication

Total Lines 224
Duplicated Lines 42.86 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 20
lcom 1
cbo 5
dl 96
loc 224
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
B index() 24 24 1
B add() 31 64 7
C edit() 15 84 9
B delete() 26 26 3

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
namespace App\Controller\Admin;
3
4
use App\Controller\AppController;
5
use Cake\Routing\Router;
6
7
class PollsController extends AppController
8
{
9
    /**
10
     * Display all Polls.
11
     *
12
     * @return \Cake\Network\Response
13
     */
14 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...
15
    {
16
        $this->loadModel('Polls');
17
18
        $this->paginate = [
19
            'maxLimit' => 15
20
        ];
21
22
        $polls = $this->Polls
0 ignored issues
show
Documentation introduced by
The property Polls does not exist on object<App\Controller\Admin\PollsController>. 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...
23
            ->find()
24
            ->contain([
25
                'Users' => function ($q) {
26
                    return $q->find('short');
27
                },
28
                'PollsAnswers',
29
                'BlogArticles'
30
            ])
31
            ->order([
32
                'Polls.created' => 'desc'
33
            ]);
34
35
        $polls = $this->paginate($polls);
36
        $this->set(compact('polls'));
37
    }
38
39
    /**
40
     * Create a Poll.
41
     *
42
     * @return \Cake\Network\Response|void
43
     */
44
    public function add()
45
    {
46
        $this->loadModel('BlogArticles');
47
        $this->loadModel('Polls');
48
        $this->loadModel('PollsAnswers');
49
50
        $poll = $this->Polls->newEntity($this->request->getParsedBody());
0 ignored issues
show
Documentation introduced by
The property Polls does not exist on object<App\Controller\Admin\PollsController>. 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...
51
        $articles = $this->Polls->BlogArticles->find('list');
0 ignored issues
show
Documentation introduced by
The property Polls does not exist on object<App\Controller\Admin\PollsController>. 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...
52
53
        if ($this->request->is('post')) {
54
            $article = $this->BlogArticles
0 ignored issues
show
Documentation introduced by
The property BlogArticles does not exist on object<App\Controller\Admin\PollsController>. 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...
55
                ->find()
56
                ->contain([
57
                    'Polls'
58
                ])
59
                ->where([
60
                    'BlogArticles.id' => $poll->article_id
61
                ])
62
                ->first();
63
64
            //Check if the article has already a poll
65 View Code Duplication
            if (!is_null($article->poll)) {
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...
66
                $this->Flash->error(
67
                    __d(
68
                        'admin',
69
                        'This article has already a poll, you can edit it <a href="{0}" class="btn btn-sm btn-danger-outline">here</a>.',
70
                        Router::url(['_name' => 'polls-edit', 'id' => $article->poll->id, 'slug' => $article->poll->name])
71
                    )
72
                );
73
74
                return $this->redirect(['action' => 'index']);
75
            }
76
77
            $pollAnswers = [];
78
79 View Code Duplication
            foreach ($poll->answers as $answers => $answer) {
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...
80
                $answer = trim($answer);
81
82
                if (!empty($answer)) {
83
                    $entity = $this->Polls->PollsAnswers->newEntity();
0 ignored issues
show
Documentation introduced by
The property Polls does not exist on object<App\Controller\Admin\PollsController>. 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
                    $entity->response = $answer;
85
                    array_push($pollAnswers, $entity);
86
                }
87
            }
88
89 View Code Duplication
            if (empty($pollAnswers)) {
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...
90
                $this->Flash->error(__d('admin', 'You must add at least one answer for this poll.'));
91
                $this->set(compact('poll', 'articles'));
92
93
                return;
94
            }
95
            $poll->user_id = $this->Auth->user('id');
96
            $poll->polls_answers = $pollAnswers;
97
            $poll->unsetProperty('anwsers');
98
99 View Code Duplication
            if ($poll = $this->Polls->save($poll)) {
0 ignored issues
show
Documentation introduced by
The property Polls does not exist on object<App\Controller\Admin\PollsController>. 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...
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...
100
                $this->Flash->success(__d('admin', 'Your poll has been created successfully !'));
101
102
                return $this->redirect(['action' => 'index']);
103
            }
104
        }
105
106
        $this->set(compact('poll', 'articles'));
107
    }
108
109
    /**
110
     * Edit a Poll.
111
     *
112
     * @return \Cake\Network\Response
113
     */
114
    public function edit()
115
    {
116
        $this->loadModel('Polls');
117
        $this->loadModel('BlogArticles');
118
119
        $poll = $this->Polls
0 ignored issues
show
Documentation introduced by
The property Polls does not exist on object<App\Controller\Admin\PollsController>. 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...
120
            ->find()
121
            ->contain([
122
                'PollsAnswers'
123
            ])
124
            ->where([
125
                'id' => $this->request->getAttribute('params')['id']
126
            ])
127
            ->first();
128
129
        //Check if the poll is found.
130
        if (empty($poll)) {
131
            $this->Flash->error(__d('admin', 'This poll doesn\'t exist or has been deleted.'));
132
133
            return $this->redirect(['action' => 'index']);
134
        }
135
136
        if ($this->request->is(['put', 'post'])) {
137
            $this->Polls->patchEntity($poll, $this->request->getParsedBody());
0 ignored issues
show
Documentation introduced by
The property Polls does not exist on object<App\Controller\Admin\PollsController>. 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
            $articles = $this->Polls->BlogArticles->find('list');
0 ignored issues
show
Documentation introduced by
The property Polls does not exist on object<App\Controller\Admin\PollsController>. 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...
139
140
            //Check if the article has already a poll
141
            $article = $this->BlogArticles
0 ignored issues
show
Documentation introduced by
The property BlogArticles does not exist on object<App\Controller\Admin\PollsController>. 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...
142
                ->find()
143
                ->contain([
144
                    'Polls'
145
                ])
146
                ->where([
147
                    'BlogArticles.id' => $poll->article_id
148
                ])
149
                ->first();
150
151
            //Check if the article has already a poll
152
            if (!is_null($article->poll) && $article->poll->id != $this->request->getAttribute('params')['id']) {
153
                $this->Flash->error(
154
                    __d(
155
                        'admin',
156
                        'This article has already a poll, you can edit it <a href="{0}" class="btn btn-sm btn-danger-outline">here</a>.',
157
                        Router::url(['_name' => 'polls-edit', 'id' => $article->poll->id, 'slug' => $article->poll->name])
158
                    )
159
                );
160
161
                return $this->redirect(['action' => 'index']);
162
            }
163
164
            $poll->polls_answers = [];
165
166 View Code Duplication
            foreach ($poll->answers as $answers => $answer) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
167
                $answer = trim($answer);
168
169
                if (!empty($answer)) {
170
                    $entity = $this->Polls->PollsAnswers->newEntity();
0 ignored issues
show
Documentation introduced by
The property Polls does not exist on object<App\Controller\Admin\PollsController>. 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...
171
                    $entity->response = $answer;
172
                    array_push($poll->polls_answers, $entity);
173
                }
174
            }
175
176 View Code Duplication
            if (empty($poll->polls_answers)) {
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...
177
                $this->Flash->error(__d('admin', 'You must add at least one answer for this poll.'));
178
                $this->set(compact('poll', 'articles'));
179
180
                return;
181
            }
182
183
            $poll->user_id = $this->Auth->user('id');
184
            $poll->unsetProperty('anwsers');
185
186
            if ($poll = $this->Polls->save($poll)) {
0 ignored issues
show
Documentation introduced by
The property Polls does not exist on object<App\Controller\Admin\PollsController>. 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...
Unused Code introduced by
$poll is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
187
                $this->Flash->success(__d('admin', 'Your poll has been edited successfully !'));
188
            } else {
189
                $this->Flash->error(__d('admin', 'An error occurred while editing the poll.'));
190
            }
191
192
            return $this->redirect(['action' => 'index']);
193
        }
194
195
        $articles = $this->Polls->BlogArticles->find('list');
0 ignored issues
show
Documentation introduced by
The property Polls does not exist on object<App\Controller\Admin\PollsController>. 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...
196
        $this->set(compact('poll', 'articles'));
197
    }
198
199
    /**
200
     * Delete a Poll.
201
     *
202
     * @return \Cake\Network\Response
203
     */
204 View Code Duplication
    public function delete()
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...
205
    {
206
        $this->loadModel('Polls');
207
208
        $poll = $this->Polls
0 ignored issues
show
Documentation introduced by
The property Polls does not exist on object<App\Controller\Admin\PollsController>. 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...
209
            ->find()
210
            ->where([
211
                'id' => $this->request->getAttribute('params')['id']
212
            ])
213
            ->first();
214
215
        //Check if the poll is found.
216
        if (empty($poll)) {
217
            $this->Flash->error(__d('admin', 'This poll doesn\'t exist or has been deleted.'));
218
219
            return $this->redirect(['action' => 'index']);
220
        }
221
222
        if ($this->Polls->delete($poll)) {
0 ignored issues
show
Documentation introduced by
The property Polls does not exist on object<App\Controller\Admin\PollsController>. 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...
223
            $this->Flash->success(__d('admin', 'This poll has been deleted successfully !'));
224
        } else {
225
            $this->Flash->error(__d('admin', 'Unable to delete this poll.'));
226
        }
227
228
        return $this->redirect(['action' => 'index']);
229
    }
230
}
231