SessionFacade   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 55
ccs 11
cts 11
cp 1
rs 10
c 0
b 0
f 0
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __call() 0 3 2
A callSessionMethod() 0 8 1
A initSession() 0 3 1
A isSessionMethodExist() 0 3 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Xervice\Session\Business;
5
6
use Xervice\Core\Business\Model\Facade\AbstractFacade;
7
8
9
/**
10
 * @method \Xervice\Session\Business\SessionBusinessFactory getFactory()
11
 * @method string getId()
12
 * @method bool has($name)
13
 * @method mixed get($name, $default = null)
14
 * @method void set($name, $value)
15
 * @method mixed remove($name)
16
 * @method void clear()
17
 */
18
class SessionFacade extends AbstractFacade
19
{
20
    /**
21
     * @param string $name
22
     * @param array $arguments
23
     *
24
     * @return mixed
25
     * @throws \InvalidArgumentException
26
     * @throws \RuntimeException
27
     */
28 1
    public function __call(string $name, array $arguments)
29
    {
30 1
        return $this->isSessionMethodExist($name) ? $this->callSessionMethod($name, $arguments) : null;
31
    }
32
33
    /**
34
     * Initialize session
35
     *
36
     * @api
37
     * @throws \InvalidArgumentException
38
     * @throws \RuntimeException
39
     */
40 2
    public function initSession(): void
41
    {
42 2
        $this->getFactory()->getSession()->start();
43 2
    }
44
45
    /**
46
     * @param string $name
47
     *
48
     * @return bool
49
     * @throws \RuntimeException
50
     * @throws \InvalidArgumentException
51
     */
52 1
    private function isSessionMethodExist(string $name): bool
53
    {
54 1
        return \method_exists($this->getFactory()->getSession(), $name);
55
    }
56
57
    /**
58
     * @param string $name
59
     * @param array $arguments
60
     *
61
     * @return mixed
62
     * @throws \RuntimeException
63
     * @throws \InvalidArgumentException
64
     */
65 1
    private function callSessionMethod(string $name, array $arguments)
66
    {
67
        return \call_user_func_array(
68
            [
69 1
                $this->getFactory()->getSession(),
70 1
                $name
71
            ],
72 1
            $arguments
73
        );
74
    }
75
}
76