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 |
||
104 | public function save() |
||
105 | { |
||
106 | if ($this->isNew()) { |
||
107 | // insert |
||
108 | $statement = $this->dbObject->prepare(<<<SQL |
||
109 | INSERT INTO domain ( |
||
110 | shortname, longname, wikiarticlepath, wikiapipath, enabled, defaultclose, defaultlanguage, |
||
111 | emailreplyaddress, notificationtarget, localdocumentation |
||
112 | ) VALUES ( |
||
113 | :shortname, :longname, :wikiarticlepath, :wikiapipath, :enabled, :defaultclose, :defaultlanguage, |
||
114 | :emailreplyaddress, :notificationtarget, :localdocumentation |
||
115 | ); |
||
116 | SQL |
||
117 | ); |
||
118 | |||
119 | $statement->bindValue(":shortname", $this->shortname); |
||
120 | $statement->bindValue(":longname", $this->longname); |
||
121 | $statement->bindValue(":wikiarticlepath", $this->wikiarticlepath); |
||
122 | $statement->bindValue(":wikiapipath", $this->wikiapipath); |
||
123 | $statement->bindValue(":enabled", $this->enabled); |
||
124 | $statement->bindValue(":defaultclose", $this->defaultclose); |
||
125 | $statement->bindValue(":defaultlanguage", $this->defaultlanguage); |
||
126 | $statement->bindValue(":emailreplyaddress", $this->emailreplyaddress); |
||
127 | $statement->bindValue(":notificationtarget", $this->notificationtarget); |
||
128 | $statement->bindValue(":localdocumentation", $this->localdocumentation); |
||
129 | |||
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 domain SET |
||
141 | longname = :longname, |
||
142 | wikiarticlepath = :wikiarticlepath, |
||
143 | wikiapipath = :wikiapipath, |
||
144 | enabled = :enabled, |
||
145 | defaultclose = :defaultclose, |
||
146 | defaultlanguage = :defaultlanguage, |
||
147 | emailreplyaddress = :emailreplyaddress, |
||
148 | notificationtarget = :notificationtarget, |
||
149 | localdocumentation = :localdocumentation, |
||
150 | |||
151 | updateversion = updateversion + 1 |
||
152 | WHERE id = :id AND updateversion = :updateversion; |
||
153 | SQL |
||
154 | ); |
||
155 | |||
156 | $statement->bindValue(":longname", $this->longname); |
||
157 | $statement->bindValue(":wikiarticlepath", $this->wikiarticlepath); |
||
158 | $statement->bindValue(":wikiapipath", $this->wikiapipath); |
||
159 | $statement->bindValue(":enabled", $this->enabled); |
||
160 | $statement->bindValue(":defaultclose", $this->defaultclose); |
||
161 | $statement->bindValue(":defaultlanguage", $this->defaultlanguage); |
||
162 | $statement->bindValue(":emailreplyaddress", $this->emailreplyaddress); |
||
163 | $statement->bindValue(":notificationtarget", $this->notificationtarget); |
||
164 | $statement->bindValue(":localdocumentation", $this->localdocumentation); |
||
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 | } |
||
340 | } |