| Conditions | 5 | 
| Paths | 5 | 
| Total Lines | 61 | 
| Lines | 61 | 
| Ratio | 100 % | 
| 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 | ||
| 171 | View Code Duplication | public function save() | |
| 172 |     { | ||
| 173 |         if ($this->isNew()) { | ||
| 174 | // insert | ||
| 175 | $statement = $this->dbObject->prepare(<<<SQL | ||
| 176 | INSERT INTO credential ( updateversion, user, factor, type, data, version, timeout, disabled, priority ) | ||
| 177 | VALUES ( 0, :user, :factor, :type, :data, :version, :timeout, :disabled, :priority ); | ||
| 178 | SQL | ||
| 179 | ); | ||
| 180 |             $statement->bindValue(":user", $this->user); | ||
| 181 |             $statement->bindValue(":factor", $this->factor); | ||
| 182 |             $statement->bindValue(":type", $this->type); | ||
| 183 |             $statement->bindValue(":data", $this->data); | ||
| 184 |             $statement->bindValue(":version", $this->version); | ||
| 185 |             $statement->bindValue(":timeout", $this->timeout); | ||
| 186 |             $statement->bindValue(":disabled", $this->disabled); | ||
| 187 |             $statement->bindValue(":priority", $this->priority); | ||
| 188 | |||
| 189 |             if ($statement->execute()) { | ||
| 190 | $this->id = (int)$this->dbObject->lastInsertId(); | ||
| 191 | } | ||
| 192 |             else { | ||
| 193 | throw new Exception($statement->errorInfo()); | ||
| 194 | } | ||
| 195 | } | ||
| 196 |         else { | ||
| 197 | // update | ||
| 198 | $statement = $this->dbObject->prepare(<<<SQL | ||
| 199 | UPDATE credential | ||
| 200 | SET factor = :factor | ||
| 201 | , data = :data | ||
| 202 | , version = :version | ||
| 203 | , timeout = :timeout | ||
| 204 | , disabled = :disabled | ||
| 205 | , priority = :priority | ||
| 206 | , updateversion = updateversion + 1 | ||
| 207 | WHERE id = :id AND updateversion = :updateversion; | ||
| 208 | SQL | ||
| 209 | ); | ||
| 210 | |||
| 211 |             $statement->bindValue(':id', $this->id); | ||
| 212 |             $statement->bindValue(':updateversion', $this->updateversion); | ||
| 213 | |||
| 214 |             $statement->bindValue(":factor", $this->factor); | ||
| 215 |             $statement->bindValue(":data", $this->data); | ||
| 216 |             $statement->bindValue(":version", $this->version); | ||
| 217 |             $statement->bindValue(":timeout", $this->timeout); | ||
| 218 |             $statement->bindValue(":disabled", $this->disabled); | ||
| 219 |             $statement->bindValue(":priority", $this->priority); | ||
| 220 | |||
| 221 |             if (!$statement->execute()) { | ||
| 222 | throw new Exception($statement->errorInfo()); | ||
| 223 | } | ||
| 224 | |||
| 225 |             if ($statement->rowCount() !== 1) { | ||
| 226 | throw new OptimisticLockFailedException(); | ||
| 227 | } | ||
| 228 | |||
| 229 | $this->updateversion++; | ||
| 230 | } | ||
| 231 | } | ||
| 232 | } | 
This check looks for the generic type
arrayas a return type and suggests a more specific type. This type is inferred from the actual code.