Passed
Branch master (8bf58c)
by Korotkov
02:01
created

InstantiationsTrait   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Importance

Changes 6
Bugs 0 Features 4
Metric Value
eloc 10
c 6
b 0
f 4
dl 0
loc 42
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A containerize() 0 7 2
A init() 0 8 2
1
<?php
2
3
/**
4
 * @author    : Jagepard <[email protected]">
5
 * @license   https://mit-license.org/ MIT
6
 */
7
8
namespace Rudra\Container\Traits;
9
10
trait InstantiationsTrait
11
{
12
    private array $containers = [];
13
    private array $services   = [];
14
15
    /**
16
     * Creates a container instance
17
     * ----------------------------
18
     * Создает экземпляр контейнера
19
     * 
20
     * @param  string $name
21
     * @param  string $instance
22
     * @param  array  $data
23
     * @return void
24
     */
25
    private function containerize(string $name, string $instance, $data = [])
26
    {
27
        if (!array_key_exists($name, $this->containers)) {
28
            $this->containers[$name] = new $instance($data);
29
        }
30
31
        return $this->containers[$name];
32
    }
33
34
    /**
35
     * Initializes the service
36
     * -----------------------
37
     * Иницианализирует сервис
38
     * 
39
     * @param  string      $name
40
     * @param  string|null $instance
41
     * @param  array       $data
42
     * @return void
43
     */
44
    private function init(string $name, string $instance = null, $data = [])
45
    {
46
        $instance ??= $name;
47
        if (!array_key_exists($name, $this->services)) {
48
            $this->set([$name, [$instance, $data]]);
0 ignored issues
show
Bug introduced by
It seems like set() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

48
            $this->/** @scrutinizer ignore-call */ 
49
                   set([$name, [$instance, $data]]);
Loading history...
49
        }
50
51
        return $this->get($instance);
0 ignored issues
show
Bug introduced by
It seems like get() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

51
        return $this->/** @scrutinizer ignore-call */ get($instance);
Loading history...
52
    }
53
}
54