ConfigurationContainer::__construct()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 13
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 10
nc 3
nop 1
dl 0
loc 13
rs 9.9332
c 1
b 0
f 0
1
<?php
2
3
4
namespace Pfilsx\DataGrid\Config;
5
6
7
class ConfigurationContainer implements ConfigurationContainerInterface
8
{
9
    /**
10
     * @var ConfigurationInterface[]
11
     */
12
    private $instances = [];
13
14
    public function __construct(array $config)
15
    {
16
        $this->instances['default'] = new Configuration([
17
            'template' => '@DataGrid/grid.blocks.html.twig',
18
            'no_data_message' => 'No data found',
19
            'show_titles' => true,
20
            'pagination_enabled' => true,
21
            'pagination_limit' => 10,
22
            'translation_domain' => null
23
        ]);
24
        if (!empty($config['instances'])){
25
            foreach ($config['instances'] as $key => $configuration) {
26
                $this->instances[$key] = new Configuration($configuration);
27
            }
28
        }
29
    }
30
31
    public function getInstance(string $name): ConfigurationInterface
32
    {
33
        return array_key_exists($name, $this->instances) ? $this->instances[$name] : null;
0 ignored issues
show
Bug Best Practice introduced by
The expression return array_key_exists(...instances[$name] : null could return the type null which is incompatible with the type-hinted return Pfilsx\DataGrid\Config\ConfigurationInterface. Consider adding an additional type-check to rule them out.
Loading history...
34
    }
35
}