Completed
Push — master ( 73599e...397cb1 )
by Neomerx
06:11
created

Container   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 7
c 2
b 0
f 0
lcom 1
cbo 2
dl 0
loc 50
ccs 17
cts 17
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A get() 0 8 2
A has() 0 4 1
A registerDestructor() 0 4 1
A __destruct() 0 9 3
1
<?php namespace Limoncello\ContainerLight;
2
3
/**
4
 * Copyright 2015-2016 [email protected] (www.neomerx.com)
5
 *
6
 * Licensed under the Apache License, Version 2.0 (the "License");
7
 * you may not use this file except in compliance with the License.
8
 * You may obtain a copy of the License at
9
 *
10
 * http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing, software
13
 * distributed under the License is distributed on an "AS IS" BASIS,
14
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
 * See the License for the specific language governing permissions and
16
 * limitations under the License.
17
 */
18
19
use Interop\Container\ContainerInterface;
20
use InvalidArgumentException;
21
use Limoncello\ContainerLight\Exceptions\NotFoundException;
22
23
/**
24
 * @package Limoncello\ContainerLight
25
 */
26
class Container extends \Pimple\Container implements ContainerInterface
27
{
28
    /**
29
     * @var callable[]|null
30
     */
31
    private $destructorHandlers = null;
32
33
    /**
34
     * @inheritdoc
35
     */
36 2
    public function get($identity)
37
    {
38
        try {
39 2
            return $this->offsetGet($identity);
40 1
        } catch (InvalidArgumentException $exception) {
41 1
            throw new NotFoundException($exception->getMessage(), $exception->getCode(), $exception);
42
        }
43
    }
44
45
    /**
46
     * @inheritdoc
47
     */
48 1
    public function has($identity)
49
    {
50 1
        return $this->offsetExists($identity);
51
    }
52
53
    /**
54
     * @param callable $handler
55
     *
56
     * @return void
57
     */
58 1
    public function registerDestructor(callable $handler)
59
    {
60 1
        $this->destructorHandlers[] = $handler;
61 1
    }
62
63
    /**
64
     * @return void
65
     */
66 3
    public function __destruct()
67
    {
68 3
        if ($this->destructorHandlers !== null) {
69 1
            foreach ($this->destructorHandlers as $handler) {
70 1
                call_user_func($handler);
71 1
            }
72 1
            unset($this->destructorHandlers);
73 1
        }
74 3
    }
75
}
76