Completed
Push — master ( ccb78a...e0e64f )
by Nazar
04:41
created

ExitException   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 88.24%

Importance

Changes 0
Metric Value
dl 0
loc 45
ccs 15
cts 17
cp 0.8824
rs 10
c 0
b 0
f 0
wmc 6
lcom 1
cbo 1

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 17 4
A getJson() 0 3 1
A setJson() 0 4 1
1
<?php
2
/**
3
 * @package   CleverStyle Framework
4
 * @author    Nazar Mokrynskyi <[email protected]>
5
 * @copyright Copyright (c) 2015-2016, Nazar Mokrynskyi
6
 * @license   MIT License, see license.txt
7
 */
8
namespace cs;
9
use
10
	Exception;
11
12
class ExitException extends Exception {
13
	/**
14
	 * @var bool
15
	 */
16
	protected $json = false;
17
	/**
18
	 * ExitException constructor.
19
	 *
20
	 * @param int|string|string[] $message Error message (or code if no message)
21
	 * @param int                 $code    HTTP status code
22
	 * @param Exception|null      $previous
23
	 */
24 4
	function __construct ($message = '', $code = 0, Exception $previous = null) {
25 4
		parent::__construct('', $code, $previous);
26 4
		if (is_numeric($message) && !$code) {
27 4
			$this->code = $message;
28
		} else {
29 2
			$this->message = $message;
30
		}
31
		/**
32
		 * Make sure code is always the same in `cs\ExitException` and `cs\Response` instances
33
		 */
34 4
		$Response = Response::instance();
35 4
		if ($this->code) {
36 4
			$Response->code = $this->code;
37
		} else {
38 2
			$this->code = $Response->code;
39
		}
40 4
	}
41
	/**
42
	 * @return bool
43
	 */
44 4
	function getJson () {
45 4
		return $this->json;
46
	}
47
	/**
48
	 * Specify that error should be in JSON format
49
	 *
50
	 * @return $this
51
	 */
52 2
	function setJson () {
53 2
		$this->json = true;
54 2
		return $this;
55
	}
56
}
57