Completed
Push — master ( 1d9f27...7623c5 )
by Beniamin
02:34
created

InternalContainer   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 98
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 8

Test Coverage

Coverage 60.61%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 10
c 1
b 0
f 1
lcom 2
cbo 8
dl 0
loc 98
ccs 20
cts 33
cp 0.6061
rs 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 17 1
A set() 0 6 1
A get() 0 12 3
A has() 0 4 1
A initialized() 0 4 1
A getParameter() 0 4 1
A hasParameter() 0 4 1
A setParameter() 0 6 1
1
<?php
2
3
/**
4
 * This file is part of Phuria SQL Builder package.
5
 *
6
 * Copyright (c) 2016 Beniamin Jonatan Šimko
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Phuria\SQLBuilder\DependencyInjection;
13
14
use Phuria\SQLBuilder\Parameter\ParameterManager;
15
use Phuria\SQLBuilder\QueryCompiler\ConcreteCompiler\DeleteCompiler;
16
use Phuria\SQLBuilder\QueryCompiler\ConcreteCompiler\InsertCompiler;
17
use Phuria\SQLBuilder\QueryCompiler\ConcreteCompiler\SelectCompiler;
18
use Phuria\SQLBuilder\QueryCompiler\ConcreteCompiler\UpdateCompiler;
19
use Phuria\SQLBuilder\QueryCompiler\QueryCompiler;
20
use Phuria\SQLBuilder\TableFactory\TableFactory;
21
use Phuria\SQLBuilder\TableRegistry;
22
use Symfony\Component\DependencyInjection\ContainerInterface;
23
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
24
25
/**
26
 * @author Beniamin Jonatan Šimko <[email protected]>
27
 */
28
class InternalContainer implements ContainerInterface
29
{
30
    /**
31
     * @var array
32
     */
33
    private $services = [];
34
35
    /**
36
     * @var array
37
     */
38
    private $parameters = [];
39
40 6
    public function __construct()
41
    {
42 6
        $this->parameters['phuria.sql_builder.parameter_manager.class'] = ParameterManager::class;
43
44 6
        $tableRegistry = new TableRegistry();
45 6
        $this->services['phuria.sql_builder.table_registry'] = $tableRegistry;
46
47 6
        $tableFactory = new TableFactory($tableRegistry);
48 6
        $this->services['phuria.sql_builder.table_factory'] = $tableFactory;
49
50 6
        $queryCompiler = new QueryCompiler();
51 6
        $queryCompiler->addConcreteCompiler(new SelectCompiler());
52 6
        $queryCompiler->addConcreteCompiler(new InsertCompiler());
53 6
        $queryCompiler->addConcreteCompiler(new DeleteCompiler());
54 6
        $queryCompiler->addConcreteCompiler(new UpdateCompiler());
55 6
        $this->services['phuria.sql_builder.query_compiler'] = $queryCompiler;
56 6
    }
57
58
    /**
59
     * @inheritdoc
60
     */
61
    public function set($id, $service)
62
    {
63
        $this->services[$id] = $service;
64
65
        return $this;
66
    }
67
68
    /**
69
     * @inheritdoc
70
     */
71 35
    public function get($id, $invalidBehavior = self::EXCEPTION_ON_INVALID_REFERENCE)
72
    {
73 35
        if ($this->has($id)) {
74 35
            return $this->services[$id];
75
        }
76
77
        if (self::EXCEPTION_ON_INVALID_REFERENCE === $invalidBehavior) {
78
            throw new ServiceNotFoundException($id);
79
        }
80
81
        return null;
82
    }
83
84
    /**
85
     * @inheritdoc
86
     */
87 35
    public function has($id)
88
    {
89 35
        return array_key_exists($id, $this->services);
90
    }
91
92
    /**
93
     * @inheritdoc
94
     */
95
    public function initialized($id)
96
    {
97
        return true;
98
    }
99
100
    /**
101
     * @inheritdoc
102
     */
103 35
    public function getParameter($name)
104
    {
105 35
        return $this->parameters[$name];
106
    }
107
108
    /**
109
     * @inheritdoc
110
     */
111
    public function hasParameter($name)
112
    {
113
        return array_key_exists($name, $this->parameters);
114
    }
115
116
    /**
117
     * @inheritdoc
118
     */
119
    public function setParameter($name, $value)
120
    {
121
        $this->parameters[$name] = $value;
122
123
        return $this;
124
    }
125
}