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.
Completed
Pull Request — master (#6)
by Koldo
15:07
created

LaravelLazyLocator::addHandlers()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 6
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 6
loc 6
ccs 0
cts 5
cp 0
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 3
nc 2
nop 1
crap 6
1
<?php
2
3
namespace Joselfonseca\LaravelTactician\Locator;
4
5
use League\Tactician\Exception\MissingHandlerException;
6
7 View Code Duplication
class LaravelLazyLocator implements LocatorInterface
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
8
{
9
10
    /**
11
     * The handlers
12
     * @var
13
     */
14
    protected $handlers;
15
16
    /**
17
     * Bind a handler instance to receive all commands with a certain class
18
     *
19
     * @param string $handler          Handler to receive class name
20
     * @param string $commandClassName Command class e.g. "My\TaskAddedCommand"
21
     */
22
    public function addHandler($handler, $commandClassName)
23
    {
24
        $this->handlers[$commandClassName] = function () use ($handler) {
25
            return app($handler);
26
        };
27
    }
28
29
    /**
30
     * Allows you to add multiple handlers at once.
31
     *
32
     * The map should be an array in the format of:
33
     *  [
34
     *      AddTaskCommand::class      => $someHandlerClassName,
35
     *      CompleteTaskCommand::class => $someHandlerClassName,
36
     *  ]
37
     *
38
     * @param array $commandClassToHandlerMap
39
     */
40
    public function addHandlers(array $commandClassToHandlerMap)
41
    {
42
        foreach ($commandClassToHandlerMap as $commandClass => $handler) {
43
            $this->addHandler($handler, $commandClass);
44
        }
45
    }
46
47
    /**
48
     * Retrieves the handler for a specified command
49
     *
50
     * @param string $commandName
51
     *
52
     * @return object
53
     *
54
     * @throws MissingHandlerException
55
     */
56
    public function getHandlerForCommand($commandName)
57
    {
58
        if (!isset($this->handlers[$commandName])) {
59
            throw MissingHandlerException::forCommand($commandName);
60
        }
61
62
        return $this->handlers[$commandName]();
63
    }
64
}
65