Conditions | 10 |
Paths | 73 |
Total Lines | 25 |
Code Lines | 19 |
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 |
||
43 | function startCMSSession() |
||
44 | { |
||
45 | global $site_sessionname, $https_port, $session_cookie_path, $session_cookie_domain; |
||
46 | if(MODX_CLI) return; |
||
47 | |||
48 | session_name($site_sessionname); |
||
49 | removeInvalidCmsSessionIds($site_sessionname); |
||
50 | $cookieExpiration = 0; |
||
51 | $secure = ((isset ($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on') || $_SERVER['SERVER_PORT'] == $https_port); |
||
52 | $cookiePath = !empty($session_cookie_path) ? $session_cookie_path : MODX_BASE_URL; |
||
53 | $cookieDomain = !empty($session_cookie_domain) ? $session_cookie_domain : ''; |
||
54 | session_set_cookie_params($cookieExpiration, $cookiePath, $cookieDomain, $secure, true); |
||
55 | session_start(); |
||
56 | $key = "modx.mgr.session.cookie.lifetime"; |
||
57 | if (isset($_SESSION[$key]) && is_numeric($_SESSION[$key])) { |
||
58 | $cookieLifetime = (int)$_SESSION[$key]; |
||
59 | if ($cookieLifetime) { |
||
60 | $cookieExpiration = $_SERVER['REQUEST_TIME'] + $cookieLifetime; |
||
61 | } |
||
62 | setcookie(session_name(), session_id(), $cookieExpiration, $cookiePath, $cookieDomain, $secure, true); |
||
63 | } |
||
64 | if (!isset($_SESSION['modx.session.created.time'])) { |
||
65 | $_SESSION['modx.session.created.time'] = $_SERVER['REQUEST_TIME']; |
||
66 | } |
||
67 | } |
||
68 | |||
94 |
Instead of relying on
global
state, we recommend one of these alternatives:1. Pass all data via parameters
2. Create a class that maintains your state