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

ContainerAwareTrait::containerGet()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 5
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 2
crap 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