Passed
Push — master ( b9a8c8...31c054 )
by Jean-Christophe
12:35
created

CallableParser::createRouteMethod()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
c 1
b 0
f 0
dl 0
loc 3
ccs 3
cts 3
cp 1
rs 10
cc 2
nc 2
nop 9
crap 2

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

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 58
	public static function parseRouteArray(&$result, $callable, $routeArray, \ReflectionFunction $function, $prefix = "", $httpMethods = NULL) {
21 58
		$pathParameters = ControllerParser::addParamsPath ( $routeArray ["path"], $function, $routeArray ["requirements"] );
22 58
		$name = $routeArray ["name"];
23 58
		if (! isset ( $name )) {
24
			$name = UString::cleanAttribute ( $pathParameters );
25
		}
26 58
		$cache = $routeArray ["cache"];
27 58
		$duration = $routeArray ["duration"];
28 58
		$path = $pathParameters ["path"];
29 58
		$parameters = $pathParameters ["parameters"];
30 58
		$priority = $routeArray ["priority"];
31 58
		$path = ControllerParser::cleanpath ( $prefix, $path );
32 58
		if (isset ( $routeArray ["methods"] ) && \is_array ( $routeArray ["methods"] )) {
33 42
			self::createRouteMethod ( $result, $callable, $path, $routeArray ["methods"], $parameters, $name, $cache, $duration, $priority );
34 16
		} elseif (\is_array ( $httpMethods )) {
35
			self::createRouteMethod ( $result, $callable, $path, $httpMethods, $parameters, $name, $cache, $duration, $priority );
36
		} else {
37 16
			$result [$path] = [ "controller" => $callable,"action" => "","parameters" => $parameters,"name" => $name,"cache" => $cache,"duration" => $duration,"priority" => $priority ];
38
		}
39 58
	}
40
41 42
	private static function createRouteMethod(&$result, $callable, $path, $httpMethods, $parameters, $name, $cache, $duration, $priority) {
42 42
		foreach ( $httpMethods as $httpMethod ) {
43 42
			$result [$path] [$httpMethod] = [ "controller" => $callable,"action" => "","parameters" => $parameters,"name" => $name,"cache" => $cache,"duration" => $duration,"priority" => $priority ];
44
		}
45 42
	}
46
}
47
48