Conditions | 1 |
Paths | 1 |
Total Lines | 68 |
Code Lines | 44 |
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 |
||
79 | public function arrayAddColor(): array |
||
80 | { |
||
81 | $this->setUpWorkbook(); |
||
82 | |||
83 | $workbookReflection = new ReflectionClass(Workbook::class); |
||
84 | $propertyPalette = $workbookReflection->getProperty('palette'); |
||
85 | $propertyPalette->setAccessible(true); |
||
86 | |||
87 | $palette = $propertyPalette->getValue($this->workbook); |
||
88 | self::assertIsArray($palette); |
||
89 | |||
90 | $newColor1 = [0x00, 0x00, 0x01, 0x00]; |
||
91 | $newColor2 = [0x00, 0x00, 0x02, 0x00]; |
||
92 | $newColor3 = [0x00, 0x00, 0x03, 0x00]; |
||
93 | |||
94 | // Add one new color |
||
95 | $paletteTestOne = $palette; |
||
96 | $paletteTestOne[8] = $newColor1; |
||
97 | |||
98 | // Add one new color + one existing color after index 8 |
||
99 | $paletteTestTwo = $paletteTestOne; |
||
100 | |||
101 | // Add one new color + one existing color before index 9 |
||
102 | $paletteTestThree = $paletteTestOne; |
||
103 | $paletteTestThree[9] = $palette[8]; |
||
104 | |||
105 | // Add three new color |
||
106 | $paletteTestFour = $palette; |
||
107 | $paletteTestFour[8] = $newColor1; |
||
108 | $paletteTestFour[9] = $newColor2; |
||
109 | $paletteTestFour[10] = $newColor3; |
||
110 | |||
111 | // Add all existing color |
||
112 | $colorsAdd = array_map([$this, 'paletteToColor'], $palette); |
||
113 | $paletteTestFive = $palette; |
||
114 | |||
115 | // Add new color after all existing color |
||
116 | $colorsAddTwo = array_map([$this, 'paletteToColor'], $palette); |
||
117 | $colorsAddTwo[] = $this->paletteToColor($newColor1); |
||
118 | $paletteTestSix = $palette; |
||
119 | |||
120 | // Add one existing color |
||
121 | $paletteTestSeven = $palette; |
||
122 | |||
123 | // Add two existing color |
||
124 | $paletteTestHeight = $palette; |
||
125 | |||
126 | // Add last existing color and add one new color |
||
127 | $keyPalette = array_keys($palette); |
||
128 | $last = end($keyPalette); |
||
129 | self::assertIsArray($palette[8]); |
||
130 | self::assertIsArray($palette[10]); |
||
131 | self::assertIsArray($palette[12]); |
||
132 | self::assertIsArray($palette[25]); |
||
133 | self::assertIsArray($palette[$last]); |
||
134 | $lastColor = $this->paletteToColor($palette[$last]); |
||
135 | $paletteTestNine = $palette; |
||
136 | |||
137 | return [ |
||
138 | [[$this->paletteToColor($newColor1)], $paletteTestOne], |
||
139 | [[$this->paletteToColor($newColor1), $this->paletteToColor($palette[12])], $paletteTestTwo], |
||
140 | [[$this->paletteToColor($newColor1), $this->paletteToColor($palette[8])], $paletteTestThree], |
||
141 | [[$this->paletteToColor($newColor1), $this->paletteToColor($newColor2), $this->paletteToColor($newColor3)], $paletteTestFour], |
||
142 | [$colorsAdd, $paletteTestFive], |
||
143 | [$colorsAddTwo, $paletteTestSix], |
||
144 | [[$this->paletteToColor($palette[8])], $paletteTestSeven], |
||
145 | [[$this->paletteToColor($palette[25]), $this->paletteToColor($palette[10])], $paletteTestHeight], |
||
146 | [[$lastColor, $this->paletteToColor($newColor1)], $paletteTestNine], |
||
147 | ]; |
||
178 |