| Conditions | 7 |
| Paths | 24 |
| Total Lines | 90 |
| Code Lines | 69 |
| 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 |
||
| 184 | private function generateMethodBodyWithLob(WrapperContext $context): void |
||
| 185 | { |
||
| 186 | $this->throws(MySqlDataLayerException::class); |
||
| 187 | $this->throws(MysqlQueryErrorException::class); |
||
| 188 | $this->throws(ResultException::class); |
||
| 189 | |||
| 190 | $routineArgs = $this->getRoutineArgs($context); |
||
| 191 | |||
| 192 | $bindings = ''; |
||
| 193 | $nulls = ''; |
||
| 194 | foreach ($context->phpStratumMetadata['parameters'] as $parameter) |
||
| 195 | { |
||
| 196 | $binding = MySqlDataTypeHelper::getBindVariableType($parameter); |
||
| 197 | if ($binding=='b') |
||
| 198 | { |
||
| 199 | $bindings .= 'b'; |
||
| 200 | if ($nulls!=='') |
||
| 201 | { |
||
| 202 | $nulls .= ', '; |
||
| 203 | } |
||
| 204 | $nulls .= '$null'; |
||
| 205 | } |
||
| 206 | } |
||
| 207 | $context->codeStore->append('$query = \'call '.$context->phpStratumMetadata['routine_name'].'('.$routineArgs.')\';'); |
||
| 208 | $context->codeStore->append('$stmt = @$this->mysqli->prepare($query);'); |
||
| 209 | $context->codeStore->append('if (!$stmt)'); |
||
| 210 | $context->codeStore->append('{'); |
||
| 211 | $context->codeStore->append("throw \$this->dataLayerError('mysqli::prepare');"); |
||
| 212 | $context->codeStore->append('}'); |
||
| 213 | $context->codeStore->append(''); |
||
| 214 | $context->codeStore->append('$null = null;'); |
||
| 215 | $context->codeStore->append('$success = @$stmt->bind_param(\''.$bindings.'\', '.$nulls.');'); |
||
| 216 | $context->codeStore->append('if (!$success)'); |
||
| 217 | $context->codeStore->append('{'); |
||
| 218 | $context->codeStore->append("throw \$this->dataLayerError('mysqli_stmt::bind_param');"); |
||
| 219 | $context->codeStore->append('}'); |
||
| 220 | $context->codeStore->append(''); |
||
| 221 | $context->codeStore->append('$this->getMaxAllowedPacket();'); |
||
| 222 | $context->codeStore->append(''); |
||
| 223 | |||
| 224 | $blobArgumentIndex = 0; |
||
| 225 | foreach ($context->phpStratumMetadata['parameters'] as $parameter) |
||
| 226 | { |
||
| 227 | if (MySqlDataTypeHelper::getBindVariableType($parameter)=='b') |
||
| 228 | { |
||
| 229 | $mangledName = $context->mangler::getParameterName($parameter['parameter_name']); |
||
| 230 | |||
| 231 | $context->codeStore->append('$this->sendLongData($stmt, '.$blobArgumentIndex.', $'.$mangledName.');'); |
||
| 232 | |||
| 233 | $blobArgumentIndex++; |
||
| 234 | } |
||
| 235 | } |
||
| 236 | |||
| 237 | if ($blobArgumentIndex>0) |
||
| 238 | { |
||
| 239 | $context->codeStore->append(''); |
||
| 240 | } |
||
| 241 | |||
| 242 | $context->codeStore->append('if ($this->logQueries)'); |
||
| 243 | $context->codeStore->append('{'); |
||
| 244 | $context->codeStore->append('$time0 = microtime(true);'); |
||
| 245 | $context->codeStore->append('}'); |
||
| 246 | $context->codeStore->append(''); |
||
| 247 | $context->codeStore->append('try'); |
||
| 248 | $context->codeStore->append('{'); |
||
| 249 | $context->codeStore->append('$success = @$stmt->execute();'); |
||
| 250 | $context->codeStore->append('}'); |
||
| 251 | $context->codeStore->append('catch (\mysqli_sql_exception)'); |
||
| 252 | $context->codeStore->append('{'); |
||
| 253 | $context->codeStore->append('$success = false;'); |
||
| 254 | $context->codeStore->append('}'); |
||
| 255 | $context->codeStore->append('if (!$success)'); |
||
| 256 | $context->codeStore->append('{'); |
||
| 257 | $context->codeStore->append("throw \$this->queryError('mysqli_stmt::execute', \$query);"); |
||
| 258 | $context->codeStore->append('}'); |
||
| 259 | $context->codeStore->append(''); |
||
| 260 | $context->codeStore->append('if ($this->logQueries)'); |
||
| 261 | $context->codeStore->append('{'); |
||
| 262 | $context->codeStore->append("\$this->queryLog[] = ['query' => \$query,"); |
||
| 263 | $context->codeStore->append(" 'time' => microtime(true) - \$time0];", false); |
||
| 264 | $context->codeStore->append('}'); |
||
| 265 | $context->codeStore->append(''); |
||
| 266 | $this->generateMethodBodyWithLobFetchData($context); |
||
| 267 | $context->codeStore->append('$stmt->close();'); |
||
| 268 | $context->codeStore->append('if ($this->mysqli->more_results())'); |
||
| 269 | $context->codeStore->append('{'); |
||
| 270 | $context->codeStore->append('$this->mysqli->next_result();'); |
||
| 271 | $context->codeStore->append('}'); |
||
| 272 | $context->codeStore->append(''); |
||
| 273 | $this->generateMethodBodyWithLobReturnData($context); |
||
| 274 | } |
||
| 280 |