Passed
Push — main ( 7af4bb...131f20 )
by Rafael
58:13
created

AdminController::index()   F

Complexity

Conditions 18
Paths 1152

Size

Total Lines 134
Code Lines 80

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 18
eloc 80
c 1
b 0
f 0
nc 1152
nop 1
dl 0
loc 134
rs 0.7

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
/* Copyright (C) 2001-2004  Rodolphe Quiedeville    <[email protected]>
4
 * Copyright (C) 2004-2012  Laurent Destailleur     <[email protected]>
5
 * Copyright (C) 2015       Jean-François Ferry	    <[email protected]>
6
 * Copyright (C) 2024       Rafael San José         <[email protected]>
7
 *
8
 * This program is free software; you can redistribute it and/or modify
9
 * it under the terms of the GNU General Public License as published by
10
 * the Free Software Foundation; either version 3 of the License, or
11
 * (at your option) any later version.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU General Public License
19
 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20
 */
21
22
namespace DoliModules\Admin\Controller;
23
24
global $conf;
25
global $db;
26
global $user;
27
global $hookmanager;
28
global $user;
29
global $menumanager;
30
global $langs;
31
global $mysoc;
32
33
34
// Load Dolibarr environment
35
/*
36
require BASE_PATH . '/main.inc.php';
37
require_once BASE_PATH . '/../Dolibarr/Lib/Admin.php';
38
require_once BASE_PATH . '/../Dolibarr/Lib/Company.php';
39
require_once BASE_PATH . '/../Dolibarr/Lib/Date.php';
40
require_once BASE_PATH . '/../Dolibarr/Lib/Images.php';
41
require_once BASE_PATH . '/../Dolibarr/Lib/Files.php';
42
require_once BASE_PATH . '/../Dolibarr/Lib/Functions2.php';
43
*/
44
45
use DoliCore\Base\DolibarrController;
46
47
/**
48
 *      \file       htdocs/admin/index.php
49
 *      \brief      Home page of setup area
50
 */
