| Conditions | 21 |
| Paths | 65 |
| Total Lines | 145 |
| Code Lines | 119 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 4 | ||
| Bugs | 3 | 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 |
||
| 58 | public static function encode($input, $ibase = null) |
||
| 59 | { |
||
| 60 | $output = null; |
||
| 61 | if ($input == null || $input == '') { |
||
| 62 | return $input; |
||
| 63 | } |
||
| 64 | |||
| 65 | $codetype = 0; |
||
| 66 | $xtag = self::XTAG; |
||
| 67 | $b62x = self::b62x; |
||
| 68 | $asclist = self::asclist; |
||
| 69 | $bpos = self::bpos; |
||
| 70 | $xpos = self::xpos; |
||
| 71 | $ascmax = self::ascmax; |
||
| 72 | //$max_safe_base = self::max_safe_base; |
||
| 73 | |||
| 74 | $rb62x = self::fillRb62x($b62x, $bpos, $xpos); |
||
| 75 | $isNum = false; |
||
| 76 | if ($ibase > 0) { |
||
| 77 | $isNum = true; |
||
| 78 | } |
||
| 79 | if ($isNum) { |
||
| 80 | $num_input = self::xx2dec($input, $ibase, $rb62x); |
||
| 81 | $obase = $xpos; |
||
| 82 | $output = self::dec2xx($num_input, $obase, $b62x); |
||
| 83 | // why a mediate number format is needed? |
||
| 84 | } else { |
||
| 85 | // string |
||
| 86 | $ascidx = []; |
||
| 87 | $ascrlist = []; |
||
| 88 | $inputArr = mb_str_split($input); |
||
| 89 | $inputlen = \count($inputArr); |
||
| 90 | //if(!isset($ascidx)){ $ascidx = array(); } |
||
| 91 | //if(!isset($ascrlist)){ $ascrlist = array(); } |
||
| 92 | $setResult = self::setAscii($codetype, $inputArr, $ascidx, $ascmax, $asclist, $ascrlist); |
||
| 93 | $asctype = $setResult['asctype']; |
||
| 94 | $ascidx = $setResult['ascidx']; |
||
| 95 | $ascrlist = $setResult['ascrlist']; |
||
|
|
|||
| 96 | |||
| 97 | $op = []; |
||
| 98 | $i = 0; |
||
| 99 | $m = 0; |
||
| 100 | if ($asctype == 1) { |
||
| 101 | $ixtag = \ord($xtag); |
||
| 102 | do { |
||
| 103 | $inputArr[$i] = \ord($inputArr[$i]); |
||
| 104 | if ($ascidx[$inputArr[$i]] > -1) { |
||
| 105 | $op[$m] = $xtag; |
||
| 106 | $op[++$m] = $ascidx[$inputArr[$i]]; |
||
| 107 | } elseif ($inputArr[$i] == $ixtag) { |
||
| 108 | $op[$m] = $xtag; |
||
| 109 | $op[++$m] = $xtag; |
||
| 110 | } else { |
||
| 111 | $op[$m] = \chr((int) ($inputArr[$i])); |
||
| 112 | } |
||
| 113 | ++$m; |
||
| 114 | } while (++$i < $inputlen); |
||
| 115 | $op[$m] = $xtag; // asctype=1 has a tag 'x' appended |
||
| 116 | } else { |
||
| 117 | $c0 = 0; |
||
| 118 | $c1 = 0; |
||
| 119 | $c2 = 0; |
||
| 120 | $c3 = 0; |
||
| 121 | do { |
||
| 122 | $remaini = $inputlen - $i; |
||
| 123 | $inputArr[$i] = \ord($inputArr[$i]); |
||
| 124 | if ($remaini > 2) { |
||
| 125 | $inputArr[$i + 1] = \ord($inputArr[$i + 1]); |
||
| 126 | $inputArr[$i + 2] = \ord($inputArr[$i + 2]); |
||
| 127 | $c0 = $inputArr[$i] >> 2; |
||
| 128 | $c1 = ((($inputArr[$i] << 6) & 0xFF) >> 2) | ($inputArr[$i + 1] >> 4); |
||
| 129 | $c2 = ((($inputArr[$i + 1] << 4) & 0xFF) >> 2) | ($inputArr[$i + 2] >> 6); |
||
| 130 | $c3 = (($inputArr[$i + 2] << 2) & 0xFF) >> 2; |
||
| 131 | if ($c0 > $bpos) { |
||
| 132 | $op[$m] = $xtag; |
||
| 133 | $op[++$m] = $b62x[$c0]; |
||
| 134 | } else { |
||
| 135 | $op[$m] = $b62x[$c0]; |
||
| 136 | } |
||
| 137 | if ($c1 > $bpos) { |
||
| 138 | $op[++$m] = $xtag; |
||
| 139 | $op[++$m] = $b62x[$c1]; |
||
| 140 | } else { |
||
| 141 | $op[++$m] = $b62x[$c1]; |
||
| 142 | } |
||
| 143 | if ($c2 > $bpos) { |
||
| 144 | $op[++$m] = $xtag; |
||
| 145 | $op[++$m] = $b62x[$c2]; |
||
| 146 | } else { |
||
| 147 | $op[++$m] = $b62x[$c2]; |
||
| 148 | } |
||
| 149 | if ($c3 > $bpos) { |
||
| 150 | $op[++$m] = $xtag; |
||
| 151 | $op[++$m] = $b62x[$c3]; |
||
| 152 | } else { |
||
| 153 | $op[++$m] = $b62x[$c3]; |
||
| 154 | } |
||
| 155 | $i += 2; |
||
| 156 | } elseif ($remaini == 2) { |
||
| 157 | $inputArr[$i + 1] = \ord($inputArr[$i + 1]); |
||
| 158 | $c0 = $inputArr[$i] >> 2; |
||
| 159 | $c1 = ((($inputArr[$i] << 6) & 0xFF) >> 2) | ($inputArr[$i + 1] >> 4); |
||
| 160 | $c2 = (($inputArr[$i + 1] << 4) & 0xFF) >> 4; |
||
| 161 | if ($c0 > $bpos) { |
||
| 162 | $op[$m] = $xtag; |
||
| 163 | $op[++$m] = $b62x[$c0]; |
||
| 164 | } else { |
||
| 165 | $op[$m] = $b62x[$c0]; |
||
| 166 | } |
||
| 167 | if ($c1 > $bpos) { |
||
| 168 | $op[++$m] = $xtag; |
||
| 169 | $op[++$m] = $b62x[$c1]; |
||
| 170 | } else { |
||
| 171 | $op[++$m] = $b62x[$c1]; |
||
| 172 | } |
||
| 173 | if ($c2 > $bpos) { |
||
| 174 | $op[++$m] = $xtag; |
||
| 175 | $op[++$m] = $b62x[$c2]; |
||
| 176 | } else { |
||
| 177 | $op[++$m] = $b62x[$c2]; |
||
| 178 | } |
||
| 179 | ++$i; |
||
| 180 | } else { // == 1 |
||
| 181 | $c0 = $inputArr[$i] >> 2; |
||
| 182 | $c1 = (($inputArr[$i] << 6) & 0xFF) >> 6; |
||
| 183 | if ($c0 > $bpos) { |
||
| 184 | $op[$m] = $xtag; |
||
| 185 | $op[++$m] = $b62x[$c0]; |
||
| 186 | } else { |
||
| 187 | $op[$m] = $b62x[$c0]; |
||
| 188 | } |
||
| 189 | if ($c1 > $bpos) { |
||
| 190 | $op[++$m] = $xtag; |
||
| 191 | $op[++$m] = $b62x[$c1]; |
||
| 192 | } else { |
||
| 193 | $op[++$m] = $b62x[$c1]; |
||
| 194 | } |
||
| 195 | } |
||
| 196 | ++$m; |
||
| 197 | } while (++$i < $inputlen); |
||
| 198 | } |
||
| 199 | $output = implode('', $op); |
||
| 200 | } |
||
| 201 | |||
| 202 | return $output; |
||
| 203 | } |
||
| 508 |