Passed
Pull Request — master (#9)
by Pavel
12:36
created

MatcherDumper   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 49
c 0
b 0
f 0
wmc 2
lcom 0
cbo 3
ccs 12
cts 12
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B dump() 0 40 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