SystemContainerProvider::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 1
1
<?php
2
3
/*
4
 * This file is part of the LightSAML-Core package.
5
 *
6
 * (c) Milos Tomic <[email protected]>
7
 *
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
namespace LightSaml\Bridge\Pimple\Container\Factory;
13
14
use LightSaml\Bridge\Pimple\Container\SystemContainer;
15
use LightSaml\Provider\TimeProvider\SystemTimeProvider;
16
use Pimple\Container;
17
use Pimple\ServiceProviderInterface;
18
use Psr\Log\NullLogger;
19
use Symfony\Component\EventDispatcher\EventDispatcher;
20
use Symfony\Component\HttpFoundation\Request;
21
use Symfony\Component\HttpFoundation\Session\Session;
22
use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage;
23
24
class SystemContainerProvider implements ServiceProviderInterface
25
{
26
    /** @var bool */
27
    private $mockSession;
28
29
    public function __construct($mockSession = false)
0 ignored issues
show
Unused Code introduced by
The parameter $mockSession is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

29
    public function __construct(/** @scrutinizer ignore-unused */ $mockSession = false)

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

Loading history...
30
    {
31
        $this->mockSession = true;
32
    }
33
34
    /**
35
     * @param Container $pimple A container instance
36
     */
37
    public function register(Container $pimple)
38
    {
39
        $pimple[SystemContainer::REQUEST] = function () {
40
            return Request::createFromGlobals();
41
        };
42
43
        $pimple[SystemContainer::SESSION] = function () {
44
            if ($this->mockSession) {
45
                $session = new Session(new MockArraySessionStorage());
46
            } else {
47
                $session = new Session();
48
            }
49
            $session->setName(sprintf('SID%s', mt_rand(1000, 9999)));
50
            $session->start();
51
52
            return $session;
53
        };
54
55
        $pimple[SystemContainer::TIME_PROVIDER] = function () {
56
            return new SystemTimeProvider();
57
        };
58
59
        $pimple[SystemContainer::EVENT_DISPATCHER] = function () {
60
            return new EventDispatcher();
61
        };
62
63
        $pimple[SystemContainer::LOGGER] = function () {
64
            return new NullLogger();
65
        };
66
    }
67
}
68