Dispatcher::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Buttress\Concrete\Route;
4
5
use FastRoute\RouteCollector as Collector;
6
use function FastRoute\simpleDispatcher;
7
8
/**
9
 * A Dispatcher wrapper that adjusts the API to work with CLI
10
 */
11
class Dispatcher
12
{
13
14 6
    public function __construct(\FastRoute\Dispatcher $dispatcher)
15
    {
16 6
        $this->dispatcher = $dispatcher;
0 ignored issues
show
Bug introduced by
The property dispatcher does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
17 6
    }
18
19
    /**
20
     * Dispatches against the provided HTTP method verb and URI.
21
     *
22
     * Returns array with one of the following formats:
23
     *
24
     *     [self::NOT_FOUND]
25
     *     [self::METHOD_NOT_ALLOWED, ['GET', 'OTHER_ALLOWED_METHODS']]
26
     *     [self::FOUND, $handler, ['varName' => 'value', ...]]
27
     *
28
     * @param string $command
29
     *
30
     * @return array
31
     */
32 3
    public function dispatch($command)
33
    {
34 3
        return $this->dispatcher->dispatch('get', $command);
35
    }
36
37
    /**
38
     * Get a new instance of dispatcher
39
     * @param callable $routeDefinitionCallback
40
     * @param array $options
41
     * @return static
42
     */
43
    public static function simpleDispatcher(callable $routeDefinitionCallback, array $options = [])
44
    {
45 3
        return new static(simpleDispatcher(function (Collector $collector) use ($routeDefinitionCallback) {
46 3
            return $routeDefinitionCallback(new RouteCollector($collector));
47 3
        }, $options));
48
    }
49
}
50