Passed
Pull Request — 1.x.x (#5)
by Koldo
04:31 queued 02:10
created

AuraSessionSegmentFactory   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
c 1
b 0
f 0
dl 0
loc 19
ccs 9
cts 9
cp 1
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 8 2
A __construct() 0 4 1
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