Passed
Branch master (37a4df)
by Anatoly
02:49
created

JsonException::assert()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 4
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 9
ccs 5
cts 5
cp 1
crap 2
rs 10
1
<?php declare(strict_types=1);
2
3
/**
4
 * It's free open-source software released under the MIT License.
5
 *
6
 * @author Anatoly Fenric <[email protected]>
7
 * @copyright Copyright (c) 2018, Anatoly Fenric
8
 * @license https://github.com/sunrise-php/http-message/blob/master/LICENSE
9
 * @link https://github.com/sunrise-php/http-message
10
 */
11
12
namespace Sunrise\Http\Message\Exception;
13
14
/**
15
 * Import classes
16
 */
17
use RuntimeException;
18
19
/**
20
 * Import functions
21
 */
22
use function json_last_error;
23
use function json_last_error_msg;
24
25
/**
26
 * Import constants
27
 */
28
use const JSON_ERROR_NONE;
29
30
/**
31
 * JsonException
32
 */
33
class JsonException extends RuntimeException
34
{
35
36
	/**
37
	 * @return void
38
	 *
39
	 * @throws self
40
	 */
41 2
	public static function assert() : void
42
	{
43 2
		$code = json_last_error();
44
45 2
		if (JSON_ERROR_NONE === $code) {
46 1
			return;
47
		}
48
49 1
		throw new self(json_last_error_msg(), $code);
50
	}
51
}
52