Passed
Push — decouple_from_aura ( 86867c )
by Koldo
03:06
created

AuraSessionSegmentFactory::__construct()   A

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 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 4
ccs 3
cts 3
cp 1
crap 1
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