Total Complexity | 4 |
Total Lines | 40 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 0 |
1 | <?php |
||
20 | class Container extends Pimple implements ContainerInterface |
||
21 | { |
||
22 | |||
23 | |||
24 | /** |
||
25 | * Finds an entry of the container by its identifier and returns it. |
||
26 | * |
||
27 | * @param string $id Identifier of the entry to look for. |
||
28 | * |
||
29 | * @return mixed Entry. |
||
30 | * @throws ContainerExceptionInterface Error while retrieving the entry. |
||
31 | * |
||
32 | * @throws NotFoundExceptionInterface No entry was found for **this** identifier. |
||
33 | */ |
||
34 | 3 | public function get($id) |
|
35 | { |
||
36 | try { |
||
37 | 3 | $item = $this->offsetGet($id); |
|
38 | 1 | return $item; |
|
39 | 2 | } catch (UnknownIdentifierException $e) { |
|
40 | 1 | throw new NotFoundException("Key $id not found."); |
|
41 | 1 | } catch (Exception $e) { |
|
42 | 1 | throw new ContainerException("Problem fetching key $id.\n" . $e->getMessage(), $e->getCode()); |
|
43 | } |
||
44 | } |
||
45 | |||
46 | /** |
||
47 | * Returns true if the container can return an entry for the given identifier. |
||
48 | * Returns false otherwise. |
||
49 | * |
||
50 | * `has($id)` returning true does not mean that `get($id)` will not throw an exception. |
||
51 | * It does however mean that `get($id)` will not throw a `NotFoundExceptionInterface`. |
||
52 | * |
||
53 | * @param string $id Identifier of the entry to look for. |
||
54 | * |
||
55 | * @return bool |
||
56 | */ |
||
57 | 1 | public function has($id) |
|
60 | } |
||
61 | |||
63 |