Completed
Push — master ( 7831e5...73e30d )
by Denis
02:33
created

SystemFacade::setExceptionHandler()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
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
        if (function_exists('http_response_code')) {
128 1
            return http_response_code($httpCode);
129
        }
130
131
        // http_response_code is added in 5.4.
132
        // For compatibility with 5.3 we use the third argument in header call
133
        // First argument must be a real header.
134
        // If it is empty, PHP will ignore the third argument.
135
        // If it is invalid, such as a single space, Apache will handle it well,
136
        // but the PHP development server will hang.
137
        // Setting a full status line would require us to hardcode
138
        // string values for all different status code, and detect the protocol.
139
        // which is an extra error-prone complexity.
140
        header('X-Ignore-This: 1', true, $httpCode);
141
142
        return $httpCode;
143
    }
144
145
    /**
146
     * @param int $exitStatus
147
     */
148
    public function stopExecution($exitStatus)
149
    {
150
        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...
151
    }
152
}
153