Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
0.00% covered (danger)
0.00%
0 / 1
14.29% covered (danger)
14.29%
1 / 7
CRAP
21.74% covered (danger)
21.74%
5 / 23
Session
0.00% covered (danger)
0.00%
0 / 1
14.29% covered (danger)
14.29%
1 / 7
94.01
21.74% covered (danger)
21.74%
5 / 23
 get
0.00% covered (danger)
0.00%
0 / 1
6
0.00% covered (danger)
0.00%
0 / 2
 set
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
3 / 3
 has
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 2
 destroy
0.00% covered (danger)
0.00%
0 / 1
12
0.00% covered (danger)
0.00%
0 / 7
 start
0.00% covered (danger)
0.00%
0 / 1
4.12
50.00% covered (danger)
50.00%
2 / 4
 all
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 2
 clear
0.00% covered (danger)
0.00%
0 / 1
6
0.00% covered (danger)
0.00%
0 / 3
<?php
declare(strict_types=1);
namespace Eywa\Session {
    class Session implements SessionInterface
    {
        /**
         * @inheritDoc
         */
        public function get(string $key)
        {
            $this->start();
            return $this->has($key) ?  $_SESSION[$key] : '';
        }
        /**
         * @inheritDoc
         */
        public function set(string $key, $value): SessionInterface
        {
            $this->start();
            $_SESSION[$key] = $value;
            return $this;
        }
        /**
         * @inheritDoc
         */
        public function has(string $key): bool
        {
            $this->start();
            return  array_key_exists($key, $_SESSION);
        }
        /**
         * @inheritDoc
         */
        public function destroy(array $keys): bool
        {
            $x = collect();
            foreach ($keys as $key) {
                if ($this->has($key)) {
                    unset($_SESSION[$key]);
                    $x->push(true);
                } else {
                    $x->push(false);
                }
            }
            return $x->ok();
        }
        /**
         * @inheritDoc
         */
        public function start(): SessionInterface
        {
            if (php_sapi_name() !== 'cli') {
                if (session_status() === PHP_SESSION_NONE) {
                    session_start();
                }
            }
            return  $this;
        }
        /**
         * @inheritDoc
         */
        public function all(): array
        {
            $this->start();
            return $_SESSION;
        }
        /**
         * @inheritDoc
         */
        public function clear(): bool
        {
            foreach ($this->all() as $value) {
                $this->destroy($value);
            }
            return empty($this->all());
        }
    }
}