SessionConfiguration   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 74
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 1
dl 0
loc 74
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A apply() 0 11 1
A prepareSession() 0 16 3
A startSession() 0 4 1
A canSessionStart() 0 4 1
A isCli() 0 4 1
1
<?php
2
3
namespace Equip\Configuration;
4
5
use Auryn\Injector;
6
use Equip\Configuration\ConfigurationInterface;
7
use Equip\NativeSession;
8
use Equip\SessionInterface;
9
10
class SessionConfiguration implements ConfigurationInterface
11
{
12
    /**
13
     * @inheritDoc
14
     */
15 1
    public function apply(Injector $injector)
16
    {
17 1
        $injector->share(SessionInterface::class);
18
19 1
        $injector->alias(
20 1
            SessionInterface::class,
21
            NativeSession::class
22 1
        );
23
24 1
        $injector->prepare(NativeSession::class, [$this, 'prepareSession']);
25 1
    }
26
27
    /**
28
     * Initialize the session
29
     *
30
     * @param NativeSession $session
31
     * @param Injector $injector
32
     *
33
     * @return void
34
     */
35 1
    public function prepareSession(NativeSession $session, Injector $injector)
0 ignored issues
show
Unused Code introduced by
The parameter $session is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $injector is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
36
    {
37
        // It seems impossible to test this, since it has to be run in a web
38
        // server to really be useful and PHPUnit will prevent the session
39
        // headers working properly. One possible way to test it is by using
40
        // runkit to mock the [native function][1], but that seems extreme and
41
        // requires installation of a PECL extension.
42
        //
43
        // [1]: https://github.com/tcz/phpunit-mockfunction
0 ignored issues
show
Unused Code Comprehensibility introduced by
58% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
44
        //
45
        // @codeCoverageIgnoreStart
46
        if ($this->canSessionStart() && $this->isCli() === false) {
47
            $this->startSession();
48
        }
49
        // @codeCoverageIgnoreEnd
50 1
    }
51
52
    /**
53
     * Start a new session
54
     *
55
     * @return void
56
     *
57
     * @codeCoverageIgnore
58
     */
59
    protected function startSession()
60
    {
61
        session_start();
62
    }
63
64
    /**
65
     * Check if a session can be started
66
     *
67
     * @return boolean
68
     */
69 1
    private function canSessionStart()
70
    {
71 1
        return session_status() === PHP_SESSION_NONE;
72
    }
73
74
    /**
75
     * Check if we are running in a command line context
76
     *
77
     * @return boolean
78
     */
79 1
    private function isCli()
80
    {
81 1
        return php_sapi_name() === 'cli';
82
    }
83
}
84