Passed
Push — 1.x.x ( 769858...6e6b4c )
by Koldo
02:22
created

AuraSessionSegmentFactory::__invoke()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 4
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 8
ccs 5
cts 5
cp 1
crap 2
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Antidot\Session\Infrastructure;
6
7
use Antidot\Session\Application\Http\SessionSegment;
8
use Antidot\Session\Application\Http\SessionSegmentFactory;
9
use Aura\Session\SessionFactory;
10
use Psr\Http\Message\ServerRequestInterface;
11
12
class AuraSessionSegmentFactory implements SessionSegmentFactory
13
{
14
    private SessionFactory $factory;
15
    private string $segmentName;
16
17 2
    public function __construct(SessionFactory $factory, string $segmentName = 'app')
18
    {
19 2
        $this->factory = $factory;
20 2
        $this->segmentName = $segmentName;
21 2
    }
22
23 2
    public function __invoke(ServerRequestInterface $request): SessionSegment
24
    {
25 2
        $session = $this->factory->newInstance($request->getCookieParams());
26 2
        if (false === $session->isStarted()) {
27 2
            $session->start();
28
        }
29
30 2
        return new AuraSessionSegment($session->getSegment($this->segmentName));
31
    }
32
}
33