Conditions | 16 |
Paths | 155 |
Total Lines | 47 |
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 |
||
96 | protected function getLineIteratorWithHeaderInFirstLines() |
||
97 | { |
||
98 | $headers = array_map(array($this, 'retrieveNextCsvRow'), range(1, $this->options['skipFirstNRows'] + $this->options['combineFirstNRowsAsHeader'])); |
||
99 | $combinedHeader = null; |
||
100 | $i = 0; |
||
101 | foreach($headers as $header) { |
||
102 | if($this->options['skipFirstNRows'] > $i) { |
||
103 | $i++; |
||
104 | continue; |
||
105 | } |
||
106 | |||
107 | if(false === $header || null === $header) { |
||
108 | return new EmptyIterator(); |
||
109 | } |
||
110 | if(null === $combinedHeader) { |
||
111 | $combinedHeader = array_fill_keys(array_keys($header), ''); |
||
112 | } |
||
113 | $previousNonEmptyColumnTitle = ''; |
||
114 | foreach($header as $i => $columnTitle) { |
||
115 | if(! array_key_exists($i, $header)) { |
||
116 | if(! $this->options['ignoreMissingColumns']) { |
||
117 | throw new InvalidCsvException('You provided a csv with missing columns'); |
||
118 | } else { |
||
119 | continue; |
||
120 | } |
||
121 | } |
||
122 | $combinedHeader[$i] .= |
||
123 | ('' == trim($combinedHeader[$i]) || '' == trim($columnTitle) ? '' : ' ') . |
||
124 | ('' == trim($columnTitle) ? $previousNonEmptyColumnTitle : $columnTitle); |
||
125 | if('' != trim($columnTitle)) { |
||
126 | $previousNonEmptyColumnTitle = $columnTitle; |
||
127 | } |
||
128 | } |
||
129 | } |
||
130 | if(null === $combinedHeader) { |
||
131 | throw new Exception('Unable to get header'); |
||
132 | } |
||
133 | // make columns unique (double columns become empty) |
||
134 | $previousColumns = array(); |
||
135 | foreach($combinedHeader as & $name) { |
||
136 | if(array_key_exists($name, $previousColumns)) { |
||
137 | $name = ''; |
||
138 | } |
||
139 | $previousColumns[$name] = ''; |
||
140 | } |
||
141 | return $this->getLineIteratorWithHeader($combinedHeader); |
||
142 | } |
||
143 | } |
||
145 |