Core   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 18
dl 0
loc 45
ccs 17
cts 17
cp 1
rs 10
c 0
b 0
f 0
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A rewriteLocation() 0 14 1
A handle() 0 14 4
1
<?php
2
3
namespace Mpyw\Exceper;
4
5
/**
6
 * Class Core
7
 */
8
class Core
9
{
10
    /**
11
     * @param callable $callback
12
     * @param callable $handler
13
     * @param int $types
14
     * @return mixed
15
     * @throws \Exception|\Throwable
16
     */
17
    public static function handle($callback, $handler, $types = null)
18 20
    {
19
        \set_error_handler($handler, $types === null ? \E_ALL | \E_STRICT : $types);
20 20
21
        try {
22
            $result = \call_user_func($callback);
23 20
            \restore_error_handler();
24 7
            return $result;
25 7
        } catch (\Exception $e) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
26 13
        } catch (\Throwable $e) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
27 5
        }
28
29
        \restore_error_handler();
30 13
        throw $e;
31 13
    }
32
33
    /**
34
     * @param \Exception|\Throwable $e
35
     * @param string $file
36
     * @param int $line
37
     * @return \Exception|\Throwable $e
38
     */
39
    public static function rewriteLocation($e, $file, $line)
40 8
    {
41
        $rc = new \ReflectionClass($e);
42 8
43
        $rpf = $rc->getProperty('file');
44 8
        $rpl = $rc->getProperty('line');
45 8
46
        $rpf->setAccessible(true);
47 8
        $rpl->setAccessible(true);
48 8
49
        $rpf->setValue($e, $file);
50 8
        $rpl->setValue($e, $line);
51 8
52
        return $e;
53 8
    }
54
}
55