| Conditions | 20 |
| Paths | 144 |
| Total Lines | 97 |
| Code Lines | 51 |
| Lines | 18 |
| Ratio | 18.56 % |
| 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 |
||
| 24 | protected function init() |
||
| 25 | { |
||
| 26 | global $PHP_SELF, $currencies, $messageStack, $oscTemplate, $breadcrumb; |
||
| 27 | |||
| 28 | $OSCOM_Cookies = new Cookies(); |
||
| 29 | Registry::set('Cookies', $OSCOM_Cookies); |
||
| 30 | |||
| 31 | Registry::set('Cache', new Cache()); |
||
| 32 | |||
| 33 | $OSCOM_Db = Db::initialize(); |
||
| 34 | Registry::set('Db', $OSCOM_Db); |
||
| 35 | |||
| 36 | Registry::set('Hooks', new Hooks()); |
||
| 37 | |||
| 38 | Registry::set('Language', new Language()); |
||
| 39 | |||
| 40 | // set the application parameters |
||
| 41 | $Qcfg = $OSCOM_Db->get('configuration', [ |
||
| 42 | 'configuration_key as k', |
||
| 43 | 'configuration_value as v' |
||
| 44 | ]);//, null, null, null, 'configuration'); // TODO add cache when supported by admin |
||
| 45 | |||
| 46 | while ($Qcfg->fetch()) { |
||
| 47 | define($Qcfg->value('k'), $Qcfg->value('v')); |
||
| 48 | } |
||
| 49 | |||
| 50 | // set php_self in the global scope |
||
| 51 | $req = parse_url($_SERVER['SCRIPT_NAME']); |
||
| 52 | $PHP_SELF = substr($req['path'], strlen(OSCOM::getConfig('http_path', 'Shop'))); |
||
| 53 | |||
| 54 | $OSCOM_Session = Session::load(); |
||
| 55 | Registry::set('Session', $OSCOM_Session); |
||
| 56 | |||
| 57 | // start the session |
||
| 58 | $OSCOM_Session->start(); |
||
| 59 | |||
| 60 | $this->ignored_actions[] = session_name(); |
||
|
|
|||
| 61 | |||
| 62 | // create the shopping cart |
||
| 63 | View Code Duplication | if (!isset($_SESSION['cart']) || !is_object($_SESSION['cart']) || (get_class($_SESSION['cart']) != 'shoppingCart')) { |
|
| 64 | $_SESSION['cart'] = new \shoppingCart(); |
||
| 65 | } |
||
| 66 | |||
| 67 | // include currencies class and create an instance |
||
| 68 | $currencies = new \currencies(); |
||
| 69 | |||
| 70 | // set the language |
||
| 71 | View Code Duplication | if (!isset($_SESSION['language']) || isset($_GET['language'])) { |
|
| 72 | $lng = new \language(); |
||
| 73 | |||
| 74 | if (isset($_GET['language']) && !empty($_GET['language'])) { |
||
| 75 | $lng->set_language($_GET['language']); |
||
| 76 | } else { |
||
| 77 | $lng->get_browser_language(); |
||
| 78 | } |
||
| 79 | |||
| 80 | $_SESSION['language'] = $lng->language['directory']; |
||
| 81 | $_SESSION['languages_id'] = $lng->language['id']; |
||
| 82 | } |
||
| 83 | |||
| 84 | // include the language translations |
||
| 85 | $system_locale_numeric = setlocale(LC_NUMERIC, 0); |
||
| 86 | include(OSCOM::getConfig('dir_root') . 'includes/languages/' . $_SESSION['language'] . '.php'); |
||
| 87 | setlocale(LC_NUMERIC, $system_locale_numeric); // Prevent LC_ALL from setting LC_NUMERIC to a locale with 1,0 float/decimal values instead of 1.0 (see bug #634) |
||
| 88 | |||
| 89 | // currency |
||
| 90 | if (!isset($_SESSION['currency']) || isset($_GET['currency']) || ((USE_DEFAULT_LANGUAGE_CURRENCY == 'true') && (LANGUAGE_CURRENCY != $_SESSION['currency']))) { |
||
| 91 | if (isset($_GET['currency']) && $currencies->is_set($_GET['currency'])) { |
||
| 92 | $_SESSION['currency'] = $_GET['currency']; |
||
| 93 | } else { |
||
| 94 | $_SESSION['currency'] = ((USE_DEFAULT_LANGUAGE_CURRENCY == 'true') && $currencies->is_set(LANGUAGE_CURRENCY)) ? LANGUAGE_CURRENCY : DEFAULT_CURRENCY; |
||
| 95 | } |
||
| 96 | } |
||
| 97 | |||
| 98 | // navigation history |
||
| 99 | View Code Duplication | if (!isset($_SESSION['navigation']) || !is_object($_SESSION['navigation']) || (get_class($_SESSION['navigation']) != 'navigationHistory')) { |
|
| 100 | $_SESSION['navigation'] = new \navigationHistory(); |
||
| 101 | } |
||
| 102 | |||
| 103 | $_SESSION['navigation']->add_current_page(); |
||
| 104 | |||
| 105 | $messageStack = new \messageStack(); |
||
| 106 | |||
| 107 | tep_update_whos_online(); |
||
| 108 | |||
| 109 | tep_activate_banners(); |
||
| 110 | tep_expire_banners(); |
||
| 111 | |||
| 112 | tep_expire_specials(); |
||
| 113 | |||
| 114 | $oscTemplate = new \oscTemplate(); |
||
| 115 | |||
| 116 | $breadcrumb = new \breadcrumb(); |
||
| 117 | |||
| 118 | $breadcrumb->add(HEADER_TITLE_TOP, OSCOM::getConfig('http_server', 'Shop')); |
||
| 119 | $breadcrumb->add(HEADER_TITLE_CATALOG, OSCOM::link('index.php')); |
||
| 120 | } |
||
| 121 | |||
| 192 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: