http_lib::response_code()   A
last analyzed

Complexity

Conditions 4
Paths 5

Size

Total Lines 16
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 10
nc 5
nop 3
dl 0
loc 16
rs 9.9332
c 0
b 0
f 0
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