Conditions | 7 |
Paths | 26 |
Total Lines | 63 |
Code Lines | 40 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
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 interleaveEcBytes(BitBuffer $bitBuffer):SplFixedArray{ |
||
48 | [$l1, $l2, $b1, $b2] = $this->version->getRSBlocks($this->eccLevel->getLevel()); |
||
49 | |||
50 | $numRsBlocks = $l1 + $l2; |
||
51 | $ecBytes = new SplFixedArray($numRsBlocks); |
||
52 | $rsBlocks = array_fill(0, $l1, [$b1, $b2]); |
||
53 | |||
54 | if($l2 > 0){ |
||
55 | $rsBlocks = array_merge($rsBlocks, array_fill(0, $l2, [$b1 + 1, $b2 + 1])); |
||
56 | } |
||
57 | |||
58 | $dataBytes = SplFixedArray::fromArray($rsBlocks); |
||
59 | $maxDataBytes = 0; |
||
60 | $maxEcBytes = 0; |
||
61 | $dataByteOffset = 0; |
||
62 | $bitBufferData = $bitBuffer->getBuffer(); |
||
63 | |||
64 | foreach($rsBlocks as $key => $block){ |
||
65 | [$rsBlockTotal, $dataByteCount] = $block; |
||
66 | |||
67 | $ecByteCount = $rsBlockTotal - $dataByteCount; |
||
68 | $maxDataBytes = max($maxDataBytes, $dataByteCount); |
||
69 | $maxEcBytes = max($maxEcBytes, $ecByteCount); |
||
70 | $dataBytes[$key] = new SplFixedArray($dataByteCount); |
||
71 | |||
72 | foreach($dataBytes[$key] as $i => $_){ |
||
73 | $dataBytes[$key][$i] = $bitBufferData[$i + $dataByteOffset] & 0xff; |
||
74 | } |
||
75 | |||
76 | $rsPoly = new Polynomial; |
||
77 | $modPoly = new Polynomial; |
||
78 | |||
79 | for($i = 0; $i < $ecByteCount; $i++){ |
||
80 | $modPoly->setNum([1, $modPoly->gexp($i)]); |
||
81 | $rsPoly->multiply($modPoly->getNum()); |
||
82 | } |
||
83 | |||
84 | $rsPolyCount = count($rsPoly->getNum()) - 1; |
||
85 | |||
86 | $modPoly |
||
87 | ->setNum($dataBytes[$key]->toArray(), $rsPolyCount) |
||
88 | ->mod($rsPoly->getNum()) |
||
89 | ; |
||
90 | |||
91 | $ecBytes[$key] = new SplFixedArray($rsPolyCount); |
||
92 | $num = $modPoly->getNum(); |
||
93 | $count = count($num) - count($ecBytes[$key]); |
||
94 | |||
95 | foreach($ecBytes[$key] as $i => $_){ |
||
96 | $modIndex = $i + $count; |
||
97 | $ecBytes[$key][$i] = $modIndex >= 0 ? $num[$modIndex] : 0; |
||
98 | } |
||
99 | |||
100 | $dataByteOffset += $dataByteCount; |
||
101 | } |
||
102 | |||
103 | $this->interleavedData = new SplFixedArray($this->version->getTotalCodewords()); |
||
104 | $this->interleavedDataIndex = 0; |
||
105 | |||
106 | $this->interleave($dataBytes, $maxDataBytes, $numRsBlocks); |
||
107 | $this->interleave($ecBytes, $maxEcBytes, $numRsBlocks); |
||
108 | |||
109 | return $this->interleavedData; |
||
110 | } |
||
126 |