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

TicketsController::index()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 7
ccs 4
cts 4
cp 1
crap 1
rs 10
1
<?php
2
namespace App\Controller;
3
4
use App\Controller\AppController;
5
use Cake\I18n\Time;
6
use Cake\I18n\I18n;
7
8
/**
9
 * Tickets Controller
10
 *
11
 * @property \App\Model\Table\TicketsTable $Tickets
12
 */
13
class TicketsController extends AppController
14
{
15
16
    /**
17
     * Index method
18
     *
19
     * @return \Cake\Network\Response|null
20
     */
21 1
    public function index()
22
    {
23
        
24 1
		$tickets = $this->paginate($this->Tickets->find('all', ['contain'=>['Tickettypes', 'Ticketstatuses']]));
25
26 1
        $this->set(compact('tickets'));
27 1
        $this->set('_serialize', ['tickets']);
28 1
    }
29
30
    /**
31
     * View method
32
     *
33
     * @param string|null $id Ticket id.
34
     * @return \Cake\Network\Response|null
35
     * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
36
     */
37 1
    public function view($id = null)
38
    {
39 1
        $ticket = $this->Tickets->get($id, [
40 1
            'contain' => ['Operations', 'Tickettypes']
41
        ]);
42
43 1
        $this->set('ticket', $ticket);
44 1
        $this->set('_serialize', ['ticket']);
45 1
    }
46
47
    /**
48
     * Add method
49
     *
50
     * @return \Cake\Network\Response|null Redirects on successful add, renders view otherwise.
51
     */
52 1
    public function add()
53
    {
54 1
        $ticket = $this->Tickets->newEntity();
55 1
        if ($this->request->is('post')) {
56 1
            $ticket = $this->Tickets->patchEntity($ticket, $this->request->data);
0 ignored issues
show
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
            $ticket = $this->Tickets->patchEntity($ticket, /** @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...
Bug introduced by
It seems like $this->request->data can also be of type object; however, parameter $data of App\Model\Table\TicketsTable::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
            $ticket = $this->Tickets->patchEntity($ticket, /** @scrutinizer ignore-type */ $this->request->data);
Loading history...
57 1
            if ($this->Tickets->save($ticket)) {
58 1
                $this->Flash->success(__('The ticket has been saved.'));
59
60 1
                return $this->redirect(['prefix'=>false, 'controller'=>'Tickets', 'action' => 'index']);
61
            }
62
            $this->Flash->error(__('The ticket could not be saved. Please, try again.'));
63
        }
64 1
		$types = $this->Tickets->Tickettypes->find('list');
0 ignored issues
show
Bug Best Practice introduced by
The property Tickettypes does not exist on App\Model\Table\TicketsTable. Since you implemented __get, consider adding a @property annotation.
Loading history...
65 1
		$statuses = $this->Tickets->Ticketstatuses->find('list');
0 ignored issues
show
Bug Best Practice introduced by
The property Ticketstatuses does not exist on App\Model\Table\TicketsTable. Since you implemented __get, consider adding a @property annotation.
Loading history...
66 1
        $this->set(compact('ticket', 'types', 'statuses'));
67 1
        $this->set('_serialize', ['ticket']);
68 1
    }
69
70
    /**
71
     * Edit method
72
     *
73
     * @param string|null $id Ticket id.
74
     * @return \Cake\Network\Response|null Redirects on successful edit, renders view otherwise.
75
     * @throws \Cake\Network\Exception\NotFoundException When record not found.
76
     */
77 1
    public function edit($id = null)
78
    {
79 1
        $ticket = $this->Tickets->get($id, [
80 1
            'contain' => ['Tickettypes']
81
        ]);
82 1
        if ($this->request->is(['patch', 'post', 'put'])) {
83 1
            $ticket = $this->Tickets->patchEntity($ticket, $this->request->data);
0 ignored issues
show
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

83
            $ticket = $this->Tickets->patchEntity($ticket, /** @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...
Bug introduced by
It seems like $this->request->data can also be of type object; however, parameter $data of App\Model\Table\TicketsTable::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

83
            $ticket = $this->Tickets->patchEntity($ticket, /** @scrutinizer ignore-type */ $this->request->data);
Loading history...
84 1
            if ($this->Tickets->save($ticket)) {
85 1
                $this->Flash->success(__('The ticket has been saved.'));
86
87 1
                return $this->redirect(['prefix'=>false, 'controller'=>'Tickets', 'action' => 'index']);
88
            }
89
            $this->Flash->error(__('The ticket could not be saved. Please, try again.'));
90
        }
91 1
		$tickettypes = $this->Tickets->Tickettypes->find('list');
0 ignored issues
show
Bug Best Practice introduced by
The property Tickettypes does not exist on App\Model\Table\TicketsTable. Since you implemented __get, consider adding a @property annotation.
Loading history...
92 1
		$ticketstatuses = $this->Tickets->Ticketstatuses->find('list');
0 ignored issues
show
Bug Best Practice introduced by
The property Ticketstatuses does not exist on App\Model\Table\TicketsTable. Since you implemented __get, consider adding a @property annotation.
Loading history...
93 1
        $this->set(compact('ticket', 'tickettypes', 'ticketstatuses'));
94 1
        $this->set('_serialize', ['ticket']);
95 1
    }
96
97
    /**
98
     * Delete method
99
     *
100
     * @param string|null $id Ticket id.
101
     * @return \Cake\Network\Response|null Redirects to index.
102
     * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
103
     */
104 1
    public function delete($id = null)
105
    {
106 1
        $this->request->allowMethod(['post', 'delete']);
107 1
        $ticket = $this->Tickets->get($id);
108 1
        if ($this->Tickets->delete($ticket)) {
109 1
            $this->Flash->success(__('The ticket has been deleted.'));
110
        } else {
111
            $this->Flash->error(__('The ticket could not be deleted. Please, try again.'));
112
        }
113
114 1
        return $this->redirect(['prefix'=>false, 'controller'=>'Tickets', 'action' => 'index']);
115
    }
116
	
117 1
	public function addOperation($id = null) {
118 1
		$ticket = $this->Tickets->get($id, [
0 ignored issues
show
Unused Code introduced by
The assignment to $ticket is dead and can be removed.
Loading history...
119 1
            'contain' => []
120
        ]);
121
		
122 1
		$this->loadModel('Operations');
123 1
		$newOperation = $this->Operations->newEntity();
0 ignored issues
show
Bug Best Practice introduced by
The property Operations does not exist on App\Controller\TicketsController. Since you implemented __get, consider adding a @property annotation.
Loading history...
124 1
		if ($this->request->is('post')) {
125 1
			$datetimeStart = Time::parseDateTime($this->request->data['start']);
0 ignored issues
show
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

125
			$datetimeStart = Time::parseDateTime(/** @scrutinizer ignore-deprecated */ $this->request->data['start']);

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...
126 1
			$datetimeEnd = Time::parseDateTime($this->request->data['end']);
0 ignored issues
show
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

126
			$datetimeEnd = Time::parseDateTime(/** @scrutinizer ignore-deprecated */ $this->request->data['end']);

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...
127 1
			$newOperation->ticket_id = $this->request->data['ticket_id'];
0 ignored issues
show
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

127
			$newOperation->ticket_id = /** @scrutinizer ignore-deprecated */ $this->request->data['ticket_id'];

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...
128 1
			$newOperation->description = $this->request->data['description'];
0 ignored issues
show
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

128
			$newOperation->description = /** @scrutinizer ignore-deprecated */ $this->request->data['description'];

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...
129 1
			$newOperation->start = $datetimeStart;
130 1
			$newOperation->end = $datetimeEnd;
131 1
            if ($this->Operations->save($newOperation)) {
132
                $this->Flash->success(__('The new operation has been saved.'));
133
                return $this->redirect(['prefix'=>false, 'controller'=>'Tickets', 'action' => 'view', $this->request->data['ticket_id']]);
0 ignored issues
show
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

133
                return $this->redirect(['prefix'=>false, 'controller'=>'Tickets', 'action' => 'view', /** @scrutinizer ignore-deprecated */ $this->request->data['ticket_id']]);

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...
134
            }
135 1
            $this->Flash->error(__('The new operation could not be saved. Please, try again.'));
136
        }
137 1
		$newOperation->ticket_id = $id;
138 1
		$this->set('newOperation', $newOperation);
139 1
	}
140
141
    /**
142
     * @param null $operation_id
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $operation_id is correct as it would always require null to be passed?
Loading history...
143
     * @return \Cake\Network\Response|null
144
     */
145 1
    public function editOperation($operation_id = null) {
146
147 1
        $this->loadModel('Operations');
148 1
        $operation = $this->Operations->get($operation_id, [
0 ignored issues
show
Bug Best Practice introduced by
The property Operations does not exist on App\Controller\TicketsController. Since you implemented __get, consider adding a @property annotation.
Loading history...
149 1
            'contain' => ['Tickets']
150
        ]);
151 1
        if ($this->request->is(['patch', 'post', 'put'])) {
152 1
			$this->request->data['start'] = Time::parseDateTime($this->request->data['start']);
0 ignored issues
show
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

152
			/** @scrutinizer ignore-deprecated */ $this->request->data['start'] = Time::parseDateTime($this->request->data['start']);

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...
153 1
			$this->request->data['end'] = Time::parseDateTime($this->request->data['end']);
0 ignored issues
show
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

153
			/** @scrutinizer ignore-deprecated */ $this->request->data['end'] = Time::parseDateTime($this->request->data['end']);

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...
154 1
            $operation = $this->Operations->patchEntity($operation, $this->request->data);
0 ignored issues
show
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

154
            $operation = $this->Operations->patchEntity($operation, /** @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...
155
156 1
            if ($this->Operations->save($operation)) {
157
                $this->Flash->success(__('The operation has been saved.'));
158
159
                return $this->redirect(['prefix'=>false, 'controller'=>'Tickets', 'action' => 'view', $this->request->data['ticket_id']]);
0 ignored issues
show
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

159
                return $this->redirect(['prefix'=>false, 'controller'=>'Tickets', 'action' => 'view', /** @scrutinizer ignore-deprecated */ $this->request->data['ticket_id']]);

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...
160
            }
161 1
            $this->Flash->error(__('The operation could not be saved. Please, try again.'));
162
        }
