| Conditions | 11 |
| Paths | 8 |
| Total Lines | 30 |
| Code Lines | 16 |
| Lines | 8 |
| Ratio | 26.67 % |
| 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 |
||
| 19 | function global_url_handler($hook, $type, $returnvalue, $params) { |
||
| 20 | |||
| 21 | // checks to make sure that the url does not affect the ajax calls |
||
| 22 | if (strpos($_SERVER['PHP_SELF'], 'ajax') !== false) return; |
||
| 23 | |||
| 24 | if (strpos($_SERVER['PHP_SELF'], '/view') !== false || strpos($_SERVER['PHP_SELF'], '/profile') !== false) { |
||
| 25 | |||
| 26 | if ($_GET["language"] == 'fr') { |
||
| 27 | View Code Duplication | if ($_COOKIE['connex_lang'] != 'fr') { |
|
| 28 | setcookie('connex_lang', 'fr', 0, '/'); |
||
| 29 | Header('Location: '.$_SERVER['PHP_SELF']); |
||
| 30 | } |
||
| 31 | } elseif ($_GET["language"] == 'en') { |
||
| 32 | View Code Duplication | if ($_COOKIE['connex_lang'] != 'en') { |
|
| 33 | setcookie('connex_lang', 'en', 0, '/'); |
||
| 34 | Header('Location: '.$_SERVER['PHP_SELF']); |
||
| 35 | } |
||
| 36 | } else { |
||
| 37 | if ($_GET["language"] == '' || $_GET["language"] != 'en' || $_GET["language"] != 'fr' ) { |
||
| 38 | |||
| 39 | forward("?language=" . get_current_language()); |
||
| 40 | } |
||
| 41 | } |
||
| 42 | |||
| 43 | } else { |
||
| 44 | |||
| 45 | return; |
||
| 46 | } |
||
| 47 | |||
| 48 | } |
||
| 49 | |||
| 51 |
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: