Conditions | 4 |
Paths | 4 |
Total Lines | 51 |
Code Lines | 20 |
Lines | 0 |
Ratio | 0 % |
Changes | 3 | ||
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 |
||
119 | public function start(string $storagePath = ''): bool |
||
120 | { |
||
121 | if (\WebServCo\Framework\Helpers\PhpHelper::isCli()) { |
||
122 | throw new SessionException('Not starting session in CLI mode.'); |
||
123 | } |
||
124 | |||
125 | if (\PHP_SESSION_ACTIVE === \session_status()) { |
||
126 | throw new SessionException('Unable to start session: already started.'); |
||
127 | } |
||
128 | |||
129 | /** |
||
130 | * Set cache limiter. |
||
131 | */ |
||
132 | \session_cache_limiter('public, must-revalidate'); |
||
133 | |||
134 | /** |
||
135 | * Set cache expire (minutes). |
||
136 | */ |
||
137 | \session_cache_expire($this->setting('expire', '36000') / 60); |
||
138 | |||
139 | /** |
||
140 | * Set garbage collector timeout (seconds). |
||
141 | */ |
||
142 | \ini_set('session.gc_maxlifetime', (string) $this->setting('expire', '36000')); |
||
143 | |||
144 | /** |
||
145 | * Set custom session storage path. |
||
146 | */ |
||
147 | $this->setStoragePath($storagePath); |
||
148 | |||
149 | /** |
||
150 | * Make sure garbage collector visits us. |
||
151 | */ |
||
152 | \ini_set('session.gc_probability', '1'); |
||
153 | |||
154 | \session_set_cookie_params([ |
||
155 | 'domain' => $this->setting(\sprintf('cookie%sdomain', Settings::DIVIDER), ''), |
||
156 | 'httponly' => $this->setting(\sprintf('cookie%shttponly', Settings::DIVIDER), true), |
||
157 | 'lifetime' => $this->setting(\sprintf('cookie%slifetime', Settings::DIVIDER), 60 * 60 * 24 * 14), |
||
158 | 'path' => $this->setting(\sprintf('cookie%spath', Settings::DIVIDER), '/'), |
||
159 | 'samesite' => $this->setting(\sprintf('cookie%ssamesite', Settings::DIVIDER), 'Lax'), |
||
160 | 'secure' => $this->setting(\sprintf('cookie%ssecure', Settings::DIVIDER), true), |
||
161 | ]); |
||
162 | |||
163 | \session_name('webservco'); |
||
164 | |||
165 | if (!\session_start()) { |
||
166 | throw new SessionException('Unable to start session.'); |
||
167 | } |
||
168 | |||
169 | return true; |
||
170 | } |
||
197 |