Completed
Push — master ( 740d41...a3b506 )
by Michal
07:10 queued 16s
created

IncidentsController   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 89.47%

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 4
dl 0
loc 64
ccs 34
cts 38
cp 0.8947
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A json() 0 20 3
A view() 0 17 3
A create() 0 21 3
1
<?php
2
/* vim: set noexpandtab sw=2 ts=2 sts=2: */
3
namespace App\Controller;
4
5
use App\Controller\AppController;
6
use Cake\Network\Exception\NotFoundException;
7
use App\Utility\Sanitize;
8
/**
9
 * Incidents controller handling incident creation and rendering
10
 *
11
 * phpMyAdmin Error reporting server
12
 * Copyright (c) phpMyAdmin project (https://www.phpmyadmin.net/)
13
 *
14
 * Licensed under The MIT License
15
 * For full copyright and license information, please see the LICENSE.txt
16
 * Redistributions of files must retain the above copyright notice.
17
 *
18
 * @copyright     Copyright (c) phpMyAdmin project (https://www.phpmyadmin.net/)
19
 * @package       Server.Controller
20
 * @link          https://www.phpmyadmin.net/
21
 * @license       https://opensource.org/licenses/mit-license.php MIT License
22
 */
23
24
/**
25
 * Incidents controller handling incident creation and rendering
26
 *
27
 * @package       Server.Controller
28
 */
29
class IncidentsController extends AppController {
30
	public $uses = array("Incident", "Notification");
31
32 1
	public function create() {
33 1
		$bugReport = $this->request->input('json_decode', true);
34 1
		$result = $this->Incidents->createIncidentFromBugReport($bugReport);
35 1
		if (count($result) > 0 
36 1
			&& !in_array(false, $result)
37
		) {
38
			$response = array(
39 1
				"success" => true,
40 1
				"message" => "Thank you for your submission",
41 1
				"incident_id" => $result,		// Return a list of incident ids.
42
			);
43
		} else {
44
			$response = array(
45 1
				"success" => false,
46
				"message" => "There was a problem with your submission.",
47
			);
48
		}
49 1
		$this->autoRender = false;
50 1
        $this->response->body(json_encode($response, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
51 1
        return $this->response;
52
	}
53
54 1
	public function json($id) {
55 1
		if (!$id) {
56
			throw new NotFoundException(__('Invalid Incident'));
57
		}
58
59 1
		$this->Incidents->recursive = -1;
60 1
		$incident = $this->Incidents->findById($id)->all()->first();
61 1
		if (!$incident) {
62
			throw new NotFoundException(__('Invalid Incident'));
63
		}
64
65 1
		$incident['full_report'] =
66 1
				json_decode($incident['full_report'], true);
67 1
		$incident['stacktrace'] =
68 1
				json_decode($incident['stacktrace'], true);
69
70 1
		$this->autoRender = false;
71 1
        $this->response->body(json_encode($incident, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
72 1
        return $this->response;
73
	}
74
75 1
	public function view($incidentId) {
76 1
		if (!$incidentId) {
77
			throw new NotFoundException(__('Invalid Incident'));
78
		}
79
80 1
		$incident = $this->Incidents->findById($incidentId)->all()->first();
81 1
		if (!$incident) {
82
			throw new NotFoundException(__('Invalid Incident'));
83
		}
84
85 1
		$incident['full_report'] =
86 1
				json_decode($incident['full_report'], true);
87 1
		$incident['stacktrace'] =
88 1
				json_decode($incident['stacktrace'], true);
89
90 1
		$this->set('incident', $incident);
91 1
	}
92
}
93