Completed
Push — master ( aa60f5...228ec0 )
by Jan-Petter
02:43
created

ErrorHandler::callback()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 11
rs 9.4285
cc 1
eloc 8
nc 1
nop 5
1
<?php
2
/**
3
 * vipnytt/RobotsTxtParser
4
 *
5
 * @link https://github.com/VIPnytt/RobotsTxtParser
6
 * @license https://github.com/VIPnytt/RobotsTxtParser/blob/master/LICENSE The MIT License (MIT)
7
 */
8
9
namespace vipnytt\RobotsTxtParser\Handler;
10
11
/**
12
 * Class ErrorHandler
13
 *
14
 * @package vipnytt\RobotsTxtParser\Handler
15
 */
16
class ErrorHandler
17
{
18
    /**
19
     * Error log
20
     * @var string[]
21
     */
22
    protected $log = [];
23
24
    /**
25
     * ErrorHandler constructor.
26
     */
27
    public function __construct()
28
    {
29
    }
30
31
    /**
32
     * Callback
33
     *
34
     * @param int $no
35
     * @param string $str
36
     * @param string $file
37
     * @param int $line
38
     * @param array $context
39
     * @return bool
40
     */
41
    public function callback($no, $str, $file = '', $line = 0, $context = [])
42
    {
43
        $this->log[(string)microtime(true)] = [
44
            'no' => $no,
45
            'str' => $str,
46
            'file' => $file,
47
            'line' => $line,
48
            'context' => $context,
49
        ];
50
        return $this->handle();
51
    }
52
53
    /**
54
     * Handle
55
     *
56
     * @return bool
57
     */
58
    private function handle()
59
    {
60
        return !in_array(end($this->log)['no'], [
61
            E_ERROR,
62
            E_USER_ERROR,
63
        ]);
64
    }
65
66
    /**
67
     * Last error as string
68
     *
69
     * @return array|false
70
     */
71
    public function getLast()
72
    {
73
        return end($this->log);
74
    }
75
}
76