163 1
        $this->set(compact('operation'));
164 1
        $this->set('_serialize', ['operation']);
165 1
    }
166
167
	public function viewOperation($id = null) {
168
		
169
		$this->loadModel('Operations');
170
		$operation = $this->Operations->get($id, [
0 ignored issues
show
Bug Best Practice introduced by
The property Operations does not exist on App\Controller\TicketsController. Since you implemented __get, consider adding a @property annotation.
Loading history...
171
			'contain' => ['Tickets']
172
		]);
173
174
		$this->set('operation', $operation);
175
		$this->set('_serialize', ['operation']);
176
	}
177
	
178
	public function deleteOperation($id = null) {
179
		
180
		$this->loadModel('Operations');
181
		$this->request->allowMethod(['post', 'delete']);
182
        $operation = $this->Operations->get($id, [
0 ignored issues
show
Bug Best Practice introduced by
The property Operations does not exist on App\Controller\TicketsController. Since you implemented __get, consider adding a @property annotation.
Loading history...
183
			'contain' => ['Tickets']
184
		]
185
		);
186
        if ($this->Operations->delete($operation)) {
187
            $this->Flash->success(__('The operation has been deleted.'));
188
        } else {
189
            $this->Flash->error(__('The operation could not be deleted. Please, try again.'));
190
        }
191
192
        return $this->redirect(['prefix'=>false, 'controller'=>'Tickets', 'action' => 'view', $operation->ticket_id]);
193
	}
194
}
195