Passed
Push — master ( 235c52...927bab )
by Daniel
30:30 queued 10s
created

PicoErrorResponse::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 22
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 15
c 1
b 0
f 0
dl 0
loc 22
ccs 0
cts 19
cp 0
rs 9.7666
cc 2
nc 2
nop 2
crap 6
1
<?php
2
/**
3
 * CMS Pico - Create websites using Pico CMS for Nextcloud.
4
 *
5
 * @copyright Copyright (c) 2019, Daniel Rudolf (<[email protected]>)
6
 *
7
 * @license GNU AGPL version 3 or any later version
8
 *
9
 * This program is free software: you can redistribute it and/or modify
10
 * it under the terms of the GNU Affero General Public License as
11
 * published by the Free Software Foundation, either version 3 of the
12
 * License, or (at your option) any later version.
13
 *
14
 * This program is distributed in the hope that it will be useful,
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 * GNU Affero General Public License for more details.
18
 *
19
 * You should have received a copy of the GNU Affero General Public License
20
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
21
 */
22
23
declare(strict_types=1);
24
25
namespace OCA\CMSPico\Http;
26
27
use OCA\CMSPico\AppInfo\Application;
28
use OCP\AppFramework\Http;
29
use OCP\AppFramework\Http\TemplateResponse;
30
31
class PicoErrorResponse extends TemplateResponse
32
{
33
	/** @var \Exception|null */
34
	private $exception;
35
36
	/**
37
	 * PicoErrorResponse constructor.
38
	 *
39
	 * @param string|null $message
40
	 * @param \Exception|null $exception
41
	 */
42
	public function __construct(string $message = null, \Exception $exception = null)
43
	{
44
		$this->exception = $exception;
45
46
		$params = [
47
			'message' => $message,
48
			'debugMode' => \OC::$server->getSystemConfig()->getValue('debug', false),
49
			'remoteAddr' => \OC::$server->getRequest()->getRemoteAddress(),
50
			'requestID' => \OC::$server->getRequest()->getId(),
51
		];
52
53
		if ($this->exception !== null) {
54
			$params['errorClass'] = get_class($this->exception);
55
			$params['errorMsg'] = $this->exception->getMessage();
56
			$params['errorCode'] = $this->exception->getCode();
57
			$params['errorFile'] = $this->exception->getFile();
58
			$params['errorLine'] = $this->exception->getLine();
59
			$params['errorTrace'] = $this->exception->getTraceAsString();
60
		}
61
62
		parent::__construct(Application::APP_NAME, 'error', $params, 'guest');
63
		$this->setStatus(Http::STATUS_INTERNAL_SERVER_ERROR);
64
	}
65
}
66