Passed
Push — master ( a8509b...45146e )
by Arnold
03:21
created

NoInvoker   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Test Coverage

Coverage 50%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 26
ccs 2
cts 4
cp 0.5
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A generateDefault() 0 3 1
A generateInvocation() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Jasny\SwitchRoute;
6
7
/**
8
 * Null object for returning rather invoking the action or script specified by the route.
9
 */
10
class NoInvoker implements InvokerInterface
11
{
12
    /**
13
     * Generate code for a function or method class for the route.
14
     *
15
     * The argument template should have two '%s' placeholders. The first is used for the argument name, the second for
16
     *   the default value.
17
     *
18
     * @param array    $route
19
     * @param callable $genArg  Callback to generate code for arguments.
20
     * @param string   $new     PHP code to instantiate class.
21
     * @return string
22
     */
23
    public function generateInvocation(array $route, callable $genArg, string $new = '(new %s)'): string
24
    {
25
        return '[200, ' . var_export($route, true) . ', ' . $genArg(null) . ']';
26
    }
27
28
    /**
29
     * Generate standard code for when no route matches.
30
     *
31
     * @return string
32
     */
33 1
    public function generateDefault(): string
34
    {
35 1
        return 'return $allowedMethods === [] ? [404] : [405, $allowedMethods];';
36
    }
37
}
38