| Conditions | 5 |
| Paths | 5 |
| Total Lines | 71 |
| Code Lines | 53 |
| 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 |
||
| 107 | public function save() |
||
| 108 | { |
||
| 109 | if ($this->isNew()) { |
||
| 110 | // insert |
||
| 111 | $statement = $this->dbObject->prepare(<<<SQL |
||
| 112 | INSERT INTO requestform ( |
||
| 113 | enabled, domain, name, publicendpoint, formcontent, overridequeue, usernamehelp, emailhelp, commentshelp |
||
| 114 | ) VALUES ( |
||
| 115 | :enabled, :domain, :name, :publicendpoint, :formcontent, :overridequeue, :usernamehelp, :emailhelp, :commentshelp |
||
| 116 | ); |
||
| 117 | SQL |
||
| 118 | ); |
||
| 119 | |||
| 120 | $statement->bindValue(":enabled", $this->enabled); |
||
| 121 | $statement->bindValue(":domain", $this->domain); |
||
| 122 | $statement->bindValue(":name", $this->name); |
||
| 123 | $statement->bindValue(":publicendpoint", $this->publicendpoint); |
||
| 124 | $statement->bindValue(":formcontent", $this->formcontent); |
||
| 125 | $statement->bindValue(":overridequeue", $this->overridequeue); |
||
| 126 | $statement->bindValue(":usernamehelp", $this->usernamehelp); |
||
| 127 | $statement->bindValue(":emailhelp", $this->emailhelp); |
||
| 128 | $statement->bindValue(":commentshelp", $this->commentshelp); |
||
| 129 | |||
| 130 | if ($statement->execute()) { |
||
| 131 | $this->id = (int)$this->dbObject->lastInsertId(); |
||
| 132 | } |
||
| 133 | else { |
||
| 134 | throw new Exception($statement->errorInfo()); |
||
|
|
|||
| 135 | } |
||
| 136 | } |
||
| 137 | else { |
||
| 138 | $statement = $this->dbObject->prepare(<<<SQL |
||
| 139 | UPDATE requestform SET |
||
| 140 | enabled = :enabled, |
||
| 141 | domain = :domain, |
||
| 142 | name = :name, |
||
| 143 | publicendpoint = :publicendpoint, |
||
| 144 | formcontent = :formcontent, |
||
| 145 | overridequeue = :overridequeue, |
||
| 146 | usernamehelp = :usernamehelp, |
||
| 147 | emailhelp = :emailhelp, |
||
| 148 | commentshelp = :commentshelp, |
||
| 149 | |||
| 150 | updateversion = updateversion + 1 |
||
| 151 | WHERE id = :id AND updateversion = :updateversion; |
||
| 152 | SQL |
||
| 153 | ); |
||
| 154 | |||
| 155 | $statement->bindValue(":enabled", $this->enabled); |
||
| 156 | $statement->bindValue(":domain", $this->domain); |
||
| 157 | $statement->bindValue(":name", $this->name); |
||
| 158 | $statement->bindValue(":publicendpoint", $this->publicendpoint); |
||
| 159 | $statement->bindValue(":formcontent", $this->formcontent); |
||
| 160 | $statement->bindValue(":overridequeue", $this->overridequeue); |
||
| 161 | $statement->bindValue(":usernamehelp", $this->usernamehelp); |
||
| 162 | $statement->bindValue(":emailhelp", $this->emailhelp); |
||
| 163 | $statement->bindValue(":commentshelp", $this->commentshelp); |
||
| 164 | |||
| 165 | |||
| 166 | $statement->bindValue(':id', $this->id); |
||
| 167 | $statement->bindValue(':updateversion', $this->updateversion); |
||
| 168 | |||
| 169 | if (!$statement->execute()) { |
||
| 170 | throw new Exception($statement->errorInfo()); |
||
| 171 | } |
||
| 172 | |||
| 173 | if ($statement->rowCount() !== 1) { |
||
| 174 | throw new OptimisticLockFailedException(); |
||
| 175 | } |
||
| 176 | |||
| 177 | $this->updateversion++; |
||
| 178 | } |
||
| 335 | } |