ContainerAdapter   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 75
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 75
rs 10
c 0
b 0
f 0
wmc 9

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A setContainer() 0 3 1
A get() 0 3 1
A has() 0 3 1
A set() 0 3 1
A make() 0 3 1
A call() 0 9 3
1
<?php
2
3
namespace WebComplete\core\utils\container;
4
5
class ContainerAdapter implements ContainerInterface
6
{
7
    private $container;
8
9
    /**
10
     * @param object $container
11
     */
12
    public function __construct($container = null)
13
    {
14
        $this->container = $container;
15
    }
16
17
    /**
18
     * @param object $container
19
     */
20
    public function setContainer($container)
21
    {
22
        $this->container = $container;
23
    }
24
25
    /**
26
     * @param string $id
27
     * @return mixed
28
     * @throws ContainerException
29
     */
30
    public function get($id)
31
    {
32
        return $this->call('get', $id);
33
    }
34
35
    /**
36
     * @param $id
37
     * @param $value
38
     */
39
    public function set($id, $value)
40
    {
41
        $this->container->set($id, $value);
0 ignored issues
show
Bug introduced by
The method set() does not exist on null. ( Ignorable by Annotation )

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

41
        $this->container->/** @scrutinizer ignore-call */ 
42
                          set($id, $value);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
42
    }
43
44
    /**
45
     * @param string $id
46
     * @return mixed
47
     * @throws ContainerException
48
     */
49
    public function has($id)
50
    {
51
        return $this->call('has', $id);
52
    }
53
54
    /**
55
     * @param $id
56
     * @return mixed
57
     * @throws ContainerException
58
     */
59
    public function make($id)
60
    {
61
        return $this->call('make', $id);
62
    }
63
64
    /**
65
     * @param $method
66
     * @param $id
67
     *
68
     * @return mixed
69
     * @throws ContainerException
70
     */
71
    protected function call($method, $id)
72
    {
73
        if (!$this->container) {
74
            throw new ContainerException('Container not injected');
75
        }
76
        if (\method_exists($this->container, $method)) {
77
            return $this->container->$method($id);
78
        }
79
        throw new ContainerException('Container method not found: ' . $method);
80
    }
81
}
82