| Conditions | 10 |
| Paths | 17 |
| Total Lines | 43 |
| Code Lines | 24 |
| 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 |
||
| 35 | private function initSession() |
||
| 36 | { |
||
| 37 | global $opt; |
||
| 38 | |||
| 39 | if ($this->session_initialized !== true) { |
||
| 40 | session_name('SESSION'); |
||
| 41 | session_set_cookie_params( |
||
| 42 | $opt['session']['expire']['cookie'], |
||
| 43 | $opt['session']['path'], |
||
| 44 | $opt['session']['domain'] |
||
| 45 | ); |
||
| 46 | session_start(); |
||
| 47 | |||
| 48 | if ($opt['session']['check_referer']) { |
||
| 49 | if (isset($_SERVER['REFERER'])) { |
||
| 50 | // TODO fix the following if statement, seems corrupted |
||
| 51 | if (strtolower( |
||
| 52 | substr( |
||
| 53 | 'http' + strstr($_SERVER['REFERER'], '://'), |
||
| 54 | 0, |
||
| 55 | strlen($opt['page']['absolute_http_url']) |
||
| 56 | ) |
||
| 57 | ) != strtolower($opt['page']['absolute_http_url']) |
||
| 58 | ) { |
||
| 59 | $this->createNewSession(); |
||
| 60 | } |
||
| 61 | } |
||
| 62 | } |
||
| 63 | |||
| 64 | if ((isset($_GET['SESSION']) || isset($_POST['SESSION'])) && count($_SESSION) > 0) { |
||
| 65 | // compare and set timestamp |
||
| 66 | if (isset($_SESSION['lastcall'])) { |
||
| 67 | if (abs(time() - $_SESSION['lastcall']) > $opt['session']['expire']['url']) { |
||
| 68 | $this->createNewSession(); |
||
| 69 | } |
||
| 70 | } |
||
| 71 | |||
| 72 | $_SESSION['lastcall'] = time(); |
||
| 73 | } |
||
| 74 | |||
| 75 | $this->session_initialized = true; |
||
| 76 | } |
||
| 77 | } |
||
| 78 | |||
| 173 |
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: