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