Conditions | 5 |
Paths | 5 |
Total Lines | 61 |
Code Lines | 44 |
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 |
||
30 | public function save() |
||
31 | { |
||
32 | if ($this->isNew()) { |
||
33 | // insert |
||
34 | $statement = $this->dbObject->prepare(<<<SQL |
||
35 | INSERT INTO requestform ( |
||
36 | enabled, domain, name, publicendpoint, formcontent, overridequeue |
||
37 | ) VALUES ( |
||
38 | :enabled, :domain, :name, :publicendpoint, :formcontent, :overridequeue |
||
39 | ); |
||
40 | SQL |
||
41 | ); |
||
42 | |||
43 | $statement->bindValue(":enabled", $this->enabled); |
||
44 | $statement->bindValue(":domain", $this->domain); |
||
45 | $statement->bindValue(":name", $this->name); |
||
46 | $statement->bindValue(":publicendpoint", $this->publicendpoint); |
||
47 | $statement->bindValue(":formcontent", $this->formcontent); |
||
48 | $statement->bindValue(":overridequeue", $this->overridequeue); |
||
49 | |||
50 | if ($statement->execute()) { |
||
51 | $this->id = (int)$this->dbObject->lastInsertId(); |
||
52 | } |
||
53 | else { |
||
54 | throw new Exception($statement->errorInfo()); |
||
|
|||
55 | } |
||
56 | } |
||
57 | else { |
||
58 | $statement = $this->dbObject->prepare(<<<SQL |
||
59 | UPDATE requestform SET |
||
60 | enabled = :enabled, |
||
61 | domain = :domain, |
||
62 | name = :name, |
||
63 | publicendpoint = :publicendpoint, |
||
64 | formcontent = :formcontent, |
||
65 | overridequeue = :overridequeue, |
||
66 | |||
67 | updateversion = updateversion + 1 |
||
68 | WHERE id = :id AND updateversion = :updateversion; |
||
69 | SQL |
||
70 | ); |
||
71 | |||
72 | $statement->bindValue(":enabled", $this->enabled); |
||
73 | $statement->bindValue(":domain", $this->domain); |
||
74 | $statement->bindValue(":name", $this->name); |
||
75 | $statement->bindValue(":publicendpoint", $this->publicendpoint); |
||
76 | $statement->bindValue(":formcontent", $this->formcontent); |
||
77 | $statement->bindValue(":overridequeue", $this->overridequeue); |
||
78 | |||
79 | $statement->bindValue(':id', $this->id); |
||
80 | $statement->bindValue(':updateversion', $this->updateversion); |
||
81 | |||
82 | if (!$statement->execute()) { |
||
83 | throw new Exception($statement->errorInfo()); |
||
84 | } |
||
85 | |||
86 | if ($statement->rowCount() !== 1) { |
||
87 | throw new OptimisticLockFailedException(); |
||
88 | } |
||
89 | |||
90 | $this->updateversion++; |
||
91 | } |
||
191 | } |