Test Failed
Push — main ( 8e55b2...88c391 )
by Rafael
10:33
created

Controller::url()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 3
rs 10
1
<?php
2
/**
3
 * Alxarafe. Development of PHP applications in a flash!
4
 * Copyright (C) 2018 Alxarafe <[email protected]>
5
 */
6
7
namespace Alxarafe\Core\Base;
8
9
use Alxarafe\Database\Engine;
10
use Alxarafe\Database\SqlHelper;
11
use DebugBar\DebugBarException;
12
13
/**
14
 * Class Controller
15
 *
16
 * The controller is who responds to the various events.
17
 *
18
 * @package Alxarafe\Core\Base
19
 */
20
abstract class Controller extends BasicController
21
{
22
    /**
23
     * The database engine.
24
     *
25
     * @var Engine
26
     */
27
    public static Engine $engine;
28
29
    /**
30
     * The database SQL Helper.
31
     *
32
     * @var SqlHelper
33
     */
34
    public static SqlHelper $sqlHelper;
35
36
    /**
37
     * It contains an instance of the view class, or null if it is
38
     * not assigned, or does not have an associated view.
39
     *
40
     * @var View
41
     */
42
    public View $view;
43
44
    public function __construct()
45
    {
46
        parent::__construct();
47
48
        $this->hasMenu = true;
49
    }
50
51
    /**
52
     * Initialization of variables required for all controllers
53
     *
54
     * @return bool
55
     * @throws DebugBarException
56
     */
57
    public function preLoad(): bool
58
    {
59
        if (!parent::preLoad() || !$this->configExists) {
60
            die('No existe el archivo de configuración!'); // No tendría que haber llegado aquí, pero sin configuración, no se puede utilizar base de datos.
0 ignored issues
show
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...
Bug Best Practice introduced by
In this branch, the function will implicitly return null which is incompatible with the type-hinted return boolean. 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...
61
        }
62
63
        if (!$this->config->connectToDatabaseAndAuth()) {
64
            return false;
65
        }
66
67
        self::$engine = $this->config->getEngine();
68
        self::$sqlHelper = $this->config->getSqlHelper();
69
70
        $this->action = filter_input(INPUT_POST, 'action', FILTER_DEFAULT);
71
72
        // TODO: This will have to be assigned in a yaml file, when activating and deactivating modules.
73
        $this->translator->addDirs([
74
            constant('BASE_FOLDER') . '/Modules/Main',
75
        ]);
76
77
        return true;
78
    }
79
80
}
81