Passed
Push — master ( c6150b...ef80b0 )
by Mihail
05:01
created

ActionAddRoute::addRoute()   A

Complexity

Conditions 5
Paths 3

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 8
nc 3
nop 0
dl 0
loc 13
rs 9.6111
c 0
b 0
f 0
1
<?php
2
3
namespace Apps\Controller\Admin\Main;
4
5
6
use Apps\Model\Admin\Main\FormAddRoute;
7
use Ffcms\Core\App;
8
use Ffcms\Core\Arch\View;
9
use Ffcms\Core\Helper\FileSystem\File;
10
use Ffcms\Core\Network\Request;
11
use Ffcms\Core\Network\Response;
12
13
/**
14
 * Trait ActionAddRoute
15
 * @package Apps\Controller\Admin\Main
16
 * @property Request $request
17
 * @property Response $response
18
 * @property View $view
19
 */
20
trait ActionAddRoute
21
{
22
    /**
23
     * Route add form action
24
     * @return string|null
25
     * @throws \Ffcms\Core\Exception\SyntaxException
26
     */
27
    public function addRoute(): ?string
28
    {
29
        $model = new FormAddRoute(true);
30
31
        if (!File::exist('/Private/Config/Routing.php') || !File::writable('/Private/Config/Routing.php')) {
32
            App::$Session->getFlashBag()->add('error', __('Routing configuration file is not allowed to write: /Private/Config/Routing.php'));
33
        } elseif ($model->send() && $model->validate()) {
34
            $model->save();
35
            return $this->view->render('main/add_route_save');
36
        }
37
38
        return $this->view->render('main/add_route', [
39
            'model' => $model
40
        ]);
41
    }
42
}