Conditions | 9 |
Paths | 26 |
Total Lines | 60 |
Code Lines | 33 |
Lines | 0 |
Ratio | 0 % |
Tests | 28 |
CRAP Score | 9.2815 |
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 |
||
215 | 2 | public function afterCreate() |
|
216 | { |
||
217 | /** |
||
218 | * User signing up for a new app / plan |
||
219 | * How do we know? well he doesnt have a default_company |
||
220 | */ |
||
221 | 2 | if ($this->isOwner()) { |
|
222 | 1 | $company = new Companies(); |
|
223 | 1 | $company->name = $this->defaultCompanyName; |
|
224 | 1 | $company->users_id = $this->getId(); |
|
225 | |||
226 | 1 | if (!$company->save()) { |
|
227 | throw new Exception(current($company->getMessages())); |
||
228 | } |
||
229 | |||
230 | 1 | $this->default_company = $company->getId(); |
|
231 | |||
232 | 1 | if (!$this->update()) { |
|
233 | throw new Exception(current($this->getMessages())); |
||
234 | } |
||
235 | |||
236 | 1 | $this->default_company_branch = $this->defaultCompany->branch->getId(); |
|
1 ignored issue
–
show
|
|||
237 | 1 | $this->update(); |
|
238 | |||
239 | //update default subscription free trial |
||
240 | 1 | $company->app->subscriptions_id = $this->startFreeTrial()->getId(); |
|
241 | 1 | $company->update(); |
|
242 | } else { |
||
243 | //we have the company id |
||
244 | 1 | if (empty($this->default_company_branch)) { |
|
245 | $this->default_company_branch = $this->defaultCompany->branch->getId(); |
||
246 | } |
||
247 | } |
||
248 | |||
249 | //Create new company associated company |
||
250 | 2 | $newUserAssocCompany = new UsersAssociatedCompany(); |
|
251 | 2 | $newUserAssocCompany->users_id = $this->id; |
|
252 | 2 | $newUserAssocCompany->company_id = $this->default_company; |
|
253 | 2 | $newUserAssocCompany->identify_id = 1; |
|
254 | 2 | $newUserAssocCompany->user_active = 1; |
|
255 | 2 | $newUserAssocCompany->user_role = $this->roles_id == 1 ? 'admins' : 'users'; |
|
256 | |||
257 | 2 | if (!$newUserAssocCompany->save()) { |
|
258 | throw new UnprocessableEntityHttpException((string)current($newUserAssocCompany->getMessages())); |
||
259 | } |
||
260 | |||
261 | //Insert record into user_roles |
||
262 | 2 | $userRole = new UserRoles(); |
|
263 | 2 | $userRole->users_id = $this->id; |
|
264 | 2 | $userRole->roles_id = $this->roles_id; |
|
265 | 2 | $userRole->apps_id = $this->di->getApp()->getId(); |
|
266 | 2 | $userRole->company_id = $this->default_company; |
|
267 | |||
268 | 2 | if (!$userRole->save()) { |
|
269 | throw new UnprocessableEntityHttpException((string)current($userRole->getMessages())); |
||
270 | } |
||
271 | |||
272 | //update user activity when its not a empty user |
||
273 | 2 | if (!$this->isOwner()) { |
|
274 | 2 | $this->updateAppActivityLimit(); |
|
275 | } |
||
278 |