ErrorHandler::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
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 $errno
35
     * @param string $errstr
36
     * @param string $errfile
37
     * @param int $errline
38
     * @param array $errcontext
39
     * @return bool
40
     */
41
    public function callback($errno, $errstr, $errfile = '', $errline = 0, $errcontext = [])
42
    {
43
        $this->log[(string)microtime(true)] = [
44
            'no' => $errno,
45
            'str' => $errstr,
46
            'file' => $errfile,
47
            'line' => $errline,
48
            'context' => $errcontext,
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