Conditions | 5 |
Paths | 5 |
Total Lines | 89 |
Code Lines | 73 |
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 |
||
61 | public function save() |
||
62 | { |
||
63 | if ($this->isNew()) { |
||
64 | $statement = $this->dbObject->prepare(<<<SQL |
||
65 | INSERT INTO oauthidentity ( |
||
66 | user, iss, sub, aud, exp, iat, username, editcount, confirmed_email, blocked, registered, checkuser, |
||
67 | grantbasic, grantcreateaccount, granthighvolume, grantcreateeditmovepage |
||
68 | ) VALUES ( |
||
69 | :user, :iss, :sub, :aud, :exp, :iat, :username, :editcount, :confirmed_email, :blocked, :registered, |
||
70 | :checkuser, :grantbasic, :grantcreateaccount, :granthighvolume, :grantcreateeditmovepage |
||
71 | ) |
||
72 | SQL |
||
73 | ); |
||
74 | |||
75 | $statement->bindValue(':user', $this->user); |
||
76 | $statement->bindValue(':iss', $this->iss); |
||
77 | $statement->bindValue(':sub', $this->sub); |
||
78 | $statement->bindValue(':aud', $this->aud); |
||
79 | $statement->bindValue(':exp', $this->exp); |
||
80 | $statement->bindValue(':iat', $this->iat); |
||
81 | $statement->bindValue(':username', $this->username); |
||
82 | $statement->bindValue(':editcount', $this->editcount); |
||
83 | $statement->bindValue(':confirmed_email', $this->confirmed_email); |
||
84 | $statement->bindValue(':blocked', $this->blocked); |
||
85 | $statement->bindValue(':registered', $this->registered); |
||
86 | $statement->bindValue(':checkuser', $this->checkuser); |
||
87 | $statement->bindValue(':grantbasic', $this->grantbasic); |
||
88 | $statement->bindValue(':grantcreateaccount', $this->grantcreateaccount); |
||
89 | $statement->bindValue(':granthighvolume', $this->granthighvolume); |
||
90 | $statement->bindValue(':grantcreateeditmovepage', $this->grantcreateeditmovepage); |
||
91 | |||
92 | if ($statement->execute()) { |
||
93 | $this->id = (int)$this->dbObject->lastInsertId(); |
||
94 | } |
||
95 | else { |
||
96 | throw new Exception($statement->errorInfo()); |
||
|
|||
97 | } |
||
98 | } |
||
99 | else { |
||
100 | $statement = $this->dbObject->prepare(<<<SQL |
||
101 | UPDATE oauthidentity SET |
||
102 | iss = :iss |
||
103 | , sub = :sub |
||
104 | , aud = :aud |
||
105 | , exp = :exp |
||
106 | , iat = :iat |
||
107 | , username = :username |
||
108 | , editcount = :editcount |
||
109 | , confirmed_email = :confirmed_email |
||
110 | , blocked = :blocked |
||
111 | , registered = :registered |
||
112 | , checkuser = :checkuser |
||
113 | , grantbasic = :grantbasic |
||
114 | , grantcreateaccount = :grantcreateaccount |
||
115 | , granthighvolume = :granthighvolume |
||
116 | , grantcreateeditmovepage = :grantcreateeditmovepage |
||
117 | , updateversion = updateversion + 1 |
||
118 | WHERE id = :id AND updateversion = :updateversion |
||
119 | SQL |
||
120 | ); |
||
121 | |||
122 | $statement->bindValue(':iss', $this->iss); |
||
123 | $statement->bindValue(':sub', $this->sub); |
||
124 | $statement->bindValue(':aud', $this->aud); |
||
125 | $statement->bindValue(':exp', $this->exp); |
||
126 | $statement->bindValue(':iat', $this->iat); |
||
127 | $statement->bindValue(':username', $this->username); |
||
128 | $statement->bindValue(':editcount', $this->editcount); |
||
129 | $statement->bindValue(':confirmed_email', $this->confirmed_email); |
||
130 | $statement->bindValue(':blocked', $this->blocked); |
||
131 | $statement->bindValue(':registered', $this->registered); |
||
132 | $statement->bindValue(':checkuser', $this->checkuser); |
||
133 | $statement->bindValue(':grantbasic', $this->grantbasic); |
||
134 | $statement->bindValue(':grantcreateaccount', $this->grantcreateaccount); |
||
135 | $statement->bindValue(':granthighvolume', $this->granthighvolume); |
||
136 | $statement->bindValue(':grantcreateeditmovepage', $this->grantcreateeditmovepage); |
||
137 | |||
138 | $statement->bindValue(':id', $this->id); |
||
139 | $statement->bindValue(':updateversion', $this->updateversion); |
||
140 | |||
141 | if (!$statement->execute()) { |
||
142 | throw new Exception($statement->errorInfo()); |
||
143 | } |
||
144 | |||
145 | if ($statement->rowCount() !== 1) { |
||
146 | throw new OptimisticLockFailedException(); |
||
147 | } |
||
148 | |||
149 | $this->updateversion++; |
||
150 | } |
||
354 |