Completed
Push — master ( e502a6...b659c5 )
by Michael
08:23
created

Container::extend()   B

Complexity

Conditions 5
Paths 4

Size

Total Lines 18
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 5.0909

Importance

Changes 0
Metric Value
dl 0
loc 18
ccs 11
cts 13
cp 0.8462
rs 8.8571
c 0
b 0
f 0
cc 5
eloc 12
nc 4
nop 2
crap 5.0909

1 Method

Rating   Name   Duplication   Size   Complexity  
A Container::register() 0 8 2
1
<?php
2
declare(strict_types = 1);
3
/**
4
 * Contains class Container.
5
 *
6
 * This should act as a drop-in replacement for Pimple. In the end the wrapper
7
 * idea just did not work do to the design of Pimple so I re-implemented
8
 * everything here and use my interface.
9
 *
10
 * PHP version 7.0+
11
 *
12
 * This file is part of Yet Another Php Eve Api Library also know as Yapeal
13
 * which can be used to access the Eve Online API data and place it into a
14
 * database.
15
 * Copyright (C) 2014-2016 Michael Cummings
16
 *
17
 * This program is free software: you can redistribute it and/or modify it
18
 * under the terms of the GNU Lesser General Public License as published by the
19
 * Free Software Foundation, either version 3 of the License, or (at your
20
 * option) any later version.
21
 *
22
 * This program is distributed in the hope that it will be useful, but WITHOUT
23
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
24
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
25
 * for more details.
26
 *
27
 * You should have received a copy of the GNU Lesser General Public License
28
 * along with this program. If not, see
29
 * <http://spdx.org/licenses/LGPL-3.0.html>.
30
 *
31
 * You should be able to find a copy of this license in the COPYING-LESSER.md
32
 * file. A copy of the GNU GPL should also be available in the COPYING.md file.
33
 *
34
 * @copyright 2014-2016 Michael Cummings
35
 * @license   http://www.gnu.org/copyleft/lesser.html GNU LGPL
36
 * @author    Michael Cummings <[email protected]>
37
 * @author    Fabien Potencier
38
 */
39
namespace Yapeal\Container;
40
41
/**
42
 * Container class.
43
 *
44
 * @author Michael Cummings <[email protected]>
45
 * @since  1.1.x-WIP
46
 */
47
class Container implements ContainerInterface, ServiceProviderContainerInterface
48
{
49
    use ContainerArrayAccessTrait;
50
    use ContainerMagicTrait;
51
    /**
52
     * Instantiate the container.
53
     *
54
     * Objects and parameters can be passed as argument to the constructor.
55
     *
56
     * @param array $values The parameters or objects.
57
     *
58 28
     * @throws \RuntimeException
59
     */
60 28
    public function __construct(array $values = [])
61 28
    {
62 28
        $this->factories = new \SplObjectStorage();
63 1
        $this->protected = new \SplObjectStorage();
64
        $this->frozen = [];
65
        $this->keys = [];
66
        $this->raw = [];
67
        $this->values = [];
68
        foreach ($values as $key => $value) {
69
            $this->offsetSet($key, $value);
70
        }
71
    }
72
    /**
73
     * Registers a service provider.
74
     *
75
     * @param ServiceProviderInterface $provider A ServiceProviderInterface instance
76
     * @param array                    $values   An array of values that customizes the provider
77
     *
78
     * @return ContainerInterface Fluent interface.
79 5
     */
80
    public function register(ServiceProviderInterface $provider, array $values = []): ContainerInterface
81 5
    {
82 1
        $provider->register($this);
83
        foreach ($values as $key => $value) {
84 4
            $this[(string)$key] = $value;
85 2
        }
86
        return $this;
87 3
    }
88 3
    /**
89 3
     * @var \SplObjectStorage $factories
90 3
     */
91 3
    private $factories;
92
    /**
93
     * @var bool[] $frozen
94
     */
95 3
    private $frozen;
96
    /**
97
     * @var bool[] $keys
98
     */
99
    private $keys;
100
    /**
101
     * @var \SplObjectStorage $protected
102
     */
103
    private $protected;
104
    /**
105
     * @var mixed[] $raw
106 2
     */
107
    private $raw;
108
    /**
109 2
     * @var mixed[] $values
110 2
     */
111
    private $values;
112
}
113