Passed
Push — master ( 85042a...341233 )
by Enrico
02:38
created

ContainerAwareTrait   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getContainer() 0 3 1
A setContainer() 0 5 1
A __construct() 0 3 1
A containerGet() 0 5 2
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
/**
19
 * Psr11 trait. Realize a Container aware interfce from a pimple container
20
 *
21
 * @author Enrico Fagnoni <[email protected]>
22
 */
23
trait ContainerAwareTrait
24
{
25
    private $container;
26
    
27 1
    public function __construct(ContainerInterface $container = null)
28
    {
29 1
        $this->container = $container;
30 1
    }
31
    
32 1
    public function getContainer() : ContainerInterface 
33
    {
34 1
        return $this->container;
35
    }
36
    
37
    
38 1
    public function setContainer(ContainerInterface $container) : self 
39
    {
40 1
        $this->container = $container;
41
        
42 1
        return $this;
43
    }
44
    
45
    
46
    /**
47
     * A shortcut to get a value with a default
48
     */
49 1
    public function containerGet(String $id, $value=null)
50
    {
51 1
        return $this->container->has($id)
52 1
        ?$this->container->get($id)
53 1
        :$value;
54
    }
55
}
56