Completed
Push — master ( 66a152...f0c72f )
by Auke
03:39
created

route   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 90%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 4
c 1
b 0
f 1
lcom 0
cbo 2
dl 0
loc 36
ccs 18
cts 20
cp 0.9
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B match() 0 26 4
1
<?php
2
3
namespace arc;
4
/**
5
 * Class route
6
 * A simple router.
7
 * @package arc
8
 */
9
class route {
10
11
    /**
12
     * Matches a path or url to a list of routes and calls the best matching route handler.
13
     * @param string $path
14
     * @param mixed $routes A tree of routes with handlers as nodeValue.
15
     * @return array|bool
16
     */
17 2
    public static function match($path, $routes) {
18 2
        $controller = null;
0 ignored issues
show
Unused Code introduced by
$controller is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
19 2
        $routes     = \arc\tree::expand($routes);
20 2
        $controller = \arc\tree::dive(
21 2
            $routes->cd($path),
22 2
            function($node) {
23 2
                if ( isset($node->nodeValue) ) {
24 2
                    return $node;
25
                }
26 2
            }
27 2
        );
28 2
        if ( $controller ) {
29 2
            $remainder = substr( $path, strlen($controller->getPath()) );
30 2
            if ( is_callable($controller->nodeValue) ) {
31 2
                $result = call_user_func($controller->nodeValue, $remainder);
32 2
            } else {
33
                $result = $controller->nodeValue;
34
            }
35
            return [
36 2
                'path' => $controller->getPath(),
37 2
                'remainder' => $remainder,
38
                'result' => $result
39 2
            ];
40
        }
41
        return false;
42
    }
43
44
}