Passed
Push — master ( b3f945...fcf496 )
by Jelmer
04:58
created

ZendSessionProcessor   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 5
dl 0
loc 24
ccs 10
cts 10
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A processRequest() 0 8 1
A processResponse() 0 4 1
1
<?php declare(strict_types = 1);
2
3
namespace jschreuder\Middle\Session;
4
5
use Psr\Http\Message\ResponseInterface;
6
use Psr\Http\Message\ServerRequestInterface;
7
use Zend\Session\Config\ConfigInterface;
8
use Zend\Session\Container;
9
use Zend\Session\SessionManager;
10
11
class ZendSessionProcessor implements SessionProcessorInterface
12
{
13
    /** @var  int */
14
    private $zendSessionConfig;
15
16 3
    public function __construct(ConfigInterface $zendSessionConfig)
17
    {
18 3
        $this->zendSessionConfig = $zendSessionConfig;
0 ignored issues
show
Documentation Bug introduced by
It seems like $zendSessionConfig of type object<Zend\Session\Config\ConfigInterface> is incompatible with the declared type integer of property $zendSessionConfig.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
19 3
    }
20
21 1
    public function processRequest(ServerRequestInterface $request): ServerRequestInterface
22
    {
23 1
        $sessionManager = new SessionManager($this->zendSessionConfig);
0 ignored issues
show
Documentation introduced by
$this->zendSessionConfig is of type integer, but the function expects a null|object<Zend\Session\Config\ConfigInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
24 1
        $container = new Container(str_replace('.', '_', $request->getUri()->getHost()), $sessionManager);
25
26 1
        $session = new ZendSession($sessionManager, $container);
27 1
        return $request->withAttribute('session', $session);
28
    }
29
30 1
    public function processResponse(ServerRequestInterface $request, ResponseInterface $response): ResponseInterface
31
    {
32 1
        return $response;
33
    }
34
}
35