Test Setup Failed
Push — master ( a4f66d...29baaf )
by Mihail
41:06
created

Main::actionDeleteroute()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 16
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 16
rs 9.4286
cc 2
eloc 10
nc 2
nop 0
1
<?php
2
3
namespace Apps\Controller\Admin;
4
5
use Apps\Model\Admin\Main\EntityDeleteRoute;
6
use Apps\Model\Admin\Main\FormAddRoute;
7
use Apps\Model\Admin\Main\FormSettings;
8
use Extend\Core\Arch\AdminController;
9
use Ffcms\Core\App;
10
use Ffcms\Core\Exception\SyntaxException;
11
use Ffcms\Core\Helper\FileSystem\File;
12
use Ffcms\Core\Helper\Type\Arr;
13
use Ffcms\Core\Helper\Type\Integer;
14
use Ffcms\Core\Helper\Type\Str;
15
16
class Main extends AdminController
17
{
18
    public function __construct()
19
    {
20
        parent::__construct(false);
21
    }
22
23
    /**
24
     * Index page of admin dashboard
25
     */
26
    public function actionIndex()
27
    {
28
        return App::$View->render('index', [
29
30
        ]);
31
    }
32
33
    /**
34
     * Manage settings in web
35
     */
36 View Code Duplication
    public function actionSettings()
0 ignored issues
show
Duplication introduced by
This method 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...
37
    {
38
        $model = new FormSettings();
39
40
        if ($model->send()) {
41
            if ($model->validate()) {
42
                if ($model->makeSave()) {
43
                    // show message about successful save and take system some time ;)
44
                    return App::$View->render('settings_save');
45
                } else {
46
                    App::$Session->getFlashBag()->add('error', __('Configuration file is not writable! Check /Private/Config/ dir and files'));
47
                }
48
            } else {
49
                App::$Session->getFlashBag()->add('error', __('Validation of form data is failed!'));
50
            }
51
        }
52
53
        return App::$View->render('settings', [
54
            'model' => $model // no $model->export() there
0 ignored issues
show
Unused Code Comprehensibility introduced by
40% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
55
        ]);
56
    }
57
58
    /**
59
     * Manage files via elFinder
60
     */
61
    public function actionFiles()
62
    {
63
        return App::$View->render('files', [
64
            'connector' => App::$Alias->scriptUrl . '/api/main/files?lang=' . App::$Request->getLanguage()
65
        ]);
66
    }
67
68
    /**
69
     * Show antivirus
70
     */
71
    public function actionAntivirus()
72
    {
73
        return App::$View->render('antivirus');
74
    }
75
76
    public function actionDebugcookie()
77
    {
78
        $cookieProperty = App::$Properties->get('debug');
79
        //App::$Request->cookies->add([$cookieProperty['cookie']['key'] => $cookieProperty['cookie']['value']]); todo: fix me
0 ignored issues
show
Unused Code Comprehensibility introduced by
72% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
80
        setcookie($cookieProperty['cookie']['key'], $cookieProperty['cookie']['value'], Integer::MAX, '/', null, null, true);
81
        App::$Response->redirect('/');
82
    }
83
84
    /**
85
     * List available routes
86
     * @throws \Ffcms\Core\Exception\SyntaxException
87
     */
88
    public function actionRouting()
89
    {
90
        $routingMap = App::$Properties->getAll('Routing');
91
92
        return App::$View->render('routing', [
93
            'routes' => $routingMap
94
        ]);
95
    }
96
97
    /**
98
     * Show add form for routing
99
     * @throws \Ffcms\Core\Exception\SyntaxException
100
     */
101
    public function actionAddroute()
102
    {
103
        $model = new FormAddRoute();
104
105
        if (!File::exist('/Private/Config/Routing.php') || !File::writable('/Private/Config/Routing.php')) {
106
            App::$Session->getFlashBag()->add('error', __('Routing configuration file is not allowed to write: /Private/Config/Routing.php'));
107
        } elseif ($model->send() && $model->validate()) {
108
            $model->save();
109
            App::$Response->redirect('main/routing');
110
        }
111
112
        return App::$View->render('add_route', [
113
            'model' => $model
114
        ]);
115
    }
116
117
    /**
118
     * Delete scheme route
119
     * @throws SyntaxException
120
     */
121
    public function actionDeleteroute()
122
    {
123
        $type = (string)App::$Request->query->get('type');
124
        $loader = (string)App::$Request->query->get('loader');
125
        $source = Str::lowerCase((string)App::$Request->query->get('path'));
126
127
        $model = new EntityDeleteRoute($type, $loader, $source);
128
        if ($model->send()) {
129
            $model->make();
130
            App::$Response->redirect('main/routing');
131
        }
132
133
        return App::$View->render('delete_route', [
134
            'model' => $model
135
        ]);
136
    }
137
}