SessionBusinessFactory::createSession()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
ccs 3
cts 3
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
4
namespace Xervice\Session\Business;
5
6
7
use Symfony\Component\HttpFoundation\Session\Session;
8
use Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage;
9
use Symfony\Component\HttpFoundation\Session\Storage\SessionStorageInterface;
10
use Xervice\Core\Business\Model\Factory\AbstractBusinessFactory;
11
use Xervice\Session\SessionDependencyProvider;
12
13
class SessionBusinessFactory extends AbstractBusinessFactory
14
{
15
    /**
16
     * @var Session
17
     */
18
    private $session;
19
20
    /**
21
     * @return \Symfony\Component\HttpFoundation\Session\Session
22
     * @throws \InvalidArgumentException
23
     * @throws \RuntimeException
24
     */
25 2
    public function getSession(): Session
26
    {
27 2
        if ($this->session === null) {
28 1
            $this->session = $this->createSession();
29
        }
30 2
        return $this->session;
31
    }
32
33
    /**
34
     * @return \Symfony\Component\HttpFoundation\Session\Session
35
     * @throws \RuntimeException
36
     * @throws \InvalidArgumentException
37
     */
38 1
    public function createSession(): Session
39
    {
40 1
        return new Session(
41 1
            $this->createSessionStorage()
42
        );
43
    }
44
45
    /**
46
     * @return \Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage
47
     * @throws \RuntimeException
48
     * @throws \InvalidArgumentException
49
     */
50 1
    public function createSessionStorage(): SessionStorageInterface
51
    {
52 1
        return new NativeSessionStorage(
53 1
            [],
54 1
            $this->getSessionHandler()
55
        );
56
    }
57
58
    /**
59
     * @return \SessionHandlerInterface
60
     */
61 1
    public function getSessionHandler(): \SessionHandlerInterface
62
    {
63 1
        return $this->getDependency(SessionDependencyProvider::SESSION_HANDLER);
64
    }
65
}
66