| Total Complexity | 10 |
| Total Lines | 58 |
| Duplicated Lines | 0 % |
| Coverage | 70.37% |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 18 | class FlashData |
||
| 19 | { |
||
| 20 | protected $previous = []; |
||
| 21 | protected $next = []; |
||
| 22 | |||
| 23 | public const DEFAULT_SESSION_KEY = 'flash-data'; |
||
| 24 | |||
| 25 | protected $sessionKey = self::DEFAULT_SESSION_KEY; |
||
| 26 | |||
| 27 | /** |
||
| 28 | * FlashData constructor. |
||
| 29 | */ |
||
| 30 | 3 | public function __construct() |
|
| 31 | { |
||
| 32 | 3 | $this->read(); |
|
| 33 | 3 | } |
|
| 34 | |||
| 35 | 3 | public function read() |
|
| 36 | { |
||
| 37 | 3 | if (isset($_SESSION[$this->sessionKey])) { |
|
| 38 | 2 | $data = $_SESSION[$this->sessionKey]; |
|
| 39 | 2 | if (is_array($data)) { |
|
| 40 | 2 | $this->previous = $data; |
|
| 41 | } |
||
| 42 | 2 | unset($_SESSION[$this->sessionKey]); |
|
| 43 | } |
||
| 44 | 3 | } |
|
| 45 | |||
| 46 | public function has($var) |
||
| 47 | { |
||
| 48 | return isset($this->previous[trim($var)]); |
||
| 49 | } |
||
| 50 | |||
| 51 | 1 | public function get($var) |
|
| 52 | { |
||
| 53 | 1 | return $this->previous[trim($var)] ?? null; |
|
| 54 | } |
||
| 55 | |||
| 56 | 1 | public function add($var, $value) |
|
| 57 | { |
||
| 58 | 1 | $this->next[trim($var)] = $value; |
|
| 59 | 1 | $this->write(); |
|
| 60 | 1 | } |
|
| 61 | |||
| 62 | 1 | protected function write() |
|
| 63 | { |
||
| 64 | 1 | $_SESSION[$this->sessionKey] = $this->next; |
|
| 65 | 1 | } |
|
| 66 | |||
| 67 | public function remove($var) |
||
| 68 | { |
||
| 69 | unset($this->next[trim($var)]); |
||
| 70 | $this->write(); |
||
| 71 | } |
||
| 72 | |||
| 73 | protected function clear() |
||
| 76 | } |
||
| 77 | } |
||
| 78 |