Conditions | 10 |
Paths | 13 |
Total Lines | 44 |
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 |
||
13 | public function __construct(array $options = array()) |
||
14 | { |
||
15 | $defaultOptions = array( |
||
16 | 'delimiter' => ',', |
||
17 | 'enclosure' => '"', |
||
18 | 'escape' => '\\', |
||
19 | 'hasHeader' => true, |
||
20 | 'header' => null, |
||
21 | 'ignoreMissingRows' => false, // Deprecated: use ignoreMissingColumns |
||
22 | 'ignoreMissingColumns' => false, // columns* |
||
23 | 'combineFirstNRowsAsHeader' => 1, |
||
24 | 'skipFirstNRows' => 0 |
||
25 | ); |
||
26 | |||
27 | $unknownOptions = array_diff(array_keys($options), array_keys($defaultOptions)); |
||
28 | if(count($unknownOptions) != 0) { |
||
29 | throw new InvalidArgumentException('Unknown options specified: ' . implode(', ', $unknownOptions)); |
||
30 | } |
||
31 | if(array_key_exists('header', $options) && null !== $options['header'] && ! array_key_exists('hasHeader', $options)) { |
||
32 | $options['hasHeader'] = false; |
||
33 | } |
||
34 | if(array_key_exists('ignoreMissingRows', $options)) { |
||
35 | $options['ignoreMissingColumns'] = $options['ignoreMissingRows']; |
||
36 | } |
||
37 | |||
38 | $this->options = array_merge($this->options, $defaultOptions, $options); |
||
39 | |||
40 | if($this->options['hasHeader'] || null !== $this->options['header']) { |
||
41 | if(null === $this->options['header']) { |
||
42 | $it = $this->getLineIteratorWithHeaderInFirstLines(); |
||
43 | } else { |
||
44 | $i = 0; |
||
45 | while($this->options['skipFirstNRows'] > $i) { |
||
46 | $i++; |
||
47 | $this->retrieveNextCsvRow(); |
||
48 | } |
||
49 | |||
50 | $it = $this->getLineIteratorWithHeader($this->options['header']); |
||
51 | } |
||
52 | } else { |
||
53 | $it = $this->getLineIteratorWithoutHeader(); |
||
54 | } |
||
55 | parent::__construct($it, function($r) { return $r !== false; }); |
||
56 | } |
||
57 | |||
145 |