GeneratorController   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 4
Bugs 0 Features 0
Metric Value
eloc 26
c 4
b 0
f 0
dl 0
loc 56
ccs 0
cts 26
cp 0
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A generateModule() 0 8 1
A doGenerateModule() 0 23 3
1
<?php
2
3
namespace PSFS\controller;
4
5
use Exception;
6
use PSFS\base\config\ConfigForm;
7
use PSFS\base\config\ModuleForm;
8
use PSFS\base\exception\FormException;
9
use PSFS\base\Logger;
10
use PSFS\base\Security;
11
use PSFS\base\types\helpers\GeneratorHelper;
12
use PSFS\controller\base\Admin;
13
14
/**
15
 * Class GeneratorController
16
 * @package PSFS\controller
17
 * @domain ROOT
18
 */
19
class GeneratorController extends Admin
20
{
21
    /**
22
     * @Injectable
23
     * @var \PSFS\services\GeneratorService Servicio de generación de estructura de directorios
24
     */
25
    protected $gen;
26
27
    /**
28
     * @label Método que genera un nuevo módulo
29
     * @GET
30
     * @route /admin/module
31
     * @icon fa-layer-plus
32
     * @return string
33
     * @throws FormException
34
     */
35
    public function generateModule()
36
    {
37
        Logger::log("Arranque generador de módulos al solicitar " . $this->getRequest()->getRequestUri());
38
        /* @var $form ConfigForm */
39
        $form = new ModuleForm();
40
        $form->build();
41
        return $this->render("modules.html.twig", array(
42
            'form' => $form,
43
        ));
44
    }
45
46
    /**
47
     * @POST
48
     * @route /admin/module
49
     * @label Generador de módulos
50
     * @return string
51
     */
52
    public function doGenerateModule()
53
    {
54
        $form = new ModuleForm();
55
        $form->build();
56
        $form->hydrate();
57
        if ($form->isValid()) {
58
            $module = strtoupper($form->getFieldValue("module"));
0 ignored issues
show
Bug introduced by
It seems like $form->getFieldValue('module') can also be of type null; however, parameter $string of strtoupper() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

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

58
            $module = strtoupper(/** @scrutinizer ignore-type */ $form->getFieldValue("module"));
Loading history...
59
            $type = preg_replace('/normal/i', '', $form->getFieldValue("controllerType"));
60
            $apiClass = $form->getFieldValue("api");
61
            try {
62
                $module = preg_replace('/(\\\|\/)/', '/', $module);
63
                $module = preg_replace('/^\//', '', $module);
64
                GeneratorHelper::checkCustomNamespaceApi($apiClass);
65
                $this->gen->createStructureModule($module, false, $type, $apiClass);
0 ignored issues
show
Bug introduced by
It seems like $apiClass can also be of type null; however, parameter $apiClass of PSFS\services\GeneratorS...createStructureModule() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

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

65
                $this->gen->createStructureModule($module, false, $type, /** @scrutinizer ignore-type */ $apiClass);
Loading history...
66
                Security::getInstance()->setFlash("callback_message", str_replace("%s", $module, t("Módulo %s generado correctamente")));
67
                Security::getInstance()->setFlash("callback_route", $this->getRoute("admin-module", true));
68
            } catch (Exception $e) {
69
                Logger::log($e->getMessage() . " [" . $e->getFile() . ":" . $e->getLine() . "]");
70
                Security::getInstance()->setFlash("callback_message", htmlentities($e->getMessage()));
71
            }
72
        }
73
        return $this->render("modules.html.twig", array(
74
            'form' => $form,
75
        ));
76
    }
77
78
}
79