AdjacentLocator   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 2
Bugs 1 Features 0
Metric Value
wmc 3
c 2
b 1
f 0
lcom 0
cbo 2
dl 0
loc 38
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getHandlerForCommand() 0 10 2
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