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 |
||
28 | public function testStoreRetrieve() |
||
29 | { |
||
30 | // creating - retrieving array |
||
31 | $arrayExpected = ['c' => 'cc', 'b' => 'bb', 'a' => 'aa', ]; |
||
32 | |||
33 | CommonData::newArray('abc/def', $arrayExpected); |
||
34 | |||
35 | $arrayActual = CommonData::getArray('abc/def'); |
||
36 | |||
37 | $this->assertEquals($arrayExpected, $arrayActual, 'Problem retrieving commondata sorted by position!'); |
||
38 | |||
39 | // retrieving sorted array by key |
||
40 | $arraySortKey = $arrayExpected; |
||
41 | ksort($arraySortKey); |
||
42 | |||
43 | $this->assertEquals($arraySortKey, CommonData::getArray('abc/def', 'key'), 'Problem retrieving commondata sorted by key!'); |
||
44 | |||
45 | // retrieving sorted array by value |
||
46 | $arraySortValue = $arrayExpected; |
||
47 | sort($arraySortValue); |
||
48 | |||
49 | $this->assertEquals($arraySortKey, CommonData::getArray('abc/def', 'value'), 'Problem retrieving commondata sorted by value!'); |
||
50 | |||
51 | // retrieving array value |
||
52 | $valueActual = CommonData::getValue('abc/def/a'); |
||
53 | |||
54 | $this->assertEquals($arrayExpected['a'], $valueActual, 'Problem retrieving commondata value!'); |
||
55 | |||
56 | // setting array values |
||
57 | $arrayChanged = ['a' => 'aaa', 'b' => 'bbb', 'c' => 'ccc']; |
||
58 | |||
59 | foreach ($arrayChanged as $key => $value) { |
||
60 | CommonData::setValue('abc/def/' . $key, $value); |
||
61 | } |
||
62 | |||
63 | $arrayActual = CommonData::getArray('abc/def'); |
||
64 | |||
65 | $this->assertEquals($arrayChanged, $arrayActual, 'Problem setting commondata value!'); |
||
66 | |||
67 | // deleting array node |
||
68 | unset($arrayChanged['a']); |
||
69 | |||
70 | CommonData::deleteArray('abc/def/a'); |
||
71 | |||
72 | $arrayActual = CommonData::getArray('abc/def'); |
||
73 | |||
74 | $this->assertEquals($arrayChanged, $arrayActual, 'Problem deleting commondata node!'); |
||
75 | |||
76 | // extending array |
||
77 | $arrayExtension = ['a' => 'aaa']; |
||
78 | |||
79 | $arrayChanged = array_merge($arrayChanged, $arrayExtension); |
||
80 | |||
81 | CommonData::extendArray('abc/def', $arrayExtension); |
||
82 | |||
83 | $arrayActual = CommonData::getArray('abc/def'); |
||
84 | |||
85 | $this->assertEquals($arrayChanged, $arrayActual, 'Problem extending commondata array!'); |
||
86 | } |
||
106 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.