Completed
Pull Request — v1 (#450)
by Denis
02:54
created

SystemFacade::setErrorHandler()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 5
cts 5
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 2
crap 2
1
<?php
2
/**
3
 * Whoops - php errors for cool kids
4
 * @author Filipe Dobreira <http://github.com/filp>
5
 */
6
7
namespace Whoops\Util;
8
9
class SystemFacade
10
{
11
    /**
12
     * Turns on output buffering.
13
     *
14
     * @return bool
15
     */
16 2
    public function startOutputBuffering()
17
    {
18 2
        return ob_start();
19
    }
20
21
    /**
22
     * @param callable $handler
23
     * @param int      $types
24
     *
25
     * @return callable|null
26
     */
27 6
    public function setErrorHandler(callable $handler, $types = 'use-php-defaults')
28
    {
29
        // Workaround for PHP 5.5
30 6
        if ($types === 'use-php-defaults') {
31 5
            $types = E_ALL | E_STRICT;
32 5
        }
33 6
        return set_error_handler($handler, $types);
34
    }
35
36
    /**
37
     * @param callable $handler
38
     *
39
     * @return callable|null
40
     */
41 5
    public function setExceptionHandler(callable $handler)
42
    {
43 5
        return set_exception_handler($handler);
44
    }
45
46
    /**
47
     * @return void
48
     */
49 1
    public function restoreExceptionHandler()
50
    {
51 1
        restore_exception_handler();
52 1
    }
53
54
    /**
55
     * @return void
56
     */
57 1
    public function restoreErrorHandler()
58
    {
59 1
        restore_error_handler();
60 1
    }
61
62
    /**
63
     * @param callable $function
64
     *
65
     * @return void
66
     */
67 5
    public function registerShutdownFunction(callable $function)
68
    {
69 5
        register_shutdown_function($function);
70 5
    }
71
72
    /**
73
     * @return string|false
74
     */
75 2
    public function cleanOutputBuffer()
76
    {
77 2
        return ob_get_clean();
78
    }
79
80
    /**
81
     * @return int
82
     */
83 1
    public function getOutputBufferLevel()
84
    {
85 1
        return ob_get_level();
86
    }
87
88
    /**
89
     * @return bool
90
     */
91 1
    public function endOutputBuffering()
92
    {
93 1
        return ob_end_clean();
94
    }
95
96
    /**
97
     * @return void
98
     */
99 1
    public function flushOutputBuffer()
100
    {
101 1
        flush();
102 1
    }
103
104
    /**
105
     * @return int
106
     */
107 4
    public function getErrorReportingLevel()
108
    {
109 4
        return error_reporting();
110
    }
111
112
    /**
113
     * @return array|null
114
     */
115 1
    public function getLastError()
116
    {
117 1
        return error_get_last();
118
    }
119
120
    /**
121
     * @param int $httpCode
122
     *
123
     * @return int
124
     */
125 1
    public function setHttpResponseCode($httpCode)
126
    {
127 1
        return http_response_code($httpCode);
128
    }
129
130
    /**
131
     * @param int $exitStatus
132
     */
133
    public function stopExecution($exitStatus)
134
    {
135
        exit($exitStatus);
0 ignored issues
show
Coding Style Compatibility introduced by
The method stopExecution() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
136
    }
137
}
138