anonymous()
last analyzed

Size

Total Lines 33
Code Lines 28

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 28
c 0
b 0
f 0
nc 8
nop 1
dl 0
loc 33
1
<?php declare(strict_types=1);
2
3
use html_go\model\Config;
4
use html_go\Utils;
0 ignored issues
show
Bug introduced by
The type html_go\Utils was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
5
6
return [
7
    HTTP_GET => [
8
        ADMIN_DASHBOARD_KEY => (object) [
9
            'cb' => 'get_dashboard_view_content_object'
10
        ],
11
        CAT_INDEX_KEY => (object) [
12
            'cb' => 'get_category_listview_content_object'
13
        ],
14
        CAT_INDEX_KEY.FWD_SLASH.ADMIN_ACTION_EDIT => (object) [
15
            'cb' => 'get_category_edit_object'
16
        ],
17
        CAT_INDEX_KEY.FWD_SLASH.ADMIN_ACTION_ADD => (object) [
18
            'cb' => 'get_category_add_content_object'
19
        ],
20
        CAT_INDEX_KEY.FWD_SLASH.ADMIN_ACTION_DELETE => (object) [
21
            'cb' => 'get_category_delete_object'
22
        ]
23
    ],
24
    HTTP_POST => [
25
        CAT_INDEX_KEY => (object) [
26
            'cb' => function (array $data): \stdClass {
27
                if (empty($data[ADMIN_ACTION_CANCEL]) === false) {
28
                    header('Location: '.get_config()->getString(Config::KEY_SITE_URL).FWD_SLASH.$data[ADMIN_CONTEXT_STR].FWD_SLASH.'category');
29
                    return new \stdClass();
30
                }
31
                if (empty($data[ADMIN_ACTION_STR])) {
32
                    return new \stdClass(); // Force not-found 404
33
                }
34
                $content = new \stdClass();
35
                $action = $data[ADMIN_ACTION_STR];
36
                switch ($action) {
37
                    case ADMIN_ACTION_ADD:
38
                        if (save_category($data)) {
39
                            header('Location: '.get_config()->getString(Config::KEY_SITE_URL).FWD_SLASH.$data[ADMIN_CONTEXT_STR].FWD_SLASH.'category');
40
                        } else {
41
                            $content = get_category_add_content_object();
42
                            $content->list[0] = (object)$data;
43
                            print_r($data);
44
                        }
45
                        break;
46
                    case ADMIN_ACTION_EDIT:
47
                        if (update_category($data)) {
48
                            header('Location: '.get_config()->getString(Config::KEY_SITE_URL).FWD_SLASH.$data[ADMIN_CONTEXT_STR].FWD_SLASH.'category');
49
                        } else {
50
                            exit('Update: validation failed');
0 ignored issues
show
Bug Best Practice introduced by
In this branch, the function will implicitly return null which is incompatible with the type-hinted return stdClass. Consider adding a return statement or allowing null as return value.

For hinted functions/methods where all return statements with the correct type are only reachable via conditions, ?null? gets implicitly returned which may be incompatible with the hinted type. Let?s take a look at an example:

interface ReturnsInt {
    public function returnsIntHinted(): int;
}

class MyClass implements ReturnsInt {
    public function returnsIntHinted(): int
    {
        if (foo()) {
            return 123;
        }
        // here: null is implicitly returned
    }
}
Loading history...
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...
51
                        }
52
                        break;
53
                    case ADMIN_ACTION_DELETE:
54
                        break;
55
                    default:
56
                        break;
57
                }
58
                return $content;
59
            }
60
        ]
61
    ]
62
];
63