Container   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 5
lcom 1
cbo 3
dl 0
loc 61
ccs 20
cts 20
cp 1
rs 10
c 2
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A get() 0 22 3
A has() 0 12 1
1
<?php
2
/**
3
 * @author @shochdoerfer <[email protected]>
4
 * @created 18.10.15, 12:14
5
 */
6
namespace Fabfuel\Prophiler\Adapter\Interop\Container;
7
8
use Fabfuel\Prophiler\Adapter\AdapterAbstract;
9
use Fabfuel\Prophiler\ProfilerInterface;
10
use Interop\Container\ContainerInterface;
11
12
class Container extends AdapterAbstract implements ContainerInterface
13
{
14
    /**
15
     * @var ContainerInterface
16
     */
17
    protected $container;
18
19
    /**
20
     * Creates a new {@link \Fabfuel\Prophiler\Adapter\Interop\Container\Container}.
21
     *
22
     * @param ContainerInterface $container
23
     * @param ProfilerInterface $profiler
24
     */
25 3
    public function __construct(ContainerInterface $container, ProfilerInterface $profiler)
26
    {
27 3
        parent::__construct($profiler);
28 3
        $this->container = $container;
29 3
    }
30
31
    /**
32
     * {@inheritdoc}
33
     */
34 2
    public function get($id)
35
    {
36 2
        $entry = null;
37
        $metadata = [
38
            'id' => $id
39 2
        ];
40
41
        try {
42 2
            $benchmark = $this->profiler->start('Container::get', $metadata, 'Container-Interop');
43 2
            $entry = $this->container->get($id);
44 2
        } catch (\Exception $e) {
45
            // exception needs to be catched and thrown after stopping the profiler
46
        }
47
48 2
        $this->profiler->stop($benchmark);
49
50 2
        if (isset($e)) {
51 1
            throw $e;
52
        }
53
54 1
        return $entry;
55
    }
56
57
    /**
58
     * {@inheritdoc}
59
     */
60 1
    public function has($id)
61
    {
62
        $metadata = [
63
            'id' => $id
64 1
        ];
65 1
        $benchmark = $this->profiler->start('Container::has', $metadata, 'Container-Interop');
66
67 1
        $has = $this->container->has($id);
68
69 1
        $this->profiler->stop($benchmark);
70 1
        return $has;
71
    }
72
}
73