SingletonContainer::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 2
c 2
b 0
f 0
dl 0
loc 4
rs 10
ccs 0
cts 4
cp 0
cc 1
nc 1
nop 1
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace DMK\MKSamlAuth\Container;
6
7
use TYPO3\CMS\Core\SingletonInterface;
8
use TYPO3\CMS\Extbase\Object\Container\Container;
9
10
class SingletonContainer implements SingletonInterface
11
{
12
    /**
13
     * @var Container
14
     */
15
    private $container;
16
17
    /**
18
     * @var []
0 ignored issues
show
Documentation Bug introduced by
The doc comment [] at position 0 could not be parsed: Unknown type name '[' at position 0 in [].
Loading history...
19
     */
20
    private $instances;
21
22
    public function __construct(Container $container)
23
    {
24
        $this->container = $container;
25
        $this->instances = [];
26
    }
27
28
    public function getInstance(string $className, array $givenConstructorArguments = [])
29
    {
30
        if (isset($this->instances[$className])) {
31
            return $this->instances[$className];
32
        }
33
34
        return $this->instances[$className] = $this->container->getInstance($className, $givenConstructorArguments);
35
    }
36
}
37