| Conditions | 13 |
| Paths | 27 |
| Total Lines | 43 |
| Code Lines | 25 |
| 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 |
||
| 82 | protected function readData():void{ |
||
| 83 | \fseek($this->fh, $this->header['EntryOffset'] + $this->headerSize); |
||
| 84 | |||
| 85 | $this->data = array_fill(0, $this->header['RecordCount'], null); |
||
| 86 | |||
| 87 | // read a row |
||
| 88 | foreach($this->data as $i => $_){ |
||
| 89 | $data = \fread($this->fh, $this->header['RecordSize']); |
||
| 90 | $row = []; |
||
| 91 | $j = 0; |
||
| 92 | $skip = false; |
||
| 93 | |||
| 94 | // loop through the columns |
||
| 95 | foreach($this->cols as $c => $col){ |
||
| 96 | |||
| 97 | // skip 4 bytes if the string offset is 0 (determined by $skip), the current type is string and the next isn't |
||
| 98 | if($skip === true && ($c > 0 && $this->cols[$c - 1]['header']['DataType'] === 130) && $col['header']['DataType'] !== 130){ |
||
| 99 | $j += 4; |
||
| 100 | } |
||
| 101 | |||
| 102 | switch($col['header']['DataType']){ |
||
| 103 | case 3: // uint32 |
||
| 104 | case 11: // booleans (stored as uint32 0/1) |
||
| 105 | $v = uint32(\substr($data, $j, 4)); $j += 4; break; |
||
| 106 | case 4: // float |
||
| 107 | $v = \round(float(\substr($data, $j, 4)), 3); $j += 4; break; |
||
| 108 | case 20: // uint64 |
||
| 109 | $v = uint64(\substr($data, $j, 8)); $j += 8; break; |
||
| 110 | case 130: // string (UTF-16LE) |
||
| 111 | $v = $this->readString($data, $j, $skip); $j += 8; break; |
||
| 112 | |||
| 113 | default: $v = null; |
||
| 114 | } |
||
| 115 | |||
| 116 | $row[$col['name']] = $v; |
||
| 117 | } |
||
| 118 | |||
| 119 | // if we run into this, a horrible thing happened |
||
| 120 | if(\count($row) !== $this->header['FieldCount']){ |
||
| 121 | throw new WSDBException('invalid field count'); |
||
| 122 | } |
||
| 123 | |||
| 124 | $this->data[$i] = $row; |
||
| 125 | } |
||
| 157 |