Completed
Push — master ( 470825...143e87 )
by Joram van den
06:11
created

error.php ➔ desc()   C

Complexity

Conditions 10
Paths 10

Size

Total Lines 24
Code Lines 21

Duplication

Lines 14
Ratio 58.33 %

Importance

Changes 0
Metric Value
cc 10
eloc 21
nc 10
nop 0
dl 14
loc 24
rs 5.2164
c 0
b 0
f 0

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
// Allow direct access from .htaccess
4
// if (!defined('AJDE')) {
5
// 	die('No direct access');
6
// }
7
8
global $code;
9
if (isset($_SERVER['REDIRECT_STATUS'])) {
10
    $code = $_SERVER['REDIRECT_STATUS'];
11
    if ($code === '200') {
12
        $code = 500;
13
    }
14
} else {
15
    $code = 500;
16
}
17
18 View Code Duplication
function desc()
0 ignored issues
show
Duplication introduced by
This function seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
19
{
20
    global $code;
21
    switch ($code) {
22
        case 400:
23
            return 'Bad Request';
24
        case 401:
25
            return 'Unauthorized';
26
        case 403:
27
            return 'Forbidden';
28
        case 404:
29
            return 'Not Found';
30
        case 500:
31
            return 'Internal Server Error';
32
        case 501:
33
            return 'Not Implemented';
34
        case 502:
35
            return 'Bad Gateway';
36
        case 503:
37
            return 'Service Unavailable';
38
        case 504:
39
            return 'Bad Timeout';
40
    }
41
}
42
43
?>
44
<!DOCTYPE html>
45
<html>
46
<head>
47
    <title>Server error</title>
48
</head>
49
<body>
50
<h1>ERROR <?php echo $code; ?> - <?php echo desc(); ?></h1>
51
<h3>Unfortunately, something went wrong.</h3>
52
<hr/>
53
<p><a href="http://code.google.com/p/ajde">Ajde open framework</a>
54
55
    <!--
56
    Adding up to at least 512 bytes with some text from
57
    http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html
58
59
    The server has not found anything matching the Request-URI. No
60
    indication is given of whether the condition is temporary or permanent. The
61
    410 (Gone) status code SHOULD be used if the server knows, through some
62
    internally configurable mechanism, that an old resource is permanently
63
    unavailable and has no forwarding address. This status code is commonly
64
    used when the server does not wish to reveal exactly why the request has
65
    been refused, or when no other response is applicable.
66
    -->
67
</body>
68
</html>
69