Conditions | 29 |
Paths | 1370 |
Total Lines | 118 |
Code Lines | 62 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
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:
If many parameters/temporary variables are present:
1 | <?php |
||
25 | protected function init() |
||
26 | { |
||
27 | global $PHP_SELF, $login_request, $cfgModules, $oscTemplate; |
||
28 | |||
29 | $OSCOM_Cookies = new Cookies(); |
||
30 | Registry::set('Cookies', $OSCOM_Cookies); |
||
31 | |||
32 | try { |
||
33 | $OSCOM_Db = Db::initialize(); |
||
34 | Registry::set('Db', $OSCOM_Db); |
||
35 | } catch (\Exception $e) { |
||
36 | include(OSCOM::getConfig('dir_root', 'Shop') . 'includes/error_documents/maintenance.php'); |
||
37 | exit; |
||
38 | } |
||
39 | |||
40 | Registry::set('Hooks', new Hooks()); |
||
41 | |||
42 | Registry::set('MessageStack', new MessageStack()); |
||
43 | |||
44 | // set the application parameters |
||
45 | $Qcfg = $OSCOM_Db->get('configuration', [ |
||
46 | 'configuration_key as k', |
||
47 | 'configuration_value as v' |
||
48 | ]);//, null, null, null, 'configuration'); // TODO add cache when supported by admin |
||
49 | |||
50 | while ($Qcfg->fetch()) { |
||
51 | define($Qcfg->value('k'), $Qcfg->value('v')); |
||
52 | } |
||
53 | |||
54 | // Used in the "Backup Manager" to compress backups |
||
55 | define('LOCAL_EXE_GZIP', 'gzip'); |
||
56 | define('LOCAL_EXE_GUNZIP', 'gunzip'); |
||
57 | define('LOCAL_EXE_ZIP', 'zip'); |
||
58 | define('LOCAL_EXE_UNZIP', 'unzip'); |
||
59 | |||
60 | // set php_self in the global scope |
||
61 | $req = parse_url($_SERVER['SCRIPT_NAME']); |
||
62 | $PHP_SELF = substr($req['path'], strlen(OSCOM::getConfig('http_path'))); |
||
63 | |||
64 | $OSCOM_Session = Session::load(); |
||
65 | Registry::set('Session', $OSCOM_Session); |
||
66 | |||
67 | $OSCOM_Session->start(); |
||
68 | |||
69 | $OSCOM_Language = new Language(); |
||
70 | Registry::set('Language', $OSCOM_Language); |
||
71 | |||
72 | // set the language |
||
73 | if (!isset($_SESSION['language']) || isset($_GET['language'])) { |
||
74 | if (isset($_GET['language']) && !empty($_GET['language']) && $OSCOM_Language->exists($_GET['language'])) { |
||
75 | $OSCOM_Language->set($_GET['language']); |
||
76 | } |
||
77 | |||
78 | $_SESSION['language'] = $OSCOM_Language->get('code'); |
||
79 | } |
||
80 | |||
81 | // redirect to login page if administrator is not yet logged in |
||
82 | if (!isset($_SESSION['admin'])) { |
||
83 | $redirect = false; |
||
84 | |||
85 | $current_page = $PHP_SELF; |
||
86 | |||
87 | // if the first page request is to the login page, set the current page to the index page |
||
88 | // so the redirection on a successful login is not made to the login page again |
||
89 | if (($current_page == FILENAME_LOGIN) && !isset($_SESSION['redirect_origin'])) { |
||
90 | $current_page = FILENAME_DEFAULT; |
||
91 | } |
||
92 | |||
93 | if ($current_page != FILENAME_LOGIN) { |
||
94 | if (!isset($_SESSION['redirect_origin'])) { |
||
95 | $_SESSION['redirect_origin'] = [ |
||
96 | 'page' => $current_page, |
||
97 | 'get' => [] |
||
98 | ]; |
||
99 | } |
||
100 | |||
101 | // try to automatically login with the HTTP Authentication values if it exists |
||
102 | if (!isset($_SESSION['auth_ignore'])) { |
||
103 | if (isset($_SERVER['PHP_AUTH_USER']) && !empty($_SERVER['PHP_AUTH_USER']) && isset($_SERVER['PHP_AUTH_PW']) && !empty($_SERVER['PHP_AUTH_PW'])) { |
||
104 | $_SESSION['redirect_origin']['auth_user'] = $_SERVER['PHP_AUTH_USER']; |
||
105 | $_SESSION['redirect_origin']['auth_pw'] = $_SERVER['PHP_AUTH_PW']; |
||
106 | } |
||
107 | } |
||
108 | |||
109 | $redirect = true; |
||
110 | } |
||
111 | |||
112 | if (!isset($login_request) || isset($_GET['login_request']) || isset($_POST['login_request']) || isset($_COOKIE['login_request']) || isset($_SESSION['login_request']) || isset($_FILES['login_request']) || isset($_SERVER['login_request'])) { |
||
113 | $redirect = true; |
||
114 | } |
||
115 | |||
116 | if ($redirect == true) { |
||
|
|||
117 | OSCOM::redirect(FILENAME_LOGIN, (isset($_SESSION['redirect_origin']['auth_user']) ? 'action=process' : '')); |
||
118 | } |
||
119 | } |
||
120 | |||
121 | // include the language translations |
||
122 | $OSCOM_Language->loadDefinitions('main'); |
||
123 | |||
124 | // Prevent LC_ALL from setting LC_NUMERIC to a locale with 1,0 float/decimal values instead of 1.0 (see bug #634) |
||
125 | $system_locale_numeric = setlocale(LC_NUMERIC, 0); |
||
126 | setlocale(LC_ALL, explode(';', OSCOM::getDef('system_locale'))); |
||
127 | setlocale(LC_NUMERIC, $system_locale_numeric); |
||
128 | |||
129 | $current_page = basename($PHP_SELF); |
||
130 | |||
131 | if ($OSCOM_Language->definitionsExist(pathinfo($current_page, PATHINFO_FILENAME))) { |
||
132 | $OSCOM_Language->loadDefinitions(pathinfo($current_page, PATHINFO_FILENAME)); |
||
133 | } |
||
134 | |||
135 | $oscTemplate = new \oscTemplate(); |
||
136 | |||
137 | $cfgModules = new \cfg_modules(); |
||
138 | |||
139 | if (!FileSystem::isWritable(ErrorHandler::getDirectory())) { |
||
140 | Registry::get('MessageStack')->add('The log directory is not writable. Please allow the web server to write to: ' . FileSystem::displayPath(ErrorHandler::getDirectory())); |
||
141 | } |
||
142 | } |
||
143 | |||
194 |
When comparing two booleans, it is generally considered safer to use the strict comparison operator.