Passed
Push — master ( 2bc6a1...487703 )
by Tom
02:53
created

ErrorCatcher::end()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 7
ccs 5
cts 5
cp 1
crap 1
rs 9.4285
c 0
b 0
f 0
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 3
    public function __construct()
30
    {
31 3
        $this->start();
32 3
    }
33
34
    /**
35
     * @return ErrorCatcher
36
     */
37 1
    public static function create()
38
    {
39 1
        return new self();
40
    }
41
42
    /**
43
     * @return bool an error occured 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
     * start catching session (is auto-started on create)
56
     */
57 3
    private function start()
58
    {
59 3
        $this->previous = error_get_last();
60 3
        $this->level = error_reporting();
61 3
        error_reporting(0);
62 3
    }
63
}
64