| Conditions | 4 |
| Paths | 2 |
| Total Lines | 53 |
| Code Lines | 25 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| 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 |
||
| 121 | public function getGetterSetterCode() |
||
| 122 | { |
||
| 123 | $type = $this->column->getType(); |
||
| 124 | $normalizedType = TDBMDaoGenerator::dbalTypeToPhpType($type); |
||
| 125 | |||
| 126 | $columnGetterName = $this->getGetterName(); |
||
| 127 | $columnSetterName = $this->getSetterName(); |
||
| 128 | |||
| 129 | if ($normalizedType == '\\DateTimeInterface') { |
||
| 130 | $castTo = '\\DateTimeInterface '; |
||
| 131 | } else { |
||
| 132 | $castTo = ''; |
||
| 133 | } |
||
| 134 | |||
| 135 | $getterAndSetterCode = ' /** |
||
| 136 | * The getter for the "%s" column. |
||
| 137 | * |
||
| 138 | * @return %s |
||
| 139 | */ |
||
| 140 | public function %s() { |
||
| 141 | return $this->get(%s, %s); |
||
| 142 | } |
||
| 143 | |||
| 144 | /** |
||
| 145 | * The setter for the "%s" column. |
||
| 146 | * |
||
| 147 | * @param %s $%s |
||
| 148 | */ |
||
| 149 | public function %s(%s$%s) { |
||
| 150 | $this->set(%s, $%s, %s); |
||
| 151 | } |
||
| 152 | |||
| 153 | '; |
||
| 154 | |||
| 155 | return sprintf($getterAndSetterCode, |
||
| 156 | // Getter |
||
| 157 | $this->column->getName(), |
||
| 158 | $normalizedType, |
||
| 159 | $columnGetterName, |
||
| 160 | var_export($this->column->getName(), true), |
||
| 161 | var_export($this->table->getName(), true), |
||
| 162 | // Setter |
||
| 163 | $this->column->getName(), |
||
| 164 | $normalizedType, |
||
| 165 | $this->column->getName(), |
||
| 166 | $columnSetterName, |
||
| 167 | $castTo, |
||
| 168 | $this->column->getName().($castTo ? ($this->column->getNotnull() ? '' : ' = null') : ''), |
||
| 169 | var_export($this->column->getName(), true), |
||
| 170 | $this->column->getName(), |
||
| 171 | var_export($this->table->getName(), true) |
||
| 172 | ); |
||
| 173 | } |
||
| 174 | |||
| 202 |