| Conditions | 13 |
| Paths | 129 |
| Total Lines | 62 |
| Code Lines | 42 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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 |
||
| 31 | protected function getChannelData() |
||
| 32 | { |
||
| 33 | $this->rows = $this->reader->getSheetIterator()->current()->getRowIterator(); |
||
| 34 | $this->rows->rewind(); |
||
| 35 | |||
| 36 | $data = ['attributes' => []]; |
||
| 37 | $channelLabels = []; |
||
| 38 | $labelLocales = []; |
||
| 39 | $codeColumn = null; |
||
| 40 | $useAsLabelColumn = null; |
||
| 41 | $channelColumn = null; |
||
| 42 | |||
| 43 | $arrayHelper = new ArrayHelper(); |
||
| 44 | |||
| 45 | $rowIterator = $this->rows; |
||
| 46 | |||
| 47 | foreach ($rowIterator as $index => $row) { |
||
| 48 | $row = $this->trimRight($row); |
||
| 49 | if ($index == $this->options['channel_label_row']) { |
||
| 50 | $channelLabels = $row; |
||
| 51 | } |
||
| 52 | if ($index == $this->options['family_labels_locales_row']) { |
||
| 53 | $labelLocales = array_slice($row, $this->options['family_labels_first_column']); |
||
| 54 | } |
||
| 55 | if ($index == $this->options['family_data_row']) { |
||
| 56 | $data['code'] = $row[$this->options['family_code_column']]; |
||
| 57 | $data['labels'] = $arrayHelper->combineArrays( |
||
| 58 | $labelLocales, |
||
| 59 | array_slice($row, $this->options['family_labels_first_column']) |
||
| 60 | ); |
||
| 61 | } |
||
| 62 | if ($index == $this->options['attribute_label_row']) { |
||
| 63 | $attributeLabels = $row; |
||
| 64 | $channelColumn = count($attributeLabels); |
||
| 65 | array_splice($channelLabels, 0, $channelColumn); |
||
| 66 | $data['requirements'] = array_fill_keys($channelLabels, []); |
||
| 67 | $codeColumn = array_search('code', $attributeLabels); |
||
| 68 | $useAsLabelColumn = array_search('use_as_label', $attributeLabels); |
||
| 69 | } |
||
| 70 | |||
| 71 | if ($index >= (int) $this->options['attribute_data_row']) { |
||
| 72 | $code = $row[$codeColumn]; |
||
| 73 | if ($code === '') { |
||
| 74 | continue; |
||
| 75 | } |
||
| 76 | $data['attributes'][] = $code; |
||
| 77 | if (isset($row[$useAsLabelColumn]) && ('1' === trim($row[$useAsLabelColumn]))) { |
||
| 78 | $data['attribute_as_label'] = $code; |
||
| 79 | } |
||
| 80 | $channelValues = array_slice($row, $channelColumn); |
||
| 81 | foreach ($channelLabels as $channelIndex => $channel) { |
||
| 82 | if (isset($channelValues[$channelIndex]) && '1' === trim($channelValues[$channelIndex])) { |
||
| 83 | $data['requirements'][$channel][] = $code; |
||
| 84 | } |
||
| 85 | } |
||
| 86 | } |
||
| 87 | } |
||
| 88 | |||
| 89 | $data['attributes'] = implode(',', $data['attributes']); |
||
| 90 | |||
| 91 | return $data; |
||
| 92 | } |
||
| 93 | |||
| 116 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..