SessionProvider   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 6
dl 0
loc 62
ccs 31
cts 31
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A register() 0 10 1
A registerSettings() 0 10 1
A registerSetCookie() 0 10 1
A registerMiddleware() 0 14 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Chubbyphp\Session;
6
7
use Dflydev\FigCookies\SetCookie;
8
use Lcobucci\JWT\Parser;
9
use Lcobucci\JWT\Signer\Hmac\Sha256;
10
use Pimple\Container;
11
use Pimple\ServiceProviderInterface;
12
use PSR7Sessions\Storageless\Http\SessionMiddleware;
13
use PSR7Sessions\Storageless\Time\SystemCurrentTime;
14
15
final class SessionProvider implements ServiceProviderInterface
16
{
17
    /**
18
     * @param Container $container
19
     */
20 1
    public function register(Container $container)
21
    {
22 1
        $this->registerSettings($container);
0 ignored issues
show
Unused Code introduced by
The call to the method Chubbyphp\Session\Sessio...der::registerSettings() seems un-needed as the method has no side-effects.

PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.

Let’s take a look at an example:

class User
{
    private $email;

    public function getEmail()
    {
        return $this->email;
    }

    public function setEmail($email)
    {
        $this->email = $email;
    }
}

If we look at the getEmail() method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:

$user = new User();
$user->getEmail(); // This line could safely be removed as it has no effect.

On the hand, if we look at the setEmail(), this method _has_ side-effects. In the following case, we could not remove the method call:

$user = new User();
$user->setEmail('email@domain'); // This line has a side-effect (it changes an
                                 // instance variable).
Loading history...
23 1
        $this->registerSetCookie($container);
0 ignored issues
show
Unused Code introduced by
The call to the method Chubbyphp\Session\Sessio...er::registerSetCookie() seems un-needed as the method has no side-effects.

PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.

Let’s take a look at an example:

class User
{
    private $email;

    public function getEmail()
    {
        return $this->email;
    }

    public function setEmail($email)
    {
        $this->email = $email;
    }
}

If we look at the getEmail() method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:

$user = new User();
$user->getEmail(); // This line could safely be removed as it has no effect.

On the hand, if we look at the setEmail(), this method _has_ side-effects. In the following case, we could not remove the method call:

$user = new User();
$user->setEmail('email@domain'); // This line has a side-effect (it changes an
                                 // instance variable).
Loading history...
24 1
        $this->registerMiddleware($container);
0 ignored issues
show
Unused Code introduced by
The call to the method Chubbyphp\Session\Sessio...r::registerMiddleware() seems un-needed as the method has no side-effects.

PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.

Let’s take a look at an example:

class User
{
    private $email;

    public function getEmail()
    {
        return $this->email;
    }

    public function setEmail($email)
    {
        $this->email = $email;
    }
}

If we look at the getEmail() method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:

$user = new User();
$user->getEmail(); // This line could safely be removed as it has no effect.

On the hand, if we look at the setEmail(), this method _has_ side-effects. In the following case, we could not remove the method call:

$user = new User();
$user->setEmail('email@domain'); // This line has a side-effect (it changes an
                                 // instance variable).
Loading history...
25
26 1
        $container['session'] = function () use ($container) {
27 1
            return new Session($container['logger'] ?? null);
28
        };
29 1
    }
30
31
    /**
32
     * @param Container $container
33
     */
34 1
    private function registerSettings(Container $container)
35
    {
36 1
        $container['session.expirationTime'] = 1200;
37 1
        $container['session.privateRsaKey'] = '';
38 1
        $container['session.publicRsaKey'] = '';
39
40 1
        $container['session.setCookieHttpOnly'] = true;
41 1
        $container['session.setCookiePath'] = '/';
42 1
        $container['session.setCookieSecureOnly'] = true;
43 1
    }
44
45
    /**
46
     * @param Container $container
47
     */
48
    private function registerSetCookie(Container $container)
49
    {
50 1
        $container['session.setCookie'] = function () use ($container) {
51 1
            return SetCookie::create(SessionMiddleware::DEFAULT_COOKIE)
52 1
                ->withHttpOnly($container['session.setCookieHttpOnly'])
53 1
                ->withPath($container['session.setCookiePath'])
54 1
                ->withSecure($container['session.setCookieSecureOnly'])
55
            ;
56
        };
57 1
    }
58
59
    /**
60
     * @param Container $container
61
     */
62
    private function registerMiddleware(Container $container)
63
    {
64 1
        $container['session.middleware'] = function () use ($container) {
65 1
            return new SessionMiddleware(
66 1
                new Sha256(),
67 1
                $container['session.privateRsaKey'],
68 1
                $container['session.publicRsaKey'],
69 1
                $container['session.setCookie'],
70 1
                new Parser(),
71 1
                $container['session.expirationTime'],
72 1
                new SystemCurrentTime()
73
            );
74
        };
75 1
    }
76
}
77