Test Failed
Push — main ( fac5ed...59bfee )
by Rafael
50:50
created

DolibarrGenericController   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 17
c 1
b 0
f 0
dl 0
loc 46
rs 10
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 11 3
A url() 0 12 2
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 DoliCore\Base;
20
21
/**
22
 * Class DolibarrGenericController. The generic controller contains what is necessary for any controller
23
 *
24
 * This class is only needed for compatibility with Dolibarr.
25
 *
26
 * @package DoliCore\Base
27
 */
28
abstract class DolibarrGenericController
29
{
30
    /**
31
     * Contains the controller to execute.
32
     *
33
     * @var string
34
     */
35
    protected $controller;
36
37
    /**
38
     * Contains the action to execute.
39
     *
40
     * @var string
41
     */
42
    protected $action;
43
44
    /**
45
     * GenericController constructor.
46
     */
47
    public function __construct()
48
    {
49
        $this->controller = filter_input(INPUT_GET, GET_FILENAME_VAR);
50
        $this->action = filter_input(INPUT_GET, 'action');
51
        if (empty($this->controller)) {
52
            $this->controller = 'index';
53
        }
54
        if (method_exists($this, $this->controller)) {
55
            return $this->{$this->controller}();
56
        }
57
        return $this->index();
58
    }
59
60
    abstract public function index();
61
62
    public static function url($full = false)
63
    {
64
        $url = '';
65
        if ($full) {
66
            $url .= BASE_URL . '/index.php';
67
        }
68
69
        $url .=
70
            '?' . GET_ROUTE_VAR . '=' . filter_input(INPUT_GET, GET_ROUTE_VAR) .
71
            '&' . GET_FILENAME_VAR . '=' . filter_input(INPUT_GET, GET_FILENAME_VAR);
72
73
        return $url;
74
    }
75
}
76