Completed
Pull Request — master (#22)
by Sergey
15:55
created

DI   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 3
dl 0
loc 22
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A init() 0 9 1
A make() 0 5 2
1
<?php
2
3
namespace Isswp101\Persimmon\DI;
4
5
use Elasticsearch\ClientBuilder;
6
use Isswp101\Persimmon\Repository\ElasticsearchRepository;
7
8
final class DI
9
{
10
    const ELASTICSEARCH = 'elasticsearch';
11
12
    private static $containers = [];
13
14
    private static function init(): array
15
    {
16
        return DI::$containers = [
17
            DI::ELASTICSEARCH => function () {
18
                $client = ClientBuilder::create()->build();
19
                return new Container(new ElasticsearchRepository($client));
0 ignored issues
show
Bug introduced by
The call to Container::__construct() misses a required argument $cache.

This check looks for function calls that miss required arguments.

Loading history...
20
            }
21
        ];
22
    }
23
24
    public static function make(string $name): Container
25
    {
26
        $containers = !DI::$containers ? DI::init() : DI::$containers;
27
        return $containers[$name]();
28
    }
29
}