| Conditions | 13 |
| Paths | 38 |
| Total Lines | 60 |
| Code Lines | 45 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 |
||
| 89 | public function toArray( $filename, $is_csv_content = false ) { |
||
| 90 | |||
| 91 | $this->_csv = $is_csv_content ? $filename : \file_get_contents( $filename ); |
||
| 92 | |||
| 93 | $CSV_LINEBREAK = $this->linebreak(); |
||
| 94 | $CSV_ENCLOSURE = $this->enclosure(); |
||
| 95 | $CSV_DELIMITER = $this->delimiter(); |
||
| 96 | |||
| 97 | |||
| 98 | $r = []; |
||
| 99 | $cnt = \strlen($this->_csv); |
||
| 100 | |||
| 101 | $esc = $escesc = false; |
||
| 102 | $i = $k = $n = 0; |
||
| 103 | $r[$k][$n] = ''; |
||
| 104 | |||
| 105 | while ($i < $cnt) { |
||
| 106 | $ch = $this->_csv[$i]; |
||
| 107 | $chch = ($i < $cnt-1) ? $ch.$this->_csv[$i+1] : $ch; |
||
| 108 | |||
| 109 | if ($ch === $CSV_LINEBREAK) { |
||
| 110 | if ($esc) { |
||
| 111 | $r[$k][$n] .= $ch; |
||
| 112 | } else { |
||
| 113 | $k++; |
||
| 114 | $n = 0; |
||
| 115 | $esc = $escesc = false; |
||
| 116 | $r[$k][$n] = ''; |
||
| 117 | } |
||
| 118 | } elseif ($chch === $CSV_LINEBREAK) { |
||
| 119 | if ($esc) { |
||
| 120 | $r[$k][$n] .= $chch; |
||
| 121 | } else { |
||
| 122 | $k++; |
||
| 123 | $n = 0; |
||
| 124 | $esc = $escesc = false; |
||
| 125 | $r[$k][$n] = ''; |
||
| 126 | } |
||
| 127 | $i++; |
||
| 128 | } elseif ($ch === $CSV_DELIMITER) { |
||
| 129 | if ($esc) { |
||
| 130 | $r[$k][$n] .= $ch; |
||
| 131 | } else { |
||
| 132 | $n++; |
||
| 133 | $r[$k][$n] = ''; |
||
| 134 | $esc = $escesc = false; |
||
| 135 | } |
||
| 136 | } elseif ( $chch === $CSV_ENCLOSURE.$CSV_ENCLOSURE && $esc ) { |
||
| 137 | $r[$k][$n] .= $CSV_ENCLOSURE; |
||
| 138 | $i++; |
||
| 139 | } elseif ($ch === $CSV_ENCLOSURE) { |
||
| 140 | |||
| 141 | $esc = !$esc; |
||
|
|
|||
| 142 | |||
| 143 | } else { |
||
| 144 | $r[$k][$n] .= $ch; |
||
| 145 | } |
||
| 146 | $i++; |
||
| 147 | } |
||
| 148 | return $r; |
||
| 149 | } |
||
| 215 |