TicketsController   A
last analyzed

Complexity

Total Complexity 19

Size/Duplication

Total Lines 174
Duplicated Lines 0 %

Test Coverage

Coverage 44.21%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
eloc 82
c 3
b 0
f 0
dl 0
loc 174
ccs 42
cts 95
cp 0.4421
rs 10
wmc 19

9 Methods

Rating   Name   Duplication   Size   Complexity  
A viewOperation() 0 9 1
A editOperation() 0 20 3
A addOperation() 0 22 3
A delete() 0 10 2
A deleteOperation() 0 15 2
A view() 0 7 1
A add() 0 15 3
A index() 0 6 1
A edit() 0 17 3
1
<?php
0 ignored issues
show
Coding Style introduced by
Filename "TicketsController.php" doesn't match the expected filename "ticketscontroller.php"
Loading history...
Coding Style introduced by
The PHP open tag does not have a corresponding PHP close tag
Loading history...
Coding Style introduced by
This file is missing a doc comment.
Loading history...
Coding Style introduced by
Class found in ".php" file; use ".inc" extension instead
Loading history...
2
0 ignored issues
show
Coding Style introduced by
Missing file doc comment
Loading history...
3
namespace App\Controller;
4
5
use App\Controller\AppController;
0 ignored issues
show
introduced by
Unused use statement
Loading history...
6
use Cake\I18n\Time;
7
use Cake\I18n\I18n;
0 ignored issues
show
introduced by
Unused use statement
Loading history...
8
9
/**
10
 * Tickets Controller
11
 *
12
 * @property \App\Model\Table\TicketsTable $Tickets
13
 */
0 ignored issues
show
Coding Style introduced by
Missing @category tag in class comment
Loading history...
Coding Style introduced by
Missing @package tag in class comment
Loading history...
Coding Style introduced by
Missing @link tag in class comment
Loading history...
Coding Style introduced by
Missing @license tag in class comment
Loading history...
Coding Style introduced by
Missing @author tag in class comment
Loading history...
14
class TicketsController extends AppController {
0 ignored issues
show
Coding Style introduced by
Opening brace of a class must be on the line after the definition
Loading history...
15
16
    /**
17
     * Index method
18
     *
19
     * @return \Cake\Network\Response|null
0 ignored issues
show
introduced by
Function return type is not void, but function has no return statement
Loading history...
introduced by
@return doc comment specified, but function has no return statement
Loading history...
20
     */
21 1
    public function index() {
0 ignored issues
show
Coding Style introduced by
Expected 0 blank lines after opening function brace; 1 found
Loading history...
Coding Style introduced by
Opening brace should be on a new line
Loading history...
22
23 1
        $tickets = $this->paginate($this->Tickets->find('all', ['contain' => ['Tickettypes', 'Ticketstatuses']]));
24
25 1
        $this->set(compact('tickets'));
26 1
        $this->set('_serialize', ['tickets']);
27 1
    }
28
29
    /**
30
     * View method
31
     *
32
     * @param string|null $id Ticket id.
0 ignored issues
show
introduced by
Parameter comment must be on the next line
Loading history...
33
     * @return \Cake\Network\Response|null
0 ignored issues
show
introduced by
@return doc comment specified, but function has no return statement
Loading history...
introduced by
Function return type is not void, but function has no return statement
Loading history...
introduced by
Separate the @param and @return sections by a blank line.
Loading history...
34
     * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
0 ignored issues
show
introduced by
@throws comment must be on the next line
Loading history...
introduced by
Separate the @return and @throws sections by a blank line.
Loading history...
35
     */
36 1
    public function view($id = null) {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on a new line
Loading history...
37 1
        $ticket = $this->Tickets->get($id, [
38 1
            'contain' => ['Operations', 'Tickettypes']
0 ignored issues
show
introduced by
A comma should follow the last multiline array item. Found: ]
Loading history...
39
        ]);
40
41 1
        $this->set('ticket', $ticket);
42 1
        $this->set('_serialize', ['ticket']);
43 1
    }
44
45
    /**
46
     * Add method
47
     *
48
     * @return \Cake\Network\Response|null Redirects on successful add, renders view otherwise.
49
     */
