Test Failed
Pull Request — master (#97)
by Gildonei
03:38
created

CallableParser::addParamsPath()   B

Complexity

Conditions 7
Paths 5

Size

Total Lines 25
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 20.4566

Importance

Changes 0
Metric Value
cc 7
eloc 20
nc 5
nop 3
dl 0
loc 25
ccs 7
cts 20
cp 0.35
crap 20.4566
rs 8.6666
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * Cache parsers
5
 */
6
namespace Ubiquity\cache\parser;
7
8
use Ubiquity\utils\base\UString;
9
10
/**
11
 * Ubiquity\cache\parser$CallableParser
12
 * This class is part of Ubiquity
13
 *
14
 * @author jcheron <[email protected]>
15
 * @version 1.0.1
16
 *
17
 */
18
class CallableParser {
19
20 37
	public static function parseRouteArray(&$result, $callable, $routeArray, \ReflectionFunction $function, $prefix = "", $httpMethods = NULL) {
21 37
		$pathParameters = ControllerParser::addParamsPath ( $routeArray ["path"], $function, $routeArray ["requirements"] );
22 37
		$name = $routeArray ["name"];
23 37
		if (! isset ( $name )) {
24
			$name = UString::cleanAttribute ( $pathParameters );
25
		}
26 37
		$cache = $routeArray ["cache"];
27 37
		$duration = $routeArray ["duration"];
28 37
		$path = $pathParameters ["path"];
29 37
		$parameters = $pathParameters ["parameters"];
30 37
		$priority = $routeArray ["priority"];
31 37
		$path = ControllerParser::cleanpath ( $prefix, $path );
32 37
		if (isset ( $routeArray ["methods"] ) && \is_array ( $routeArray ["methods"] )) {
33 37
			self::createRouteMethod ( $result, $callable, $path, $routeArray ["methods"], $parameters, $name, $cache, $duration, $priority );
34
		} elseif (\is_array ( $httpMethods )) {
35
			self::createRouteMethod ( $result, $callable, $path, $httpMethods, $parameters, $name, $cache, $duration, $priority );
36
		} else {
37
			$result [$path] = [ "controller" => $callable,"action" => "","parameters" => $parameters,"name" => $name,"cache" => $cache,"duration" => $duration,"priority" => $priority ];
38
		}
39 37
	}
40
41 37
	private static function createRouteMethod(&$result, $callable, $path, $httpMethods, $parameters, $name, $cache, $duration, $priority) {
42 37
		foreach ( $httpMethods as $httpMethod ) {
43 37
			$result [$path] [$httpMethod] = [ "controller" => $callable,"action" => "","parameters" => $parameters,"name" => $name,"cache" => $cache,"duration" => $duration,"priority" => $priority ];
44
		}
45 37
	}
46
}
47
48