Passed
Pull Request — master (#9)
by Pavel
11:27
created

MatcherDumper::dump()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 40
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 40
c 0
b 0
f 0
ccs 12
cts 12
cp 1
rs 8.8571
cc 2
eloc 17
nc 2
nop 2
crap 2
1
<?php
2
3
namespace Bankiru\Api\Rpc\Routing;
4
5
final class MatcherDumper
6
{
7
    /**
8
     * @param MethodCollection $collection
9
     * @param array            $options
10
     *
11
     * @return string
12
     */
13 1
    public function dump(MethodCollection $collection, array $options)
14
    {
15
        $content =
16
            <<<CONTENT
17
<?php
18
19
use Bankiru\Api\Rpc\Routing\Exception\MethodNotFoundException;
20
use Bankiru\Api\Rpc\Routing\MethodMatcher;
21
22 1
final class {$options['class']} implements MethodMatcher 
23
{
24
    /** {@inheritdoc} */
25
    public function match(\$method)
26
    {
27 1
        \$routes = [
28 1
CONTENT;
29
30 1
        foreach ($collection->all() as $name => $method) {
31 1
            $ret     = var_export(AttributesHelper::getAttributes($method, $name), true);
32 1
            $content .= PHP_EOL .
33
                        <<<CONTENT
34 1
            '{$method->getMethod()}' => {$ret},
35 1
CONTENT;
36 1
        }
37
38
        $content .=
39
            <<<CONTENT
40
        ];
41
        
42
        if (array_key_exists(\$method, \$routes)) {
43
            return \$routes[\$method];
44
        }
45
        
46
        throw new MethodNotFoundException(\$method);
47
    }
48
}
49 1
CONTENT;
50
51 1
        return $content;
52
    }
53
}
54