Completed
Push — master ( 3e535a...8096b4 )
by Beniamin
03:04
created

InternalContainer   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 95
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 8

Test Coverage

Coverage 58.06%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 10
c 1
b 0
f 1
lcom 2
cbo 8
dl 0
loc 95
ccs 18
cts 31
cp 0.5806
rs 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 14 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
        $this->services['phuria.sql_builder.table_registry'] = new TableRegistry();
45 6
        $this->services['phuria.sql_builder.table_factory'] = new TableFactory();
46
47 6
        $queryCompiler = new QueryCompiler();
48 6
        $queryCompiler->addConcreteCompiler(new SelectCompiler());
49 6
        $queryCompiler->addConcreteCompiler(new InsertCompiler());
50 6
        $queryCompiler->addConcreteCompiler(new DeleteCompiler());
51 6
        $queryCompiler->addConcreteCompiler(new UpdateCompiler());
52 6
        $this->services['phuria.sql_builder.query_compiler'] = $queryCompiler;
53 6
    }
54
55
    /**
56
     * @inheritdoc
57
     */
58
    public function set($id, $service)
59
    {
60
        $this->services[$id] = $service;
61
62
        return $this;
63
    }
64
65
    /**
66
     * @inheritdoc
67
     */
68 35
    public function get($id, $invalidBehavior = self::EXCEPTION_ON_INVALID_REFERENCE)
69
    {
70 35
        if ($this->has($id)) {
71 35
            return $this->services[$id];
72
        }
73
74
        if (self::EXCEPTION_ON_INVALID_REFERENCE === $invalidBehavior) {
75
            throw new ServiceNotFoundException($id);
76
        }
77
78
        return null;
79
    }
80
81
    /**
82
     * @inheritdoc
83
     */
84 35
    public function has($id)
85
    {
86 35
        return array_key_exists($id, $this->services);
87
    }
88
89
    /**
90
     * @inheritdoc
91
     */
92
    public function initialized($id)
93
    {
94
        return true;
95
    }
96
97
    /**
98
     * @inheritdoc
99
     */
100 35
    public function getParameter($name)
101
    {
102 35
        return $this->parameters[$name];
103
    }
104
105
    /**
106
     * @inheritdoc
107
     */
108
    public function hasParameter($name)
109
    {
110
        return array_key_exists($name, $this->parameters);
111
    }
112
113
    /**
114
     * @inheritdoc
115
     */
116
    public function setParameter($name, $value)
117
    {
118
        $this->parameters[$name] = $value;
119
120
        return $this;
121
    }
122
}