Conditions | 4 |
Paths | 3 |
Total Lines | 25 |
Code Lines | 18 |
Lines | 0 |
Ratio | 0 % |
Tests | 17 |
CRAP Score | 4.0186 |
Changes | 2 | ||
Bugs | 0 | Features | 1 |
1 | <?php |
||
17 | 2 | public static function match($path, $routes) { |
|
18 | 2 | $routes = \arc\tree::expand($routes); |
|
19 | 2 | $controller = \arc\tree::dive( |
|
20 | 2 | $routes->cd($path), |
|
21 | 2 | function($node) { |
|
22 | 2 | if ( isset($node->nodeValue) ) { |
|
23 | 2 | return $node; |
|
24 | } |
||
25 | 2 | } |
|
26 | 2 | ); |
|
27 | 2 | if ( $controller ) { |
|
28 | 2 | $remainder = substr( $path, strlen($controller->getPath()) ); |
|
29 | 2 | if ( is_callable($controller->nodeValue) ) { |
|
30 | 2 | $result = call_user_func($controller->nodeValue, $remainder); |
|
31 | 2 | } else { |
|
32 | $result = $controller->nodeValue; |
||
33 | } |
||
34 | return [ |
||
35 | 2 | 'path' => $controller->getPath(), |
|
36 | 2 | 'remainder' => $remainder, |
|
37 | 'result' => $result |
||
38 | 2 | ]; |
|
39 | } |
||
40 | return false; |
||
41 | } |
||
42 | |||
43 | } |