Completed
Pull Request — v1 (#422)
by
unknown
03:17
created

Misc   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 1 Features 1
Metric Value
wmc 7
c 3
b 1
f 1
lcom 0
cbo 0
dl 0
loc 36
ccs 11
cts 11
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A canSendHeaders() 0 4 2
B translateErrorCode() 0 12 5
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 Misc
10
{
11
    /**
12
	 * Can we at this point in time send HTTP headers?
13
	 *
14
	 * Currently this checks if we are even serving an HTTP request,
15
	 * as opposed to running from a command line.
16
	 *
17
	 * If we are serving an HTTP request, we check if it's not too late.
18
	 *
19
	 * @return bool
20
	 */
21 2
    public static function canSendHeaders()
22
    {
23 2
        return isset($_SERVER["REQUEST_URI"]) && !headers_sent();
24
    }
25
26
    /**
27
	 * Translate ErrorException code into the represented constant.
28
	 *
29
	 * @param int $error_code
30
	 * @return string
31
	 */
32 2
    public static function translateErrorCode($error_code)
33
    {
34 2
        $constants = get_defined_constants(true);
35 2
        if (array_key_exists('Core' , $constants)) {
36 2
            foreach ($constants['Core'] as $constant => $value) {
37 2
                if (substr($constant, 0, 2) == 'E_' && $value == $error_code) {
38 1
                    return $constant;
39
                }
40 2
            }
41 1
        }
42 1
        return "E_UNKNOWN";
43
    }
44
}
45