Controller   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 9
dl 0
loc 29
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 13 5
1
<?php
2
3
/* Copyright (C) 2024      Rafael San José      <[email protected]>
4
 *
5
 * This program is free software; you can redistribute it and/or modify
6
 * it under the terms of the GNU General Public License as published by
7
 * the Free Software Foundation; either version 3 of the License, or
8
 * any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program. If not, see <https://www.gnu.org/licenses/>.
17
 */
18
19
namespace Alxarafe\Base\Controller;
20
21
use Alxarafe\Base\Controller\Trait\DbTrait;
22
use Alxarafe\Lib\Auth;
23
use Alxarafe\Lib\Functions;
24
use CoreModules\Admin\Controller\AuthController;
25
use CoreModules\Admin\Controller\ConfigController;
26
27
/**
28
 * Class Controller. Controller is the general purpose controller and requires the user to be authenticated.
29
 *
30
 * @package Alxarafe\Base
31
 */
32
abstract class Controller extends ViewController
33
{
34
    use DbTrait;
35
36
    /**
37
     * Name of the user
38
     *
39
     * @var string
40
     */
41
    public $username;
42
43
    /**
44
     * Controller constructor.
45
     *
46
     * @throws \DebugBar\DebugBarException
47
     */
48
    public function __construct()
49
    {
50
        parent::__construct();
51
52
        if (!isset($this->config->db) || !static::connectDb($this->config->db)) {
53
            Functions::httpRedirect(ConfigController::url());
54
        }
55
56
        if (!Auth::isLogged() && static::class !== 'CoreModules\Admin\Controller\AuthController') {
57
            Functions::httpRedirect(AuthController::url());
58
        }
59
60
        $this->username = Auth::$user->name ?? null;
0 ignored issues
show
Bug introduced by
The property name does not seem to exist on CoreModules\Admin\Model\User. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
61
    }
62
}
63