SessionalInterceptor::invoke()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 16
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 3

Importance

Changes 2
Bugs 1 Features 0
Metric Value
c 2
b 1
f 0
dl 0
loc 16
ccs 9
cts 9
cp 1
rs 9.4285
cc 3
eloc 9
nc 2
nop 1
crap 3
1
<?php
2
3
namespace Ray\SymfonySessionModule;
4
5
use Ray\Aop\MethodInterceptor;
6
use Ray\Aop\MethodInvocation;
7
use Ray\SymfonySessionModule\Exception\SessionExpiredException;
8
9
class SessionalInterceptor implements MethodInterceptor
10
{
11
    use SessionInject;
12
13
    /**
14
     * {@inheritdoc}
15
     */
16 4
    public function invoke(MethodInvocation $invocation)
17
    {
18 4
        $this->session->start();
19
20 4
        $metadataBag = $this->session->getMetadataBag();
21 4
        $lifetime = $metadataBag->getLifetime();
22
23 4
        if ($lifetime > 0 && $metadataBag->getLastUsed() + $lifetime < time()) {
24 1
            $this->session->invalidate();
25 1
            throw new SessionExpiredException('Session has expired.');
26
        }
27
28 3
        $this->session->migrate();
29
30 3
        return $invocation->proceed();
31
    }
32
}
33