PHPArrayChangerHelper   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 42
Duplicated Lines 19.05 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 5
Bugs 0 Features 0
Metric Value
wmc 4
c 5
b 0
f 0
lcom 1
cbo 3
dl 8
loc 42
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getName() 0 4 1
A addRoutes() 8 8 2
A execute() 0 7 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php namespace Knot\Dict\Helpers;
2
3
use Knot\Dict\AbstractDictBody;
4
use Knot\Dict\HelperManager;
5
6
/*
7
 * This helper method's returns changed data.
8
 */
9
10
class PHPArrayChangerHelper extends AbstractPHPArrayHelper implements HelperInterface {
11
12
	public $functions = [
13
		"array_multisort",
14
		"array_pop",
15
		"array_product",
16
		"array_push",
17
		"array_rand",
18
		"array_reduce",
19
		"array_shift",
20
		"array_splice",
21
		"array_sum",
22
		"array_unshift",
23
		"array_walk_recursive",
24
		"array_walk"
25
	];
26
27
28
	public function getName()
29
	{
30
		return "phparraychangerhelper";
31
	}
32
33
34 View Code Duplication
	public function addRoutes(HelperManager $helperManager)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
35
	{
36
		foreach ($this->functions as $functionName)
37
		{
38
			$route = $this->convertPHPFunctionToRoute($functionName);
39
			$helperManager->addRoute($route, [ __CLASS__, "execute" ]);
40
		}
41
	}
42
43
44
	public static function execute(AbstractDictBody $knot, $arguments, $methodName)
45
	{
46
		$methodName = self::convertRouteToPHPFunction($methodName);
47
		$data       =& $knot->toArray();
48
49
		return call_user_func_array($methodName, array_merge([ &$data ], $arguments));
50
	}
51
}