Passed
Branch master (44bfae)
by giu
03:41
created

UseroptionsController   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 102
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 38
c 1
b 0
f 0
dl 0
loc 102
ccs 0
cts 59
cp 0
rs 10
wmc 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A edit() 0 17 3
A index() 0 9 1
A view() 0 8 1
A delete() 0 11 2
A add() 0 15 3
1
<?php
2
namespace App\Controller;
3
4
use App\Controller\AppController;
5
6
/**
7
 * Useroptions Controller
8
 *
9
 * @property \App\Model\Table\UseroptionsTable $Useroptions
10
 */
11
class UseroptionsController extends AppController
12
{
13
14
    /**
15
     * Index method
16
     *
17
     * @return \Cake\Network\Response|null
18
     */
19
    public function index()
20
    {
21
        $this->paginate = [
22
            'contain' => ['Users']
23
        ];
24
        $useroptions = $this->paginate($this->Useroptions);
25
26
        $this->set(compact('useroptions'));
27
        $this->set('_serialize', ['useroptions']);
28
    }
29
30
    /**
31
     * View method
32
     *
33
     * @param string|null $id Useroption id.
34
     * @return \Cake\Network\Response|null
35
     * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
36
     */
37
    public function view($id = null)
38
    {
39
        $useroption = $this->Useroptions->get($id, [
40
            'contain' => ['Users']
41
        ]);
42
43
        $this->set('useroption', $useroption);
44
        $this->set('_serialize', ['useroption']);
45
    }
46
47
    /**
48
     * Add method
49
     *
50
     * @return \Cake\Network\Response|null Redirects on successful add, renders view otherwise.
51
     */
52
    public function add()
53
    {
54
        $useroption = $this->Useroptions->newEntity();
55
        if ($this->request->is('post')) {
56
            $useroption = $this->Useroptions->patchEntity($useroption, $this->request->data);
0 ignored issues
show
Bug introduced by
It seems like $this->request->data can also be of type object; however, parameter $data of App\Model\Table\UseroptionsTable::patchEntity() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

56
            $useroption = $this->Useroptions->patchEntity($useroption, /** @scrutinizer ignore-type */ $this->request->data);
Loading history...
Deprecated Code introduced by
The property Cake\Http\ServerRequest::$data has been deprecated: 3.4.0 This public property will be removed in 4.0.0. Use getData() instead. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

56
            $useroption = $this->Useroptions->patchEntity($useroption, /** @scrutinizer ignore-deprecated */ $this->request->data);

This property 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 property will be removed from the class and what other property to use instead.

Loading history...
57
            if ($this->Useroptions->save($useroption)) {
58
                $this->Flash->success(__('The useroption has been saved.'));
59
60
                return $this->redirect(['action' => 'index']);
61
            }
62
            $this->Flash->error(__('The useroption could not be saved. Please, try again.'));
63
        }
64
        $users = $this->Useroptions->Users->find('list', ['limit' => 200]);
65
        $this->set(compact('useroption', 'users'));
66
        $this->set('_serialize', ['useroption']);
67
    }
68
69
    /**
70
     * Edit method
71
     *
72
     * @param string|null $id Useroption id.
73
     * @return \Cake\Network\Response|null Redirects on successful edit, renders view otherwise.
74
     * @throws \Cake\Network\Exception\NotFoundException When record not found.
75
     */
76
    public function edit($id = null)
77
    {
78
        $useroption = $this->Useroptions->get($id, [
79
            'contain' => []
80
        ]);
81
        if ($this->request->is(['patch', 'post', 'put'])) {
82
            $useroption = $this->Useroptions->patchEntity($useroption, $this->request->data);
0 ignored issues
show
Bug introduced by
It seems like $this->request->data can also be of type object; however, parameter $data of App\Model\Table\UseroptionsTable::patchEntity() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

82
            $useroption = $this->Useroptions->patchEntity($useroption, /** @scrutinizer ignore-type */ $this->request->data);
Loading history...
Deprecated Code introduced by
The property Cake\Http\ServerRequest::$data has been deprecated: 3.4.0 This public property will be removed in 4.0.0. Use getData() instead. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

82
            $useroption = $this->Useroptions->patchEntity($useroption, /** @scrutinizer ignore-deprecated */ $this->request->data);

This property 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 property will be removed from the class and what other property to use instead.

Loading history...
83
            if ($this->Useroptions->save($useroption)) {
84
                $this->Flash->success(__('The useroption has been saved.'));
85
86
                return $this->redirect(['action' => 'index']);
87
            }
88
            $this->Flash->error(__('The useroption could not be saved. Please, try again.'));
89
        }
90
        $users = $this->Useroptions->Users->find('list', ['limit' => 200]);
91
        $this->set(compact('useroption', 'users'));
92
        $this->set('_serialize', ['useroption']);
93
    }
94
95
    /**
96
     * Delete method
97
     *
98
     * @param string|null $id Useroption id.
99
     * @return \Cake\Network\Response|null Redirects to index.
100
     * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
101
     */
102
    public function delete($id = null)
103
    {
104
        $this->request->allowMethod(['post', 'delete']);
105
        $useroption = $this->Useroptions->get($id);
106
        if ($this->Useroptions->delete($useroption)) {
107
            $this->Flash->success(__('The useroption has been deleted.'));
108
        } else {
109
            $this->Flash->error(__('The useroption could not be deleted. Please, try again.'));
110
        }
111
112
        return $this->redirect(['action' => 'index']);
113
    }
114
}
115