FileDefinitionLoader   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 9
c 2
b 0
f 0
dl 0
loc 20
rs 10
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getIterator() 0 3 1
A __construct() 0 7 4
1
<?php
2
3
/**
4
 * This file is part of slick/di package
5
 *
6
 * For the full copyright and license information, please view the LICENSE.md
7
 * file that was distributed with this source code.
8
 */
9
10
namespace Slick\Di\DefinitionLoader;
11
12
use ArrayObject;
13
use Slick\Di\Definition\CreateDefinitionsMethods;
14
use Slick\Di\Definition\ObjectDefinition;
15
use Slick\Di\DefinitionLoaderInterface;
16
use Traversable;
17
18
/**
19
 * FileDefinitionLoader
20
 *
21
 * @package Slick\Di\DefinitionLoader
22
 * @author  Filipe Silva <[email protected]>
23
*/
24
class FileDefinitionLoader implements DefinitionLoaderInterface
25
{
26
    use CreateDefinitionsMethods;
27
28
    private array $definitions = [];
29
30
    public function __construct(string|array $definitions)
31
    {
32
        $services = is_string($definitions) ? require $definitions : $definitions;
0 ignored issues
show
introduced by
The condition is_string($definitions) is always false.
Loading history...
33
        foreach ($services as $name => $definition) {
34
            $this->definitions[$name] = $definition instanceof ObjectDefinition
35
                ? $definition
36
                : $this->createDefinition($definition);
37
        }
38
    }
39
40
41
    public function getIterator(): Traversable
42
    {
43
        return new ArrayObject($this->definitions);
44
    }
45
}
46