| Total Complexity | 6 |
| Total Lines | 57 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 12 | class Cookie |
||
| 13 | { |
||
| 14 | const COOKIE_PATH = '/'; |
||
| 15 | const COOKIE_TIMEOUT = 432000; |
||
| 16 | |||
| 17 | /** |
||
| 18 | * Set cookie by name |
||
| 19 | * |
||
| 20 | * @param string $name |
||
| 21 | * @param $value |
||
| 22 | * @param string $path |
||
| 23 | * @param int $timeout |
||
| 24 | * |
||
| 25 | * @return bool |
||
| 26 | */ |
||
| 27 | public static function set(string $name, $value, string $path = self::COOKIE_PATH, int $timeout = self::COOKIE_TIMEOUT): bool |
||
| 28 | { |
||
| 29 | $_COOKIE[$name] = $value; |
||
| 30 | |||
| 31 | return setcookie($name, (string) $value, time() + $timeout, $path); |
||
| 32 | } |
||
| 33 | |||
| 34 | /** |
||
| 35 | * Check cookie by name |
||
| 36 | * |
||
| 37 | * @param string $name |
||
| 38 | * |
||
| 39 | * @return bool |
||
| 40 | */ |
||
| 41 | public static function has(string $name): bool |
||
| 42 | { |
||
| 43 | return isset($_COOKIE[$name]); |
||
| 44 | } |
||
| 45 | |||
| 46 | /** |
||
| 47 | * Get cookie by name |
||
| 48 | * |
||
| 49 | * @param string $name |
||
| 50 | * @param null $default |
||
|
|
|||
| 51 | * |
||
| 52 | * @return null|mixed |
||
| 53 | */ |
||
| 54 | public static function get(string $name, $default = null) |
||
| 57 | } |
||
| 58 | |||
| 59 | /** |
||
| 60 | * Remove cookie by name |
||
| 61 | * |
||
| 62 | * @param string $name |
||
| 63 | */ |
||
| 64 | public static function remove(string $name): void |
||
| 69 | } |
||
| 70 | } |
||
| 71 | } |