Passed
Push — master ( 3f0369...26e86a )
by Tom
04:24
created

ErrorCatcher::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 1
c 1
b 0
f 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
3
/* this file is part of pipelines */
4
5
namespace Ktomk\Pipelines;
6
7
/**
8
 * catch errors w/ restore
9
 *
10
 * @package Ktomk\Pipelines
11
 */
12
class ErrorCatcher
13
{
14
    /**
15
     * @var null|array
16
     */
17
    private $last;
18
19
    /**
20
     * @var null|array
21
     */
22
    private $previous;
23
24
    /**
25
     * @var int
26
     */
27
    private $level;
28
29
    /**
30
     * @return ErrorCatcher
31
     */
32 1
    public static function create()
33
    {
34 1
        return new self();
35
    }
36
37 3
    public function __construct()
38
    {
39 3
        $this->start();
40 3
    }
41
42
    /**
43
     * @return bool an error occurred between start and end
44
     */
45 2
    public function end()
46
    {
47 2
        $this->last = error_get_last();
48 2
        $error = $this->last !== $this->previous;
49 2
        error_reporting($this->level);
50
51 2
        return $error;
52
    }
53
54
    /**
55
     * @return null|string
56
     */
57 2
    public function getLastErrorMessage()
58
    {
59 2
        $error = $this->last !== $this->previous;
60
61 2
        return $error ? $this->last['message'] : null;
62
    }
63
64
    /**
65
     * start catching session (is auto-started on create)
66
     *
67
     * @return void
68
     */
69 3
    private function start()
70
    {
71 3
        @$void;
1 ignored issue
show
Comprehensibility Best Practice introduced by
The variable $void seems to be never defined.
Loading history...
72 3
        $this->previous = error_get_last();
73 3
        $this->level = error_reporting();
74 3
        error_reporting(0);
75 3
    }
76
}
77