Completed
Push — master ( 57007c...647e58 )
by Bogdan
02:16
created

AliasContainerConfigurator::configure()   B

Complexity

Conditions 5
Paths 4

Size

Total Lines 16
Code Lines 8

Duplication

Lines 16
Ratio 100 %

Code Coverage

Tests 10
CRAP Score 5

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 16
loc 16
ccs 10
cts 10
cp 1
rs 8.8571
cc 5
eloc 8
nc 4
nop 1
crap 5
1
<?php
2
3
/*
4
  +----------------------------------------------------------------------+
5
  | This file is part of the pinepain/container-extras PHP library.      |
6
  |                                                                      |
7
  | Copyright (c) 2015-2016 Bogdan Padalko <[email protected]>          |
8
  |                                                                      |
9
  | Licensed under the MIT license: http://opensource.org/licenses/MIT   |
10
  |                                                                      |
11
  | For the full copyright and license information, please view the      |
12
  | LICENSE file that was distributed with this source or visit          |
13
  | http://opensource.org/licenses/MIT                                   |
14
  +----------------------------------------------------------------------+
15
*/
16
17
18
namespace Pinepain\Container\Extras;
19
20
21
use Pinepain\Container\Extras\Exceptions\InvalidConfigException;
22
use Traversable;
23
24
25
class AliasContainerConfigurator extends AbstractContainerConfigurator
26
{
27
    /**
28
     * @var AliasContainerInterface
29
     */
30
    private $container;
31
32
    /**
33
     * @param AliasContainerInterface $container
34
     */
35 6
    public function __construct(AliasContainerInterface $container)
36
    {
37 6
        $this->container = $container;
38 6
    }
39
40
    /**
41
     * {@inheritdoc}
42
     */
43 3
    protected function configureMany($config)
44
    {
45 3
        foreach ($config as $alias => $concrete) {
46 2
            if (!is_string($concrete)) {
47 1
                continue;
48
            }
49
50 2
            $this->configureOne($alias, $concrete);
51 3
        }
52 3
    }
53
54
    /**
55
     * {@inheritdoc}
56
     */
57 5
    public function configureOne($alias, $concrete)
58
    {
59 5
        if (!is_string($alias) || !is_string($concrete)) {
60 3
            throw new InvalidConfigException('Alias and concrete should be strings');
61
        }
62
63 2
        $this->container->add($alias, $concrete);
64 2
    }
65
}
66