Completed
Push — master ( f96c41...a922b1 )
by Maurício
01:25 queued 19s
created

Migration   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 11
dl 0
loc 50
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setGlobal() 0 4 1
A __construct() 0 3 1
A getInstance() 0 11 3
1
<?php
2
/* vim: set expandtab sw=4 ts=4 sts=4: */
3
/**
4
 * Migration from home-made DI to Symfony DI
5
 *
6
 * @package PhpMyAdmin\Di
7
 */
8
declare(strict_types=1);
9
10
namespace PhpMyAdmin\Di;
11
12
use InvalidArgumentException;
13
use Symfony\Component\DependencyInjection\ContainerBuilder;
14
15
/**
16
 * Migration from home-made DI to Symfony DI
17
 *
18
 * @package PhpMyAdmin\Di
19
 */
20
class Migration
21
{
22
    /** @var self */
23
    protected static $instance;
24
25
    /** @var ContainerBuilder */
26
    protected $containerBuilder;
27
28
    /**
29
     * Get instance of this class
30
     *
31
     * @param ContainerBuilder|null $containerBuilder ContainerBuilder object that should be used to store the data
32
     *
33
     * @return Migration
34
     */
35
    public static function getInstance(?ContainerBuilder $containerBuilder = null): self
36
    {
37
        if (null !== self::$instance) {
38
            return self::$instance;
39
        }
40
41
        if (null === $containerBuilder) {
42
            throw new InvalidArgumentException('Container builder should be sent for ' . self::class . ' creation');
43
        }
44
45
        return self::$instance = new self($containerBuilder);
46
    }
47
48
    /**
49
     * Migration constructor.
50
     *
51
     * @param ContainerBuilder $containerBuilder ContainerBuilder object that should be used to store the data
52
     */
53
    protected function __construct(ContainerBuilder $containerBuilder)
54
    {
55
        $this->containerBuilder = $containerBuilder;
56
    }
57
58
    /**
59
     * Get the instance of the service
60
     *
61
     * @param string $key   Key of data to store
62
     * @param mixed  $value Data to store
63
     *
64
     * @return void
65
     */
66
    public function setGlobal(string $key, $value)
67
    {
68
        $GLOBALS[$key] = $value;
69
        $this->containerBuilder->setParameter($key, $value);
70
    }
71
}
72