Passed
Push — master ( eb3555...d21945 )
by Korotkov
01:57 queued 12s
created

InstantiationsTrait::containerize()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

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