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

NoInvoker::generateInvocation()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 3
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
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