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::get()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 8
ccs 4
cts 4
cp 1
rs 9.4285
cc 2
eloc 5
nc 2
nop 1
crap 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