| Conditions | 27 |
| Paths | 69 |
| Total Lines | 63 |
| Code Lines | 55 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 4 | ||
| 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 |
||
| 47 | public function nextRecord() { |
||
| 48 | if ($this->records >= $this->headers["records"]) { |
||
| 49 | if ($this->memo instanceof Memo) { |
||
| 50 | unset($this->memo); |
||
| 51 | } |
||
| 52 | return false; |
||
| 53 | } |
||
| 54 | $record = []; |
||
| 55 | $data = fread($this->fp, $this->headers["record_length"]); |
||
| 56 | $record["deleted"] = (unpack("C", $data[0])[1] == 42); |
||
| 57 | $pos = 1; |
||
| 58 | foreach ($this->columns as $column) { |
||
| 59 | $sub_data = (in_array($column["type"], $this->notTrimTypes)) ? substr($data, $pos, $column["length"]) : trim(substr($data, $pos, $column["length"])); |
||
| 60 | switch($column["type"]) { |
||
| 61 | case "F": |
||
| 62 | case "N": |
||
| 63 | $record[$column["name"]] = (is_numeric($sub_data)) ? (($column["decimal"]) ? (float) $sub_data : (int) $sub_data) : null; |
||
| 64 | break; |
||
| 65 | case "Y": |
||
| 66 | $decimal = intval(str_pad("1", $column["decimal"] + 1, "0")); |
||
| 67 | $record[$column["name"]] = round(unpack("Q", $sub_data)[1] / $decimal, $column["decimal"]); |
||
| 68 | break; |
||
| 69 | case "I": |
||
| 70 | $record[$column["name"]] = unpack("l", $sub_data)[1]; |
||
| 71 | break; |
||
| 72 | case "@": |
||
| 73 | case "T": |
||
| 74 | $record[$column["name"]] = $this->getDateTime($sub_data); |
||
| 75 | break; |
||
| 76 | case "D": |
||
| 77 | $record[$column["name"]] = empty($sub_data) ? null : $sub_data; |
||
| 78 | break; |
||
| 79 | case "L": |
||
| 80 | $record[$column["name"]] = ($sub_data == "?" || empty($sub_data)) ? null : (in_array(strtolower($sub_data), $this->logicals)); |
||
| 81 | break; |
||
| 82 | case "C": |
||
| 83 | $record[$column["name"]] = $this->convertChar($sub_data); |
||
| 84 | break; |
||
| 85 | case "M": |
||
| 86 | case "P": |
||
| 87 | case "G": |
||
| 88 | $sub_data = (strlen($sub_data) == 4) ? unpack("L", $sub_data)[1] : (int)$sub_data; |
||
| 89 | if (!$sub_data) { |
||
| 90 | $record[$column["name"]] = ""; |
||
| 91 | } else { |
||
| 92 | $record[$column["name"]] = $this->getMemo($sub_data, ($column["type"] == "M")); |
||
| 93 | } |
||
| 94 | break; |
||
| 95 | case "0": |
||
| 96 | $value = intval(unpack("C*", $sub_data)[1]); |
||
| 97 | $record[$column["name"]] = $value; |
||
| 98 | foreach ($this->nullFlagColumns as $index => $name) { |
||
| 99 | if (($value >> $index) & 1) { |
||
| 100 | $record[$name] = null; |
||
| 101 | } |
||
| 102 | } |
||
| 103 | break; |
||
| 104 | } |
||
| 105 | $this->checkNullColumn($column); |
||
| 106 | $pos += $column["length"]; |
||
| 107 | } |
||
| 108 | $this->records++; |
||
| 109 | return $record; |
||
| 110 | } |
||
| 140 |