| Conditions | 18 |
| Paths | 13 |
| Total Lines | 50 |
| 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 |
||
| 88 | function inc_importer_csv_dist($file, $head = false, $delim = ',', $enclos = '"', $len = 10000, $charset_source = '') { |
||
| 89 | $return = false; |
||
| 90 | if (@file_exists($file) |
||
| 91 | and $handle = fopen($file, 'r')) { |
||
| 92 | if ($charset_source) { |
||
| 93 | importer_csv_importcharset('', $charset_source); |
||
| 94 | } |
||
| 95 | if ($head) { |
||
| 96 | $header = fgetcsv($handle, $len, $delim, $enclos); |
||
| 97 | if ($header) { |
||
| 98 | $header = array_map('importer_csv_importcharset', $header); |
||
| 99 | $header = array_map('importer_csv_nettoie_key', $header); |
||
| 100 | $header_type = array(); |
||
| 101 | foreach ($header as $heading) { |
||
| 102 | if (!isset($header_type[$heading])) { |
||
| 103 | $header_type[$heading] = "scalar"; |
||
| 104 | } else { |
||
| 105 | $header_type[$heading] = "array"; |
||
| 106 | } |
||
| 107 | } |
||
| 108 | } |
||
| 109 | } |
||
| 110 | while (($data = fgetcsv($handle, $len, $delim, $enclos)) !== false) { |
||
| 111 | $data = array_map('importer_csv_importcharset', $data); |
||
| 112 | if ($head and isset($header)) { |
||
| 113 | $row = array(); |
||
| 114 | foreach ($header as $key => $heading) { |
||
| 115 | if ($header_type[$heading] == "array") { |
||
| 116 | if (!isset($row[$heading])) { |
||
| 117 | $row[$heading] = array(); |
||
| 118 | } |
||
| 119 | if (isset($data[$key]) and strlen($data[$key])) { |
||
| 120 | $row[$heading][] = $data[$key]; |
||
| 121 | } |
||
| 122 | } else { |
||
| 123 | $row[$heading] = (isset($data[$key])) ? $data[$key] : ''; |
||
| 124 | } |
||
| 125 | } |
||
| 126 | $return[] = $row; |
||
| 127 | } else { |
||
| 128 | $return[] = $data; |
||
| 129 | } |
||
| 130 | } |
||
| 131 | if ($charset_source) { |
||
| 132 | importer_csv_importcharset('', true); |
||
| 133 | } |
||
| 134 | } |
||
| 135 | |||
| 136 | return $return; |
||
| 137 | } |
||
| 138 |
This check compares the return type specified in the
@returnannotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.