Passed
Push — master ( bacd56...58ea89 )
by Korotkov
02:35 queued 01:20
created

InstantiationsTrait::serviceCreation()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
c 0
b 0
f 0
nc 2
nop 3
dl 0
loc 8
rs 10
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
14
    private function containerize(string $name, string $instance, $data = [])
15
    {
16
        if (!array_key_exists($name, $this->containers)) {
17
            $this->containers[$name] = new $instance($data);
18
        }
19
20
        return $this->containers[$name];
21
    }
22
23
    private function serviceCreation(string $name, string $instance = null, $data = [])
24
    {
25
        $instance ??= $name;
26
        if (!array_key_exists($name, $this->services)) {
27
            $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

27
            $this->/** @scrutinizer ignore-call */ 
28
                   set([$name, [$instance, $data]]);
Loading history...
28
        }
29
30
        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

30
        return $this->/** @scrutinizer ignore-call */ get($instance);
Loading history...
31
    }
32
}
33