Conditions | 14 |
Paths | 41 |
Total Lines | 49 |
Code Lines | 30 |
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 |
||
63 | public function read(string $filename):ReaderInterface{ |
||
64 | $this->loadFile($filename); |
||
65 | $this->init(); |
||
66 | |||
67 | fseek($this->fh, $this->header['EntryOffset'] + 0x60); |
||
68 | |||
69 | for($i = 0; $i < $this->header['RecordCount']; $i++){ |
||
70 | $data = fread($this->fh, $this->header['RecordSize']); |
||
71 | $row = []; |
||
72 | $j = 0; |
||
73 | $skip = false; |
||
74 | |||
75 | foreach($this->cols as $c => $col){ |
||
76 | |||
77 | if($skip === true && ($c > 0 && $this->cols[$c - 1]['header']['DataType'] === 130) && $col['header']['DataType'] !== 130){ |
||
78 | $j += 4; |
||
79 | } |
||
80 | |||
81 | switch($col['header']['DataType']){ |
||
82 | case 3: // uint32 |
||
83 | case 11: // booleans (stored as uint32 0/1) |
||
84 | $v = unpack('L', substr($data, $j, 4))[1]; $j += 4; break; |
||
85 | case 4: // float |
||
86 | $v = round(unpack('f', substr($data, $j, 4))[1], 3); $j += 4; break; |
||
87 | case 20: // uint64 |
||
88 | $v = unpack('Q', substr($data, $j, 8))[1]; $j += 8; break; |
||
89 | case 130: // string |
||
90 | $v = $this->readString($data, $j, $skip); $j += 8; break; |
||
91 | |||
92 | default: $v = null; |
||
93 | } |
||
94 | |||
95 | $row[$col['name']] = $v; |
||
96 | } |
||
97 | |||
98 | if(count($row) !== $this->header['FieldCount']){ |
||
99 | throw new WSDBException('invalid field count'); |
||
100 | } |
||
101 | |||
102 | $this->data[$i] = $row; |
||
103 | } |
||
104 | |||
105 | fclose($this->fh); |
||
106 | |||
107 | if(count($this->data) !== $this->header['RecordCount']){ |
||
108 | throw new WSDBException('invalid row count'); |
||
109 | } |
||
110 | |||
111 | return $this; |
||
112 | } |
||
142 |