| Conditions | 6 |
| Paths | 18 |
| Total Lines | 55 |
| 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 |
||
| 15 | protected function generateBody(): void |
||
| 16 | { |
||
| 17 | $this->codeStore->append(sprintf('update %s', $this->tableName)); |
||
| 18 | $this->codeStore->append('set'); |
||
| 19 | |||
| 20 | $offset = mb_strlen($this->codeStore->getLastLine()); |
||
| 21 | $columns = $this->tableColumnsWithoutAutoIncrement(); |
||
| 22 | $width = $this->maxColumnNameLength($columns); |
||
| 23 | |||
| 24 | $first = true; |
||
| 25 | foreach ($columns as $column) |
||
| 26 | { |
||
| 27 | if ($first) |
||
| 28 | { |
||
| 29 | $format = sprintf("%%%ds %%-%ds = p_%%s", $offset, $width); |
||
| 30 | $this->codeStore->appendToLastLine(sprintf($format, '', $column['column_name'], $column['column_name'])); |
||
| 31 | |||
| 32 | $first = false; |
||
| 33 | } |
||
| 34 | else |
||
| 35 | { |
||
| 36 | $format = sprintf("%%-%ds %%-%ds = p_%%s", $offset + 3, $width); |
||
| 37 | $this->codeStore->append(sprintf($format, ',', $column['column_name'], $column['column_name'])); |
||
| 38 | } |
||
| 39 | } |
||
| 40 | |||
| 41 | $this->codeStore->append('where'); |
||
| 42 | |||
| 43 | $columns = $this->keyColumns(); |
||
| 44 | $width = $this->maxColumnNameLength($columns); |
||
| 45 | |||
| 46 | $first = true; |
||
| 47 | foreach ($columns as $column) |
||
| 48 | { |
||
| 49 | if ($first) |
||
| 50 | { |
||
| 51 | $format = sprintf("%%%ds %%-%ds = p_%%s", 1, $width); |
||
| 52 | $line = sprintf($format, '', $column['column_name'], $column['column_name']); |
||
| 53 | $this->codeStore->appendToLastLine($line); |
||
| 54 | |||
| 55 | $first = false; |
||
| 56 | } |
||
| 57 | else |
||
| 58 | { |
||
| 59 | $format = sprintf("and%%%ds %%-%ds = p_%%s", 3, $width); |
||
| 60 | $this->codeStore->append(sprintf($format, '', $column['column_name'], $column['column_name'])); |
||
| 61 | } |
||
| 62 | } |
||
| 63 | |||
| 64 | if (empty($this->uniqueIndexes)) |
||
| 65 | { |
||
| 66 | $this->codeStore->append('limit 0,1'); |
||
| 67 | } |
||
| 68 | |||
| 69 | $this->codeStore->append(';'); |
||
| 70 | } |
||
| 104 |