| Conditions | 10 |
| Paths | 25 |
| Total Lines | 38 |
| Code Lines | 21 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 |
||
| 26 | function xoops_setcookie() |
||
| 27 | { |
||
| 28 | if (headers_sent()) { |
||
| 29 | return false; |
||
| 30 | } |
||
| 31 | $argNames = array('name', 'value', 'expires', 'path', 'domain', 'secure', 'httponly'); |
||
| 32 | //$argDefaults = array(null, '', 0, '', '', false, false); |
||
| 33 | //$optionsKeys = array('expires', 'path', 'domain', 'secure', 'httponly', 'samesite'); |
||
| 34 | $rawArgs = func_get_args(); |
||
| 35 | $args = array(); |
||
| 36 | foreach ($rawArgs as $key => $value) { |
||
| 37 | if (2 === $key && is_array($value)) { |
||
| 38 | // modern call |
||
| 39 | $args['options'] = array(); |
||
| 40 | foreach ($value as $optionKey => $optionValue) { |
||
| 41 | $args['options'][strtolower($optionKey)] = $optionValue; |
||
| 42 | } |
||
| 43 | break; |
||
| 44 | } |
||
| 45 | if ($key>1) { |
||
| 46 | if (null !== $value) { |
||
| 47 | $args['options'][$argNames[$key]] = $value; |
||
| 48 | } |
||
| 49 | } else { |
||
| 50 | $args[$argNames[$key]] = $value; |
||
| 51 | } |
||
| 52 | } |
||
| 53 | |||
| 54 | // make samesite=strict the default |
||
| 55 | $args['options']['samesite'] = isset($args['options']['samesite']) ? $args['options']['samesite'] : 'strict'; |
||
| 56 | |||
| 57 | // after php 7.3 we just let php do it |
||
| 58 | if (PHP_VERSION_ID >= 70300) { |
||
| 59 | return setcookie($args['name'], $args['value'], $args['options']); |
||
| 60 | } |
||
| 61 | // render and send our own headers below php 7.3 |
||
| 62 | header(xoops_buildCookieHeader($args), false); |
||
| 63 | return true; |
||
| 64 | } |
||
| 111 |