50 2
    public function add() {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on a new line
Loading history...
51 2
        $ticket = $this->Tickets->newEmptyEntity();
52 2
        if ($this->request->is('post')) {
53 2
            $ticket = $this->Tickets->patchEntity($ticket, $this->getRequest()->getData());
54 2
            if ($this->Tickets->save($ticket)) {
55 2
                $this->Flash->success(__('The ticket has been saved.'));
56
57 2
                return $this->redirect(['prefix' => false, 'controller' => 'Tickets', 'action' => 'index']);
58
            }
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
59
            $this->Flash->error(__('The ticket could not be saved. Please, try again.'));
60
        }
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
61 2
        $types = $this->Tickets->Tickettypes->find('list');
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 4 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
62 2
        $statuses = $this->Tickets->Ticketstatuses->find('list');
63 2
        $this->set(compact('ticket', 'types', 'statuses'));
64 2
        $this->set('_serialize', ['ticket']);
65 2
    }
66
67
    /**
68
     * Edit method
69
     *
70
     * @param string|null $id Ticket id.
0 ignored issues
show
introduced by
Parameter comment must be on the next line
Loading history...
71
     * @return \Cake\Network\Response|null Redirects on successful edit, renders view otherwise.
0 ignored issues
show
introduced by
Separate the @param and @return sections by a blank line.
Loading history...
72
     * @throws \Cake\Network\Exception\NotFoundException When record not found.
0 ignored issues
show
introduced by
Separate the @return and @throws sections by a blank line.
Loading history...
introduced by
@throws comment must be on the next line
Loading history...
73
     */
74 1
    public function edit($id = null) {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on a new line
Loading history...
75 1
        $ticket = $this->Tickets->get($id, [
76 1
            'contain' => ['Tickettypes']
0 ignored issues
show
introduced by
A comma should follow the last multiline array item. Found: ]
Loading history...
77
        ]);
78 1
        if ($this->request->is(['patch', 'post', 'put'])) {
79 1
            $ticket = $this->Tickets->patchEntity($ticket, $this->getRequest()->getData());
80 1
            if ($this->Tickets->save($ticket)) {
81 1
                $this->Flash->success(__('The ticket has been saved.'));
82
83 1
                return $this->redirect(['prefix' => false, 'controller' => 'Tickets', 'action' => 'index']);
84
            }
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
85
            $this->Flash->error(__('The ticket could not be saved. Please, try again.'));
86
        }
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
87 1
        $tickettypes = $this->Tickets->Tickettypes->find('list');
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 4 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
88 1
        $ticketstatuses = $this->Tickets->Ticketstatuses->find('list');
89 1
        $this->set(compact('ticket', 'tickettypes', 'ticketstatuses'));
90 1
        $this->set('_serialize', ['ticket']);
91 1
    }
92
93
    /**
94
     * Delete method
95
     *
96
     * @param string|null $id Ticket id.
0 ignored issues
show
introduced by
Parameter comment must be on the next line
Loading history...
97
     * @return \Cake\Network\Response|null Redirects to index.
0 ignored issues
show
introduced by
Separate the @param and @return sections by a blank line.
Loading history...
98
     * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
0 ignored issues
show
introduced by
Separate the @return and @throws sections by a blank line.
Loading history...
introduced by
@throws comment must be on the next line
Loading history...
99
     */
100 1
    public function delete($id = null) {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on a new line
Loading history...
101 1
        $this->request->allowMethod(['post', 'delete']);
102 1
        $ticket = $this->Tickets->get($id);
103 1
        if ($this->Tickets->delete($ticket)) {
104 1
            $this->Flash->success(__('The ticket has been deleted.'));
105
        } else {
0 ignored issues
show
introduced by
Expected newline after closing brace
Loading history...
106
            $this->Flash->error(__('The ticket could not be deleted. Please, try again.'));
107
        }
108
109 1
        return $this->redirect(['prefix' => false, 'controller' => 'Tickets', 'action' => 'index']);
110
    }
111
112
    public function addOperation($id = null) {
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function addOperation()
Loading history...
Coding Style introduced by
Opening brace should be on a new line
Loading history...
introduced by
Missing function doc comment
Loading history...
113
        $ticket = $this->Tickets->get($id, [
114
            'contain' => []
0 ignored issues
show
introduced by
A comma should follow the last multiline array item. Found: ]
Loading history...
115
        ]);
116
117
        $this->loadModel('Operations');
118
        $newOperation = $this->Operations->newEntity();
119
        if ($this->request->is('post')) {
120
            $datetimeStart = Time::parseDateTime($this->request->data['start']);
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 13 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
121
            $datetimeEnd = Time::parseDateTime($this->request->data['end']);
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 15 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
122
            $newOperation->ticket_id = $this->request->data['ticket_id'];
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 3 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
123
            $newOperation->description = $this->request->data['description'];
124
            $newOperation->start = $datetimeStart;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 7 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
125
            $newOperation->end = $datetimeEnd;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 9 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
126
            if ($this->Operations->save($newOperation)) {
127
                $this->Flash->success(__('The new operation has been saved.'));
128
                return $this->redirect(['prefix' => false, 'controller' => 'Tickets', 'action' => 'view', $this->request->data['ticket_id']]);
129
            }
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
130
            $this->Flash->error(__('The new operation could not be saved. Please, try again.'));
131
        }
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
132
        $newOperation->ticket_id = $id;
133
        $this->set('newOperation', $newOperation);
134
    }
135
136
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
137
     * @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...
Coding Style introduced by
Missing parameter comment
Loading history...
138
     * @return \Cake\Network\Response|null
139
     */
140
    public function editOperation($operation_id = null) {
0 ignored issues
show
introduced by
Type hint "null" missing for $operation_id
Loading history...
Coding Style introduced by
Expected 0 blank lines after opening function brace; 1 found
Loading history...
Coding Style introduced by
Opening brace should be on a new line
Loading history...
141
142
        $this->loadModel('Operations');
143
        $operation = $this->Operations->get($operation_id, [
144
            'contain' => ['Tickets']
0 ignored issues
show
introduced by
A comma should follow the last multiline array item. Found: ]
Loading history...
145
        ]);
146
        if ($this->request->is(['patch', 'post', 'put'])) {
147
            $this->request->data['start'] = Time::parseDateTime($this->request->data['start']);
148
            $this->request->data['end'] = Time::parseDateTime($this->request->data['end']);
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 3 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
149
            $operation = $this->Operations->patchEntity($operation, $this->request->data);
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 20 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
150
151
            if ($this->Operations->save($operation)) {
152
                $this->Flash->success(__('The operation has been saved.'));
153
154
                return $this->redirect(['prefix' => false, 'controller' => 'Tickets', 'action' => 'view', $this->request->data['ticket_id']]);
155
            }
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
156
            $this->Flash->error(__('The operation could not be saved. Please, try again.'));
157
        }
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
158
        $this->set(compact('operation'));
159
        $this->set('_serialize', ['operation']);
160
    }
161
162
    public function viewOperation($id = null) {
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function viewOperation()
Loading history...
introduced by
Missing function doc comment
Loading history...
Coding Style introduced by
Expected 0 blank lines after opening function brace; 1 found
Loading history...
Coding Style introduced by
Opening brace should be on a new line
Loading history...
163
164
        $this->loadModel('Operations');
165
        $operation = $this->Operations->get($id, [
166
            'contain' => ['Tickets']
0 ignored issues
show
introduced by
A comma should follow the last multiline array item. Found: ]
Loading history...
167
        ]);
168
169
        $this->set('operation', $operation);
170
        $this->set('_serialize', ['operation']);
171
    }
172
173
    public function deleteOperation($id = null) {
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function deleteOperation()
Loading history...
Coding Style introduced by
Opening brace should be on a new line
Loading history...
Coding Style introduced by
Expected 0 blank lines after opening function brace; 1 found
Loading history...
introduced by
Missing function doc comment
Loading history...
174
175
        $this->loadModel('Operations');
176
        $this->request->allowMethod(['post', 'delete']);
177
        $operation = $this->Operations->get($id, [
178
            'contain' => ['Tickets']
0 ignored issues
show
introduced by
A comma should follow the last multiline array item. Found: ]
Loading history...
179
                ]
0 ignored issues
show
Coding Style introduced by
Array close brace not indented correctly; expected 8 spaces but found 16
Loading history...
180
        );
181
        if ($this->Operations->delete($operation)) {
182
            $this->Flash->success(__('The operation has been deleted.'));
183
        } else {
0 ignored issues
show
introduced by
Expected newline after closing brace
Loading history...
184
            $this->Flash->error(__('The operation could not be deleted. Please, try again.'));
185
        }
186
187
        return $this->redirect(['prefix' => false, 'controller' => 'Tickets', 'action' => 'view', $operation->ticket_id]);
188
    }
189
190
}
191