ImportException   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A error_handler_callback() 0 14 2
A exception_handler() 0 22 3
1
<?php
2
/**
3
 * @name      OpenImporter
4
 * @copyright OpenImporter contributors
5
 * @license   BSD https://opensource.org/licenses/BSD-3-Clause
6
 *
7
 * @version 1.0
8
 */
9
10
namespace OpenImporter;
11
12
/**
13
 * Class ImportException
14
 * Extends the PHP build-in Exception class and catches potential errors
15
 */
16
class ImportException extends \Exception
17
{
18
	/**
19
	 * OI Error handler
20
	 *
21
	 * @param int $code
22
	 * @param string $string
23
	 * @param string $file
24
	 * @param int $line
25
	 *
26
	 * @throws ImportException
27
	 */
28
	public static function error_handler_callback($code, $string, $file, $line)
29
	{
30
		// Not telling?
31
		if (error_reporting() === 0)
32
		{
33
			return;
34
		}
35
36
		// Telling, just convert the error over to an exception
37
		$exception = new self($string, $code);
38
		$exception->line = $line;
39
		$exception->file = $file;
40
41
		self::exception_handler($exception);
42
	}
43
44
	/**
45
	 * OI Exception handler
46
	 *
47
	 * @param \Exception $exception
48
	 * @param \OpenImporter\Template $template
49
	 */
50
	public static function exception_handler($exception, $template = null)
51
	{
52
		global $oi_import;
53
54
		// Keeping secrets
55
		if (error_reporting() === 0)
56
		{
57
			return;
58
		}
59
60
		// Tell just your friends
61
		if ($template === null)
62
		{
63
			$template = $oi_import->template ?? new Template(null);
64
		}
65
66
		$message = $exception->getMessage();
67
		$trace = $exception->getTrace();
68
		$line = $exception->getLine();
69
		$file = $exception->getFile();
70
71
		$template->error($message, $trace[0]['args'][1] ?? null, $line, $file);
72
	}
73
}
74