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.

CallbackOnMissContainer   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 4
c 2
b 0
f 0
lcom 1
cbo 2
dl 0
loc 32
ccs 11
cts 11
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 2
A get() 0 8 2
1
<?php
2
3
namespace Acclimate\Container\Decorator;
4
5
use Interop\Container\ContainerInterface;
6
use Interop\Container\Exception\NotFoundException;
7
8
/**
9
 * A container decorator that changes the default behavior of throwing an exception when an item doesn't exist in the
10
 * container to instead execute a callback function
11
 */
12
class CallbackOnMissContainer extends AbstractContainerDecorator
13
{
14
    /**
15
     * @var callback A callback function
16
     */
17
    private $callback;
18
19
    /**
20
     * @param ContainerInterface $container The container being decorated
21
     * @param callable           $callback  A callback function to be executed if an item in the container doesn't exist
22
     *
23
     * @throws \InvalidArgumentException
24
     */
25 2
    public function __construct(ContainerInterface $container, $callback)
26
    {
27 2
        parent::__construct($container);
28 2
        if (is_callable($callback)) {
29 1
            $this->callback = $callback;
30 1
        } else {
31 1
            throw new \InvalidArgumentException('The callback provided was not callable.');
32
        }
33 1
    }
34
35 1
    public function get($id)
36
    {
37
        try {
38 1
            return $this->container->get($id);
39 1
        } catch (NotFoundException $e) {
40 1
            return call_user_func($this->callback, $id);
41
        }
42
    }
43
}
44