AdjacentLocator::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace TillKruss\LaravelTactician\Locators;
4
5
use Illuminate\Contracts\Container\Container;
6
use League\Tactician\Handler\Locator\HandlerLocator;
7
use League\Tactician\Exception\MissingHandlerException;
8
9
class AdjacentLocator implements HandlerLocator
10
{
11
    /**
12
     * The container instance.
13
     *
14
     * @var \Illuminate\Contracts\Container\Container
15
     */
16
    protected $container;
17
18
    /**
19
     * Create a new adjacent locator instance.
20
     *
21
     * @param \Illuminate\Contracts\Container\Container  $container
22
     */
23
    public function __construct(Container $container)
24
    {
25
        $this->container = $container;
26
    }
27
28
    /**
29
     * Returns the handler located in the same directory for a specified command.
30
     *
31
     * @param  string  $command
32
     * @return object
33
     *
34
     * @throws \League\Tactician\Exception\MissingHandlerException
35
     */
36
    public function getHandlerForCommand($command)
37
    {
38
        $handler = substr_replace($command, 'CommandHandler', strrpos($command, 'Command'));
39
40
        if (! class_exists($handler)) {
41
            throw MissingHandlerException::forCommand($command);
42
        }
43
44
        return $this->container->make($handler);
45
    }
46
}
47