Passed
Branch master (f497d2)
by Mike
03:18
created

GSyncException::__construct()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 6
nc 4
nop 4
dl 0
loc 11
rs 10
c 1
b 0
f 0
1
<?php
2
/*
3
 * SPDX-License-Identifier: AGPL-3.0-only
4
 * SPDX-FileCopyrightText: Copyright 2007-2016 Zarafa Deutschland GmbH
5
 * SPDX-FileCopyrightText: Copyright 2020-2022 grommunio GmbH
6
 *
7
 * Main grommunio-sync exception
8
 */
9
10
class GSyncException extends Exception {
11
	protected $defaultLogLevel = LOGLEVEL_FATAL;
12
	protected $httpReturnCode = HTTP_CODE_500;
13
	protected $httpReturnMessage = "Internal Server Error";
14
	protected $httpHeaders = [];
15
	protected $showLegal = true;
16
17
	public function __construct($message = "", $code = 0, $previous = null, $logLevel = false) {
18
		if (!$message) {
19
			$message = $this->httpReturnMessage;
20
		}
21
22
		if (!$logLevel) {
23
			$logLevel = $this->defaultLogLevel;
24
		}
25
26
		parent::__construct($message, (int) $code);
27
		SLog::Write($logLevel, get_class($this) . ': ' . $message . ' - code: ' . $code . ' - file: ' . $this->getFile() . ':' . $this->getLine(), false);
28
	}
29
30
	public function getHTTPCodeString() {
31
		return $this->httpReturnCode . " " . $this->httpReturnMessage;
32
	}
33
34
	public function getHTTPHeaders() {
35
		return $this->httpHeaders;
36
	}
37
38
	public function showLegalNotice() {
39
		return $this->showLegal;
40
	}
41
}
42