Conditions | 4 |
Paths | 5 |
Total Lines | 51 |
Code Lines | 20 |
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 |
||
22 | public function start($storagePath = null) |
||
23 | { |
||
24 | if (session_status() === \PHP_SESSION_ACTIVE) { |
||
25 | throw new \ErrorException( |
||
26 | 'Could not start session, already started.' |
||
27 | ); |
||
28 | } |
||
29 | |||
30 | /** |
||
31 | * Set cache limiter. |
||
32 | */ |
||
33 | session_cache_limiter('public, must-revalidate'); |
||
34 | |||
35 | /** |
||
36 | * Set cache expire (minutes). |
||
37 | */ |
||
38 | session_cache_expire($this->setting('expire', '36000') / 60); |
||
39 | |||
40 | /** |
||
41 | * Set garbage collector timeout (seconds). |
||
42 | */ |
||
43 | ini_set('session.gc_maxlifetime', $this->setting('expire', '36000')); |
||
44 | |||
45 | /** |
||
46 | * Set custom session storage path. |
||
47 | */ |
||
48 | if (!empty($storagePath)) { |
||
49 | ini_set('session.save_path', $storagePath); |
||
50 | session_save_path($storagePath); |
||
51 | } |
||
52 | |||
53 | /** |
||
54 | * Make sure garbage collector visits us. |
||
55 | */ |
||
56 | ini_set('session.gc_probability', 1); |
||
57 | |||
58 | session_set_cookie_params( |
||
59 | $this->setting(sprintf('cookie%slifetime', S::DIVIDER), 60 * 60 * 24 * 14), |
||
60 | $this->setting(sprintf('cookie%spath', S::DIVIDER), '/'), |
||
61 | $this->setting(sprintf('cookie%sdomain', S::DIVIDER), ''), |
||
62 | $this->setting(sprintf('cookie%ssecure', S::DIVIDER), false), |
||
63 | $this->setting(sprintf('cookie%shttponly', S::DIVIDER), true) |
||
64 | ); |
||
65 | |||
66 | session_name('webservco'); |
||
67 | |||
68 | if (!session_start()) { |
||
69 | throw new \ErrorException('Failed to start session'); |
||
70 | } |
||
71 | |||
72 | return true; |
||
73 | } |
||
109 |