Passed
Push — main ( a115e2...ed9b12 )
by Marc
04:17 queued 13s
created

admin_process_post_request()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 2
rs 10
1
<?php declare(strict_types=1);
2
3
use html_go\exceptions\InternalException;
4
use html_go\model\Config;
5
require_once ADMIN_SYS_ROOT.DS.'functions.php';
6
7
function admin_route(string $uri, string $method = HTTP_GET): ?\stdClass {
8
    $context = get_config()->getString(Config::KEY_ADMIN_CONTEXT);
9
    if (\str_starts_with($uri, $context) === false) {
10
        return null;
11
    }
12
13
    switch ($method) {
14
        case HTTP_GET:
15
            $content = admin_process_get_request($context, $uri);
16
            break;
17
        case HTTP_POST:
18
            $content = admin_process_post_request($uri);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $content is correct as admin_process_post_request($uri) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
19
            break;
20
        default:
21
            throw new InternalException("Unsupported HTTP Method [$method]");
22
    }
23
24
    return $content;
25
}
26
27
function admin_process_get_request(string $context, string $uri): ?\stdClass {
28
    $resource = \substr($uri, \strlen($context));
29
    $i18n = get_i18n();
30
    $pageTitle = $i18n->getText('admin.title.prefix').$i18n->getText('admin.dashboard.title');
31
    if ($resource === DASHBOARD_INDEX_KEY) {
32
        $content = get_admin_content_object('dashboard.html', title: $pageTitle);
33
    }
34
35
    return $content;
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $content does not seem to be defined for all execution paths leading up to this point.
Loading history...
36
}
37
38
function admin_process_post_request(string $uri): ?\stdClass {
0 ignored issues
show
Unused Code introduced by
The parameter $uri is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

38
function admin_process_post_request(/** @scrutinizer ignore-unused */ string $uri): ?\stdClass {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
39
    return null;
40
}