Passed
Push — master ( e1468a...94992f )
by Mikael
02:31
created

DIFactoryConfig::__construct()   B

Complexity

Conditions 6
Paths 5

Size

Total Lines 15
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 6.5625

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 15
ccs 9
cts 12
cp 0.75
rs 8.8571
cc 6
eloc 9
nc 5
nop 1
crap 6.5625
1
<?php
2
3
namespace Anax\DI;
4
5
use \Anax\Configure\ConfigureInterface;
6
use \Anax\Configure\ConfigureTrait;
7
8
/**
9
 * DI factory class creating a set of default services by loading
10
 * them from a configuration file.
11
 */
12
class DIFactoryConfig extends DI implements ConfigureInterface, DIInterface
13
{
14
    use ConfigureTrait;
15
16
17
18
   /**
19
     * Constructor creating a set of services from a configuration file.
20
     */
21 2
    public function __construct($configFile)
22
    {
23 2
        $this->configure($configFile);
24 2
        foreach ($this->config["services"] as $name => $service) {
25 2
            if (isset($service["shared"]) && $service["shared"]) {
26 2
                $this->setShared($name, $service["callback"]);
27 2
            } else {
28
                $this->set($name, $service["callback"]);
29
            }
30
31 2
            if (isset($service["active"]) && $service["active"]) {
32
                $this->get($name);
33
            }
34 2
        }
35 2
    }
36
}
37