| Conditions | 10 |
| Paths | 14 |
| Total Lines | 37 |
| Code Lines | 23 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 24 |
| CRAP Score | 10.0064 |
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 |
||
| 98 | 1152 | private function doNext($ptr) |
|
| 99 | { |
||
| 100 | 1152 | if ($this->math->cmp($this->position, $this->end) >= 0) { |
|
| 101 | throw new \RuntimeException('Position exceeds end of script!'); |
||
| 102 | } |
||
| 103 | |||
| 104 | 1152 | $opCode = ord($this->data[$this->position++]); |
|
| 105 | 1152 | $pushData = $this->empty; |
|
| 106 | 1152 | $dataSize = 0; |
|
| 107 | |||
| 108 | 1152 | if ($opCode <= Opcodes::OP_PUSHDATA4) { |
|
| 109 | 834 | if ($opCode < Opcodes::OP_PUSHDATA1) { |
|
| 110 | 804 | $dataSize = $opCode; |
|
| 111 | 834 | } else if ($opCode === Opcodes::OP_PUSHDATA1) { |
|
| 112 | 30 | $dataSize = $this->unpackSize('C', 1); |
|
| 113 | 60 | } else if ($opCode === Opcodes::OP_PUSHDATA2) { |
|
| 114 | 18 | $dataSize = $this->unpackSize('v', 2); |
|
| 115 | 18 | } else { |
|
| 116 | 12 | $dataSize = $this->unpackSize('V', 4); |
|
| 117 | } |
||
| 118 | |||
| 119 | 834 | $delta = ($this->end - $this->position); |
|
| 120 | 834 | if ($dataSize === false || $delta < 0 || $delta < $dataSize) { |
|
| 121 | 6 | throw new \RuntimeException('Failed to unpack data from Script'); |
|
| 122 | } |
||
| 123 | |||
| 124 | 834 | if ($dataSize > 0) { |
|
| 125 | 696 | $pushData = new Buffer(substr($this->data, $this->position, $dataSize), $dataSize, $this->math); |
|
| 126 | 696 | } |
|
| 127 | |||
| 128 | 834 | $this->position += $dataSize; |
|
| 129 | 834 | } |
|
| 130 | |||
| 131 | 1152 | $this->array[$ptr] = new Operation($opCode, $pushData, $dataSize); |
|
| 132 | |||
| 133 | 1152 | return $this->array[$ptr]; |
|
| 134 | } |
||
| 135 | |||
| 216 |