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

InstantiationsTrait   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Importance

Changes 3
Bugs 0 Features 2
Metric Value
eloc 9
c 3
b 0
f 2
dl 0
loc 21
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A containerize() 0 7 2
A serviceCreation() 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
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