51
class AdminController extends DolibarrController
52
{
53
    /**
54
     *      \file       htdocs/adherents/type.php
55
     *      \ingroup    member
56
     *      \brief      Member's type setup
57
     */
58
    public function index($executeActions = true): bool
59
    {
60
        global $conf;
61
        global $db;
62
        global $user;
63
        global $hookmanager;
64
        global $user;
65
        global $menumanager;
66
        global $langs;
67
        global $mysoc;
68
69
// Load translation files required by the page
70
        $langs->loadLangs(array('admin', 'companies'));
71
72
        $action = '';
73
74
        if (!$user->admin) {
75
            accessforbidden();
76
        }
77
78
// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
79
        $hookmanager->initHooks(array('homesetup'));
80
81
82
        /*
83
         * View
84
         */
85
86
        $form = new Form($db);
87
88
        $wikihelp = 'EN:First_setup|FR:Premiers_paramétrages|ES:Primeras_configuraciones';
89
        llxHeader('', $langs->trans("Setup"), $wikihelp);
90
91
92
        print load_fiche_titre($langs->trans("SetupArea"), '', 'tools');
93
94
95
        if (getDolGlobalString('MAIN_MOTD_SETUPPAGE')) {
96
            $conf->global->MAIN_MOTD_SETUPPAGE = preg_replace('/<br(\s[\sa-zA-Z_="]*)?\/?>/i', '<br>', $conf->global->MAIN_MOTD_SETUPPAGE);
97
            if (getDolGlobalString('MAIN_MOTD_SETUPPAGE')) {
98
                $i = 0;
99
                $reg = array();
100
                while (preg_match('/__\(([a-zA-Z|@]+)\)__/i', $conf->global->MAIN_MOTD_SETUPPAGE, $reg) && $i < 100) {
101
                    $tmp = explode('|', $reg[1]);
102
                    if (!empty($tmp[1])) {
103
                        $langs->load($tmp[1]);
104
                    }
105
                    $conf->global->MAIN_MOTD_SETUPPAGE = preg_replace('/__\(' . preg_quote($reg[1]) . '\)__/i', $langs->trans($tmp[0]), $conf->global->MAIN_MOTD_SETUPPAGE);
106
                    $i++;
107
                }
108
109
                print "\n<!-- Start of welcome text for setup page -->\n";
110
                print '<table width="100%" class="notopnoleftnoright"><tr><td>';
111
                print dol_htmlentitiesbr($conf->global->MAIN_MOTD_SETUPPAGE);
112
                print '</td></tr></table><br>';
113
                print "\n<!-- End of welcome text for setup page -->\n";
114
            }
115
        }
116
117
        print '<span class="opacitymedium hideonsmartphone">';
118
        print $langs->trans("SetupDescription1") . ' ';
119
        print $langs->trans("AreaForAdminOnly") . ' ';
120
        print $langs->trans("SetupDescription2", $langs->transnoentities("MenuCompanySetup"), $langs->transnoentities("Modules"));
121
        print "<br><br>";
122
        print '</span>';
123
124
        print '<br>';
125
126
// Show info setup company
127
        if (!getDolGlobalString('MAIN_INFO_SOCIETE_NOM') || !getDolGlobalString('MAIN_INFO_SOCIETE_COUNTRY') || getDolGlobalString('MAIN_INFO_SOCIETE_SETUP_TODO_WARNING')) {
128
            $setupcompanynotcomplete = 1;
129
        }
130
131
        print '<section class="setupsection">';
132
133
        print img_picto('', 'company', 'class="paddingright valignmiddle double"') . ' ' . $langs->trans("SetupDescriptionLink", DOL_URL_ROOT . '/admin/company.php?mainmenu=home' . (empty($setupcompanynotcomplete) ? '' : '&action=edit&token=' . newToken()), $langs->transnoentities("Setup"), $langs->transnoentities("MenuCompanySetup"));
134
        print '<br><br>';
135
        print $langs->trans("SetupDescription3b");
136
        if (!empty($setupcompanynotcomplete)) {
137
            $langs->load("errors");
138
            $warnpicto = img_warning($langs->trans("WarningMandatorySetupNotComplete"), 'style="padding-right: 6px;"');
139
            print '<br><div class="warning"><a href="' . DOL_URL_ROOT . '/admin/company.php?mainmenu=home' . (empty($setupcompanynotcomplete) ? '' : '&action=edit') . '">' . $warnpicto . $langs->trans("WarningMandatorySetupNotComplete") . '</a></div>';
140
        }
141
142
        print '</section>';
143
144
        print '<br>';
145
        print '<br>';
146
147
        print '<section class="setupsection">';
148
149
        $nbmodulesnotautoenabled = count($conf->modules);
150
        if (in_array('fckeditor', $conf->modules)) {
151
            $nbmodulesnotautoenabled--;
152
        }
153
        if (in_array('export', $conf->modules)) {
154
            $nbmodulesnotautoenabled--;
155
        }
156
        if (in_array('import', $conf->modules)) {
157
            $nbmodulesnotautoenabled--;
158
        }
159
160
// Show info setup module
161
        print img_picto('', 'cog', 'class="paddingright valignmiddle double"') . ' ' . $langs->trans("SetupDescriptionLink", DOL_URL_ROOT . '/admin/modules.php?mainmenu=home', $langs->transnoentities("Setup"), $langs->transnoentities("Modules"));
162
        print '<br><br>' . $langs->trans("SetupDescription4b");
163
        if ($nbmodulesnotautoenabled <= getDolGlobalInt('MAIN_MIN_NB_ENABLED_MODULE_FOR_WARNING', 1)) { // If only minimal initial modules enabled
164
            $langs->load("errors");
165
            $warnpicto = img_warning($langs->trans("WarningEnableYourModulesApplications"), 'style="padding-right: 6px;"');
166
            print '<br><div class="warning"><a href="' . DOL_URL_ROOT . '/admin/modules.php?mainmenu=home">' . $warnpicto . $langs->trans("WarningEnableYourModulesApplications") . '</a></div>';
167
        }
168
169
        print '</section>';
170
171
        print '<br>';
172
        print '<br>';
173
        print '<br>';
174
175
// Add hook to add information
176
        $parameters = array();
177
        $object = new stdClass();
0 ignored issues
show
Bug introduced by
The type DoliModules\Admin\Controller\stdClass was not found. Did you mean stdClass? If so, make sure to prefix the type with \.
Loading history...
178
        $reshook = $hookmanager->executeHooks('addHomeSetup', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
179
        print $hookmanager->resPrint;
180
        if (empty($reshook)) {
181
            // Show into other
182
            //print '<span class="opacitymedium hideonsmartphone">'.$langs->trans("SetupDescription5")."</span><br>";
183
            print '<br class="hideonsmartphone">';
184
185
            // Show logo
186
            print '<div class="center"><div class="logo_setup"></div></div>';
187
        }
188
189
// End of page
190
        llxFooter();
191
        $db->close();
0 ignored issues
show
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...
192
    }
193
}
194