Conditions | 5 |
Paths | 6 |
Total Lines | 67 |
Code Lines | 32 |
Lines | 0 |
Ratio | 0 % |
Changes | 5 | ||
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 |
||
95 | public function start($storagePath = null) |
||
96 | { |
||
97 | if (\WebServCo\Framework\Framework::isCli()) { |
||
98 | throw new SessionException('Not starting session in CLI mode.'); |
||
99 | } |
||
100 | |||
101 | if (session_status() === \PHP_SESSION_ACTIVE) { |
||
102 | throw new SessionException( |
||
103 | 'Unable to start session: already started.' |
||
104 | ); |
||
105 | } |
||
106 | |||
107 | /** |
||
108 | * Set cache limiter. |
||
109 | */ |
||
110 | session_cache_limiter('public, must-revalidate'); |
||
111 | |||
112 | /** |
||
113 | * Set cache expire (minutes). |
||
114 | */ |
||
115 | session_cache_expire($this->setting('expire', '36000') / 60); |
||
116 | |||
117 | /** |
||
118 | * Set garbage collector timeout (seconds). |
||
119 | */ |
||
120 | ini_set('session.gc_maxlifetime', $this->setting('expire', '36000')); |
||
121 | |||
122 | /** |
||
123 | * Set custom session storage path. |
||
124 | */ |
||
125 | $this->setStoragePath($storagePath); |
||
126 | |||
127 | /** |
||
128 | * Make sure garbage collector visits us. |
||
129 | */ |
||
130 | ini_set('session.gc_probability', '1'); |
||
131 | |||
132 | if (PHP_VERSION_ID < 70300) { |
||
133 | session_set_cookie_params( |
||
134 | $this->setting(sprintf('cookie%slifetime', Settings::DIVIDER), 60 * 60 * 24 * 14), |
||
135 | sprintf( |
||
136 | '%s; SameSite=%s', |
||
137 | $this->setting(sprintf('cookie%spath', Settings::DIVIDER), '/'), |
||
138 | $this->setting(sprintf('cookie%ssamesite', Settings::DIVIDER), 'Lax') |
||
139 | ), |
||
140 | $this->setting(sprintf('cookie%sdomain', Settings::DIVIDER), ''), |
||
141 | $this->setting(sprintf('cookie%ssecure', Settings::DIVIDER), true), |
||
142 | $this->setting(sprintf('cookie%shttponly', Settings::DIVIDER), true) |
||
143 | ); |
||
144 | } else { |
||
145 | session_set_cookie_params([ |
||
146 | 'lifetime' => $this->setting(sprintf('cookie%slifetime', Settings::DIVIDER), 60 * 60 * 24 * 14), |
||
147 | 'path' => $this->setting(sprintf('cookie%spath', Settings::DIVIDER), '/'), |
||
148 | 'domain' => $this->setting(sprintf('cookie%sdomain', Settings::DIVIDER), ''), |
||
149 | 'secure' => $this->setting(sprintf('cookie%ssecure', Settings::DIVIDER), true), |
||
150 | 'httponly' => $this->setting(sprintf('cookie%shttponly', Settings::DIVIDER), true), |
||
151 | 'samesite' => $this->setting(sprintf('cookie%ssamesite', Settings::DIVIDER), 'Lax'), |
||
152 | ]); |
||
153 | } |
||
154 | |||
155 | session_name('webservco'); |
||
156 | |||
157 | if (!session_start()) { |
||
158 | throw new SessionException('Unable to start session.'); |
||
159 | } |
||
160 | |||
161 | return true; |
||
162 | } |
||
194 |