GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

ArrayContainer   A
last analyzed

Complexity

Total Complexity 14

Size/Duplication

Total Lines 71
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 14
c 3
b 0
f 0
lcom 1
cbo 2
dl 0
loc 71
ccs 31
cts 31
cp 1
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
B __construct() 0 11 5
A get() 0 15 4
A has() 0 4 1
A offsetExists() 0 4 1
A offsetGet() 0 4 1
A offsetUnset() 0 4 1
A offsetSet() 0 4 1
1
<?php
2
3
namespace Acclimate\Container;
4
5
use Interop\Container\ContainerInterface;
6
use Acclimate\Container\Exception\ContainerException;
7
use Acclimate\Container\Exception\NotFoundException;
8
9
/**
10
 * The Array Container is a simple container that follows both the `ContainerInterface` and `ArrayAccess` interface.
11
 * The container can be seeded with an array or array-like object. The "get" functionality will evaluate closures and
12
 * cache results.
13
 */
14
class ArrayContainer implements ContainerInterface, \ArrayAccess
15
{
16
    /**
17
     * @var array|\ArrayAccess The container data
18
     */
19
    protected $data;
20
    
21
    /**
22
     * @var ContainerInterface The container that will be used for dependency lookups
23
     */
24
    protected $delegateLookupContainer;
25
26
    /**
27
     * @param array|\ArrayAccess|\Traversable $data Data for the container
28
     * @param ContainerInterface $delegateLookupContainer The container that will be used for dependency lookups.
29
     *
30
     * @throws \InvalidArgumentException if the provided data is not an array or array-like object
31
     */
32 7
    public function __construct($data = array(), $delegateLookupContainer = null)
33
    {
34 7
        if (is_array($data) || $data instanceof \ArrayAccess) {
35 7
            $this->data = $data;
36 7
        } elseif ($data instanceof \Traversable) {
37 1
            $this->data = iterator_to_array($data, true);
38 1
        } else {
39 1
            throw new \InvalidArgumentException('The ArrayContainer requires either an array or an array-like object');
40
        }
41 7
        $this->delegateLookupContainer = $delegateLookupContainer ?: $this;
42 7
    }
43
44 6
    public function get($id)
45
    {
46 6
        if (isset($this->data[$id])) {
47
            try {
48 5
                if ($this->data[$id] instanceof \Closure) {
49 3
                    $this->data[$id] = call_user_func($this->data[$id], $this->delegateLookupContainer);
50 2
                }
51 5
            } catch (\Exception $prev) {
52 1
                throw ContainerException::fromPrevious($id, $prev);
53
            }
54 4
            return $this->data[$id];
55
        } else {
56 1
            throw NotFoundException::fromPrevious($id);
57
        }
58
    }
59
60 2
    public function has($identifier)
61
    {
62 2
        return isset($this->data[$identifier]);
63
    }
64
65 1
    public function offsetExists($offset)
66
    {
67 1
        return isset($this->data[$offset]);
68
    }
69
70 2
    public function offsetGet($offset)
71
    {
72 2
        return $this->get($offset);
73
    }
74
75 3
    public function offsetSet($offset, $value)
76 1
    {
77 3
        $this->data[$offset] = $value;
78 3
    }
79
80 1
    public function offsetUnset($offset)
81
    {
82 1
        unset($this->data[$offset]);
83 1
    }
84
}
85