Completed
Push — master ( 4e360d...80bc96 )
by Daan van
07:27
created

SAML2_Compat_ContainerSingleton   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1
Metric Value
wmc 4
lcom 0
cbo 1
dl 0
loc 38
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A ContainerSingleton::getInstance() 0 7 2
A ContainerSingleton::setContainer() 0 5 1
1
<?php
2
3
namespace SAML2\Compat;
4
5
use SAML2\Compat\Ssp\Container;
6
7
class ContainerSingleton
8
{
9
    /**
10
     * @var \SAML2\Compat\Ssp\Container
11
     */
12
    protected static $container;
13
14
    /**
15
     * @return \SAML2\Compat\Ssp\Container
16
     */
17
    public static function getInstance()
18
    {
19
        if (!self::$container) {
20
            self::setContainer(self::initSspContainer());
21
        }
22
        return self::$container;
23
    }
24
25
    /**
26
     * Set a container to use.
27
     *
28
     * @param \SAML2\Compat\AbstractContainer $container
29
     * @return \SAML2\Compat\AbstractContainer
30
     */
31
    public static function setContainer(AbstractContainer $container)
32
    {
33
        self::$container = $container;
0 ignored issues
show
Documentation Bug introduced by
$container is of type object<SAML2\Compat\AbstractContainer>, but the property $container was declared to be of type object<SAML2\Compat\Ssp\Container>. Are you sure that you always receive this specific sub-class here, or does it make sense to add an instanceof check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.

Either this assignment is in error or an instanceof check should be added for that assignment.

class Alien {}

class Dalek extends Alien {}

class Plot
{
    /** @var  Dalek */
    public $villain;
}

$alien = new Alien();
$plot = new Plot();
if ($alien instanceof Dalek) {
    $plot->villain = $alien;
}
Loading history...
34
        return $container;
35
    }
36
37
    /**
38
     * @return \SAML2\Compat\Ssp\Container
39
     */
40
    public static function initSspContainer()
41
    {
42
        return new Container();
43
    }
44
}
45