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

JsonException   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 4
c 1
b 0
f 0
dl 0
loc 17
ccs 5
cts 5
cp 1
rs 10
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A assert() 0 9 2
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