http_lib   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 14
dl 0
loc 27
rs 10
c 0
b 0
f 0
wmc 6

3 Methods

Rating   Name   Duplication   Size   Complexity  
A canonical_of() 0 2 1
A redirect() 0 3 1
A response_code() 0 16 4
1
<?php
2
3
class http_lib extends Library {
4
    function response_code($code, $view_and_exit = true, $view_name = false) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
5
        http_response_code($code);
6
        if ($view_and_exit) {
7
            if (empty($view_name)) {
8
                $view_name = strval($code);
9
            }
10
            // Check if a dedicated view exists; if not, load common error view
11
            $dedicated_view = $this->load_view($view_name, [
12
                'error_code' => $code,
13
            ]);
14
            if (! $dedicated_view) {
15
                $this->load_view('http_error', [
16
                    'error_code' => $code,
17
                ]);
18
            }
19
            exit();
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
20
        }
21
    }
22
23
    function redirect($url, $status_code = 302) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
24
        header('Location: ' . $url, true, $status_code);
25
        exit();
26
    }
27
28
    function canonical_of($url) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
29
        header('Link: <' . $url . '>; rel="canonical"');
30
    }
31
32
}
33