Conditions | 14 |
Paths | 96 |
Total Lines | 39 |
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 |
||
71 | function xoops_buildCookieHeader($args) |
||
72 | { |
||
73 | //$optionsKeys = array('expires', 'path', 'domain', 'secure', 'httponly', 'samesite'); |
||
74 | $options = $args['options']; |
||
75 | |||
76 | $header = 'Set-Cookie: ' . $args['name'] . '=' . rawurlencode($args['value']) . ' '; |
||
77 | |||
78 | if (isset($options['expires']) && 0 !== $options['expires']) { |
||
79 | $dateTime = new DateTime(); |
||
80 | if (time() >= $options['expires']) { |
||
81 | $dateTime->setTimestamp(0); |
||
82 | $header = 'Set-Cookie: ' . $args['name'] . '=deleted ; expires=' . $dateTime->format(DateTime::COOKIE) . ' ; Max-Age=0 '; |
||
83 | } else { |
||
84 | $dateTime->setTimestamp($options['expires']); |
||
85 | $header .= '; expires=' . $dateTime->format(DateTime::COOKIE) . ' '; |
||
86 | } |
||
87 | } |
||
88 | |||
89 | if (isset($options['path']) && '' !== $options['path']) { |
||
90 | $header .= '; path=' . $options['path'] . ' '; |
||
91 | } |
||
92 | |||
93 | if (isset($options['domain']) && '' !== $options['domain']) { |
||
94 | $header .= '; domain=' . $options['domain'] . ' '; |
||
95 | } |
||
96 | |||
97 | if (isset($options['secure']) && true === (bool) $options['secure']) { |
||
98 | $header .= '; Secure '; |
||
99 | } |
||
100 | |||
101 | if (isset($options['httponly']) && true === (bool) $options['httponly']) { |
||
102 | $header .= '; HttpOnly '; |
||
103 | } |
||
104 | |||
105 | if (isset($options['samesite']) && '' !== $options['samesite']) { |
||
106 | $header .= '; samesite=' . $options['samesite'] . ' '; |
||
107 | } |
||
108 | |||
109 | return $header; |
||
110 | } |
||
111 |