| Conditions | 5 |
| Paths | 4 |
| Total Lines | 69 |
| Code Lines | 43 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
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 declare(strict_types=1); |
||
| 17 | public function render(array $parameters, HTMLNode $previous): HTMLNode |
||
| 18 | { |
||
| 19 | $headrows = []; |
||
| 20 | $footrows = []; |
||
| 21 | if (array_key_exists(self::ROW_NAMES, $parameters)) { |
||
| 22 | foreach ($parameters[self::ROW_NAMES] as $rowname) { |
||
| 23 | $headrows[] = HTMLNode::factory( |
||
| 24 | 'th', |
||
| 25 | [ |
||
| 26 | 'class' => 'formularium-table__th' |
||
| 27 | ], |
||
| 28 | $rowname |
||
| 29 | ); |
||
| 30 | $footrows[] = HTMLNode::factory( |
||
| 31 | 'th', |
||
| 32 | [ |
||
| 33 | 'class' => 'formularium-table__th' |
||
| 34 | ], |
||
| 35 | $rowname |
||
| 36 | ); |
||
| 37 | } |
||
| 38 | } |
||
| 39 | |||
| 40 | $rowdata = []; |
||
| 41 | if (array_key_exists(self::ROW_DATA, $parameters)) { |
||
| 42 | foreach ($parameters[self::ROW_DATA] as $data) { |
||
| 43 | $rowdata[] = HTMLNode::factory( |
||
| 44 | 'tr', |
||
| 45 | [ |
||
| 46 | 'class' => 'formularium-table__td' |
||
| 47 | ], |
||
| 48 | array_map( |
||
| 49 | function ($i) { |
||
| 50 | return HTMLNode::factory('td', [], $i); |
||
| 51 | }, |
||
| 52 | $data |
||
| 53 | ) |
||
| 54 | ); |
||
| 55 | } |
||
| 56 | } |
||
| 57 | |||
| 58 | return HTMLNode::factory( |
||
| 59 | 'table', |
||
| 60 | [ |
||
| 61 | 'class' => 'formularium-table' |
||
| 62 | ], |
||
| 63 | [ |
||
| 64 | HTMLNode::factory( |
||
| 65 | 'thead', |
||
| 66 | ['class' => 'formularium-table__head'], |
||
| 67 | HTMLNode::factory( |
||
| 68 | 'tr', |
||
| 69 | ['class' => 'formularium-table__headrow'], |
||
| 70 | $headrows |
||
| 71 | ), |
||
| 72 | ), |
||
| 73 | HTMLNode::factory( |
||
| 74 | 'tfoot', |
||
| 75 | ['class' => 'formularium-table__foot'], |
||
| 76 | HTMLNode::factory( |
||
| 77 | 'tr', |
||
| 78 | ['class' => 'formularium-table__footrow'], |
||
| 79 | $footrows |
||
| 80 | ), |
||
| 81 | ), |
||
| 82 | HTMLNode::factory( |
||
| 83 | 'tbody', |
||
| 84 | ['class' => 'formularium-table__body'], |
||
| 85 | $rowdata |
||
| 86 | ) |
||
| 116 |