ContainerAwareTrait   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 1 Features 0
Metric Value
wmc 6
eloc 9
c 2
b 1
f 0
dl 0
loc 31
ccs 12
cts 12
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A containerGet() 0 5 3
A getContainer() 0 3 1
A setContainer() 0 5 1
A __construct() 0 3 1
1
<?php
2
3
/*
4
 * This file is part of the uSilex framework.
5
 *
6
 * (c) Enrico Fagnoni <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace uSilex;
13
14
use Psr\Container\ContainerInterface;
15
use Pimple\Container as PimpleContainer;
16
17
/**
18
 * Psr11 trait. Realize a Container aware interfce from a pimple container
19
 *
20
 * @author Enrico Fagnoni <[email protected]>
21
 */
22
trait ContainerAwareTrait
23
{
24
    private $container = null;
25
    
26 2
    public function __construct(ContainerInterface $container = null)
27
    {
28 2
        $this->container = $container;
29 2
    }
30
    
31 1
    public function getContainer() : ContainerInterface
32
    {
33 1
        return $this->container;
34
    }
35
    
36
    
37 1
    public function setContainer(ContainerInterface $container) : self
38
    {
39 1
        $this->container = $container;
40
        
41 1
        return $this;
42
    }
43
    
44
    
45
    /**
46
     * A shortcut to get a value with a default
47
     */
48 2
    public function containerGet(String $id, $value = null)
49
    {
50 2
        return ($this->container && $this->container->has($id))
51 1
            ? $this->container->get($id)
52 2
            : $value;
53
    }
54
}
55