| Conditions | 5 |
| Paths | 5 |
| Total Lines | 74 |
| Code Lines | 56 |
| 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 |
||
| 129 | public function save() |
||
| 130 | { |
||
| 131 | if ($this->isNew()) { |
||
| 132 | // insert |
||
| 133 | $statement = $this->dbObject->prepare(<<<SQL |
||
| 134 | INSERT INTO domain ( |
||
| 135 | shortname, longname, wikiarticlepath, wikiapipath, enabled, defaultclose, defaultlanguage, |
||
| 136 | emailreplyaddress, notificationtarget, localdocumentation |
||
| 137 | ) VALUES ( |
||
| 138 | :shortname, :longname, :wikiarticlepath, :wikiapipath, :enabled, :defaultclose, :defaultlanguage, |
||
| 139 | :emailreplyaddress, :notificationtarget, :localdocumentation |
||
| 140 | ); |
||
| 141 | SQL |
||
| 142 | ); |
||
| 143 | |||
| 144 | $statement->bindValue(":shortname", $this->shortname); |
||
| 145 | $statement->bindValue(":longname", $this->longname); |
||
| 146 | $statement->bindValue(":wikiarticlepath", $this->wikiarticlepath); |
||
| 147 | $statement->bindValue(":wikiapipath", $this->wikiapipath); |
||
| 148 | $statement->bindValue(":enabled", $this->enabled); |
||
| 149 | $statement->bindValue(":defaultclose", $this->defaultclose); |
||
| 150 | $statement->bindValue(":defaultlanguage", $this->defaultlanguage); |
||
| 151 | $statement->bindValue(":emailreplyaddress", $this->emailreplyaddress); |
||
| 152 | $statement->bindValue(":notificationtarget", $this->notificationtarget); |
||
| 153 | $statement->bindValue(":localdocumentation", $this->localdocumentation); |
||
| 154 | |||
| 155 | |||
| 156 | if ($statement->execute()) { |
||
| 157 | $this->id = (int)$this->dbObject->lastInsertId(); |
||
| 158 | } |
||
| 159 | else { |
||
| 160 | throw new Exception($statement->errorInfo()); |
||
| 161 | } |
||
| 162 | } |
||
| 163 | else { |
||
| 164 | $statement = $this->dbObject->prepare(<<<SQL |
||
| 165 | UPDATE domain SET |
||
| 166 | longname = :longname, |
||
| 167 | wikiarticlepath = :wikiarticlepath, |
||
| 168 | wikiapipath = :wikiapipath, |
||
| 169 | enabled = :enabled, |
||
| 170 | defaultclose = :defaultclose, |
||
| 171 | defaultlanguage = :defaultlanguage, |
||
| 172 | emailreplyaddress = :emailreplyaddress, |
||
| 173 | notificationtarget = :notificationtarget, |
||
| 174 | localdocumentation = :localdocumentation, |
||
| 175 | |||
| 176 | updateversion = updateversion + 1 |
||
| 177 | WHERE id = :id AND updateversion = :updateversion; |
||
| 178 | SQL |
||
| 179 | ); |
||
| 180 | |||
| 181 | $statement->bindValue(":longname", $this->longname); |
||
| 182 | $statement->bindValue(":wikiarticlepath", $this->wikiarticlepath); |
||
| 183 | $statement->bindValue(":wikiapipath", $this->wikiapipath); |
||
| 184 | $statement->bindValue(":enabled", $this->enabled); |
||
| 185 | $statement->bindValue(":defaultclose", $this->defaultclose); |
||
| 186 | $statement->bindValue(":defaultlanguage", $this->defaultlanguage); |
||
| 187 | $statement->bindValue(":emailreplyaddress", $this->emailreplyaddress); |
||
| 188 | $statement->bindValue(":notificationtarget", $this->notificationtarget); |
||
| 189 | $statement->bindValue(":localdocumentation", $this->localdocumentation); |
||
| 190 | |||
| 191 | $statement->bindValue(':id', $this->id); |
||
| 192 | $statement->bindValue(':updateversion', $this->updateversion); |
||
| 193 | |||
| 194 | if (!$statement->execute()) { |
||
| 195 | throw new Exception($statement->errorInfo()); |
||
| 196 | } |
||
| 197 | |||
| 198 | if ($statement->rowCount() !== 1) { |
||
| 199 | throw new OptimisticLockFailedException(); |
||
| 200 | } |
||
| 201 | |||
| 202 | $this->updateversion++; |
||
| 203 | } |
||
| 365 | } |