| Conditions | 8 |
| Paths | 32 |
| Total Lines | 58 |
| 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('insert into %s(', $this->tableName)); |
||
| 18 | |||
| 19 | $offset = mb_strlen($this->codeStore->getLastLine()); |
||
| 20 | $columns = $this->tableColumnsWithoutAutoIncrement(); |
||
| 21 | $padding = $this->maxColumnNameLength($columns); |
||
| 22 | |||
| 23 | $first = true; |
||
| 24 | foreach ($columns as $column) |
||
| 25 | { |
||
| 26 | if ($first) |
||
| 27 | { |
||
| 28 | $this->codeStore->appendToLastLine(sprintf(' %s', $column['column_name'])); |
||
| 29 | |||
| 30 | $first = false; |
||
| 31 | } |
||
| 32 | else |
||
| 33 | { |
||
| 34 | $format = sprintf('%%-%ds %%s', $offset); |
||
| 35 | $this->codeStore->append(sprintf($format, ',', $column['column_name'])); |
||
| 36 | |||
| 37 | if ($column===end($this->tableColumns)) |
||
| 38 | { |
||
| 39 | $this->codeStore->appendToLastLine(' )'); |
||
| 40 | } |
||
| 41 | } |
||
| 42 | } |
||
| 43 | |||
| 44 | $this->codeStore->append('values('); |
||
| 45 | $offset = mb_strlen($this->codeStore->getLastLine()); |
||
| 46 | |||
| 47 | $first = true; |
||
| 48 | foreach ($columns as $column) |
||
| 49 | { |
||
| 50 | if ($first) |
||
| 51 | { |
||
| 52 | $this->codeStore->appendToLastLine(sprintf(' p_%s', $column['column_name'])); |
||
| 53 | |||
| 54 | $first = false; |
||
| 55 | } |
||
| 56 | else |
||
| 57 | { |
||
| 58 | $format = sprintf('%%-%ds p_%%-%ds', $offset, $padding); |
||
| 59 | $this->codeStore->append(sprintf($format, ',', $column['column_name'])); |
||
| 60 | |||
| 61 | if ($column===end($this->tableColumns)) |
||
| 62 | { |
||
| 63 | $this->codeStore->appendToLastLine(' )'); |
||
| 64 | } |
||
| 65 | } |
||
| 66 | } |
||
| 67 | $this->codeStore->append(';'); |
||
| 68 | |||
| 69 | if ($this->checkAutoIncrement($this->tableColumns)) |
||
| 70 | { |
||
| 71 | $this->codeStore->append(''); |
||
| 72 | $this->codeStore->append('select last_insert_id();'); |
||
| 73 | } |
||
| 117 |