Code Duplication    Length = 26-26 lines in 2 locations

src/Controller/Admin/PollsAnswersController.php 1 location

@@ 13-38 (lines=26) @@
10
     *
11
     * @return \Cake\Network\Response
12
     */
13
    public function delete()
14
    {
15
        $this->loadModel('PollsAnswers');
16
17
        $answer = $this->PollsAnswers
18
            ->find()
19
            ->where([
20
                'id' => $this->request->getAttribute('params')['id']
21
            ])
22
            ->first();
23
24
        //Check if the answer is found.
25
        if (empty($answer)) {
26
            $this->Flash->error(__d('admin', 'This answer doesn\'t exist or has been deleted.'));
27
28
            return $this->redirect(['action' => 'index']);
29
        }
30
31
        if ($this->PollsAnswers->delete($answer)) {
32
            $this->Flash->success(__d('admin', 'This answer has been deleted successfully.'));
33
        } else {
34
             $this->Flash->error(__d('admin', 'An error occured while deleting this answers.'));
35
        }
36
37
        return $this->redirect($this->referer());
38
    }
39
}
40

src/Controller/Admin/PollsController.php 1 location

@@ 202-227 (lines=26) @@
199
     *
200
     * @return \Cake\Network\Response
201
     */
202
    public function delete()
203
    {
204
        $this->loadModel('Polls');
205
206
        $poll = $this->Polls
207
            ->find()
208
            ->where([
209
                'id' => $this->request->getAttribute('params')['id']
210
            ])
211
            ->first();
212
213
        //Check if the poll is found.
214
        if (empty($poll)) {
215
            $this->Flash->error(__d('admin', 'This poll doesn\'t exist or has been deleted.'));
216
217
            return $this->redirect(['action' => 'index']);
218
        }
219
220
        if ($this->Polls->delete($poll)) {
221
            $this->Flash->success(__d('admin', 'This poll has been deleted successfully !'));
222
        } else {
223
            $this->Flash->error(__d('admin', 'Unable to delete this poll.'));
224
        }
225
226
        return $this->redirect(['action' => 'index']);
227
    }
228
}
229