Conditions | 2 |
Paths | 2 |
Total Lines | 58 |
Code Lines | 26 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
23 | public function testStoreRetrieve() |
||
24 | { |
||
25 | // creating - retrieving array |
||
26 | $arrayExpected = ['c' => 'cc', 'b' => 'bb', 'a' => 'aa', ]; |
||
27 | |||
28 | CommonData::newArray('abc/def', $arrayExpected); |
||
29 | |||
30 | $arrayActual = CommonData::getArray('abc/def'); |
||
31 | |||
32 | $this->assertEquals($arrayExpected, $arrayActual, 'Problem retrieving commondata sorted by position!'); |
||
33 | |||
34 | // retrieving sorted array by key |
||
35 | $arraySortKey = $arrayExpected; |
||
36 | ksort($arraySortKey); |
||
37 | |||
38 | $this->assertEquals($arraySortKey, CommonData::getArray('abc/def', 'key'), 'Problem retrieving commondata sorted by key!'); |
||
39 | |||
40 | // retrieving sorted array by value |
||
41 | $arraySortValue = $arrayExpected; |
||
42 | sort($arraySortValue); |
||
43 | |||
44 | $this->assertEquals($arraySortKey, CommonData::getArray('abc/def', 'value'), 'Problem retrieving commondata sorted by value!'); |
||
45 | |||
46 | // retrieving array value |
||
47 | $valueActual = CommonData::getValue('abc/def/a'); |
||
48 | |||
49 | $this->assertEquals($arrayExpected['a'], $valueActual, 'Problem retrieving commondata value!'); |
||
50 | |||
51 | // setting array values |
||
52 | $arrayChanged = ['a' => 'aaa', 'b' => 'bbb', 'c' => 'ccc']; |
||
53 | |||
54 | foreach ($arrayChanged as $key => $value) { |
||
55 | CommonData::setValue('abc/def/' . $key, $value); |
||
56 | } |
||
57 | |||
58 | $arrayActual = CommonData::getArray('abc/def'); |
||
59 | |||
60 | $this->assertEquals($arrayChanged, $arrayActual, 'Problem setting commondata value!'); |
||
61 | |||
62 | // deleting array node |
||
63 | unset($arrayChanged['a']); |
||
64 | |||
65 | CommonData::deleteArray('abc/def/a'); |
||
66 | |||
67 | $arrayActual = CommonData::getArray('abc/def'); |
||
68 | |||
69 | $this->assertEquals($arrayChanged, $arrayActual, 'Problem deleting commondata node!'); |
||
70 | |||
71 | // extending array |
||
72 | $arrayExtension = ['a' => 'aaa']; |
||
73 | |||
74 | $arrayChanged = array_merge($arrayChanged, $arrayExtension); |
||
75 | |||
76 | CommonData::extendArray('abc/def', $arrayExtension); |
||
77 | |||
78 | $arrayActual = CommonData::getArray('abc/def'); |
||
79 | |||
80 | $this->assertEquals($arrayChanged, $arrayActual, 'Problem extending commondata array!'); |
||
81 | } |
||
124 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.