Conditions | 14 |
Paths | 257 |
Total Lines | 56 |
Code Lines | 40 |
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 |
||
27 | protected function getChannelData() |
||
28 | { |
||
29 | $xls = $this->getExcelObject(); |
||
30 | $data = [ 'attributes' => [] ]; |
||
31 | $attributeLabels = []; |
||
32 | $channelLabels = []; |
||
33 | $labelLocales = []; |
||
34 | $codeColumn = null; |
||
35 | $useAsLabelColumn = null; |
||
36 | $channelColumn = null; |
||
37 | $rowIterator = $xls->createRowIterator($this->worksheetIterator->key(), $this->options['parser_options']); |
||
38 | |||
39 | foreach ($rowIterator as $index => $row) { |
||
40 | if ($index == $this->options['code_row']) { |
||
41 | $data['code'] = $row[$this->options['code_column']]; |
||
42 | } |
||
43 | if ($index == $this->options['attribute_label_row']) { |
||
44 | $attributeLabels = $row; |
||
45 | $channelColumn = count($attributeLabels); |
||
46 | array_splice($channelLabels, 0, $channelColumn); |
||
47 | $data['requirements'] = array_fill_keys($channelLabels, []); |
||
48 | $codeColumn = array_search('code', $attributeLabels); |
||
49 | $useAsLabelColumn = array_search('use_as_label', $attributeLabels); |
||
50 | } |
||
51 | if ($index == $this->options['channel_label_row']) { |
||
52 | $channelLabels = $row; |
||
53 | } |
||
54 | if ($index == $this->options['labels_label_row']) { |
||
55 | $labelLocales = array_slice($row, $this->options['labels_column']); |
||
56 | } |
||
57 | if ($index == $this->options['labels_data_row']) { |
||
58 | $data['labels'] = $this->getArrayHelper()->combineArrays( |
||
59 | $labelLocales, |
||
60 | array_slice($row, $this->options['labels_column']) |
||
61 | ); |
||
62 | } |
||
63 | if ($index >= (int) $this->options['attribute_data_row']) { |
||
64 | $code = $row[$codeColumn]; |
||
65 | if ($code === '') { |
||
66 | continue; |
||
67 | } |
||
68 | $data['attributes'][] = $code; |
||
69 | if (isset($row[$useAsLabelColumn]) && ('1' === trim($row[$useAsLabelColumn]))) { |
||
70 | $data['attribute_as_label'] = $code; |
||
71 | } |
||
72 | $channelValues = array_slice($row, $channelColumn); |
||
73 | foreach ($channelLabels as $index => $channel) { |
||
74 | if (isset($channelValues[$index]) && '1' === trim($channelValues[$index])) { |
||
75 | $data['requirements'][$channel][] = $code; |
||
76 | } |
||
77 | } |
||
78 | } |
||
79 | } |
||
80 | |||
81 | return $data; |
||
82 | } |
||
83 | |||
106 |