Total Complexity | 9 |
Total Lines | 89 |
Duplicated Lines | 0 % |
Coverage | 95.83% |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
17 | class Cookie |
||
18 | { |
||
19 | /** |
||
20 | * Cookie constructor. |
||
21 | */ |
||
22 | 4 | public function __construct() |
|
23 | { |
||
24 | 4 | } |
|
25 | |||
26 | /** |
||
27 | * Set a cookie |
||
28 | * |
||
29 | * @param array $data |
||
30 | * @param string $name |
||
31 | * |
||
32 | * @return boolean |
||
33 | */ |
||
34 | 4 | public function set($data, $name = 'openimporter_cookie') |
|
35 | { |
||
36 | 4 | if (!empty($data)) |
|
37 | { |
||
38 | 4 | setcookie($name, serialize($data), time()+ 86400); |
|
39 | 4 | $_COOKIE[$name] = serialize($data); |
|
40 | |||
41 | 4 | return true; |
|
42 | } |
||
43 | |||
44 | 1 | return false; |
|
45 | } |
||
46 | |||
47 | /** |
||
48 | * Get our cookie |
||
49 | * |
||
50 | * @param string $name |
||
51 | * |
||
52 | * @return boolean |
||
53 | */ |
||
54 | 2 | public function get($name = 'openimporter_cookie') |
|
55 | { |
||
56 | 2 | if (isset($_COOKIE[$name])) |
|
57 | { |
||
58 | 2 | return unserialize($_COOKIE[$name], array('allowed_classes' => false)); |
|
59 | } |
||
60 | |||
61 | 1 | return false; |
|
62 | } |
||
63 | |||
64 | /** |
||
65 | * Once we are done, we should destroy our cookie |
||
66 | * |
||
67 | * @param string $name |
||
68 | * |
||
69 | * @return boolean |
||
70 | */ |
||
71 | 1 | public function destroy($name = 'openimporter_cookie') |
|
72 | { |
||
73 | 1 | setcookie($name, ''); |
|
74 | 1 | unset($_COOKIE[$name]); |
|
75 | |||
76 | 1 | return true; |
|
77 | } |
||
78 | |||
79 | /** |
||
80 | * Extend the cookie with new information |
||
81 | * |
||
82 | * @param array $data |
||
83 | * @param string $name |
||
84 | * |
||
85 | * @return boolean |
||
86 | */ |
||
87 | 1 | public function extend($data, $name = 'openimporter_cookie') |
|
106 | } |
||
107 | } |
||
108 |