Conditions | 8 |
Paths | 18 |
Total Lines | 60 |
Code Lines | 38 |
Lines | 5 |
Ratio | 8.33 % |
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 |
||
51 | public function appPost(\Base $f3) |
||
52 | { |
||
53 | $this->csrf('@api_apps'); |
||
54 | $this->redirectLoggedOutUser(); |
||
55 | |||
56 | $view = 'apps/apps.phtml'; |
||
57 | $oAuth2Model = Models\OAuth2::instance(); |
||
58 | $appsMapper = $oAuth2Model->getAppsMapper(); |
||
59 | |||
60 | // filter input vars of request, set back into REQUEST |
||
61 | $appsMapper->copyfrom($f3->get('REQUEST')); |
||
62 | $data = $appsMapper->filter(); |
||
63 | $request = $f3->get('REQUEST'); |
||
64 | foreach ($data as $k => $v) { |
||
65 | if (array_key_exists($k, $request)) { |
||
66 | $f3->set('REQUEST.' . $k, $v); |
||
67 | } |
||
68 | } |
||
69 | |||
70 | // check app name exists |
||
71 | $db = \Registry::get('db'); |
||
72 | $m = clone $appsMapper; |
||
73 | if ($m->load(['LOWER('.$db->quotekey('name').') = LOWER(?)', $m->name]) && null !== $m->client_id) { |
||
74 | $this->notify(_('An app with that name is already in use!'), 'warning'); |
||
75 | $f3->set('form', $f3->get('REQUEST')); |
||
76 | echo \View::instance()->render($view); |
||
77 | return; |
||
78 | } |
||
79 | |||
80 | // check required fields |
||
81 | $appsMapper->validationRequired([ |
||
82 | 'name', |
||
83 | 'description', |
||
84 | 'callback_uri', |
||
85 | ]); |
||
86 | |||
87 | // at this point the app can be validated |
||
88 | if (true !== $appsMapper->validate()) { |
||
89 | $this->notify(['info' => $appsMapper->validationErrors($appsMapper->validate(false))]); |
||
90 | $f3->set('form', $f3->get('REQUEST')); |
||
91 | echo \View::instance()->render($view); |
||
92 | return; |
||
93 | } |
||
94 | |||
95 | $appsMapper->client_id = $appsMapper->setUUID('client_id'); |
||
96 | $appsMapper->client_secret = $appsMapper->setUUID('client_secret'); |
||
97 | $appsMapper->users_uuid = $f3->get('uuid'); |
||
98 | |||
99 | // admin group auto-approved |
||
100 | $scopes = $f3->get('userScopes'); |
||
101 | $appsMapper->status = in_array('admin', $scopes) ? 'approved' : 'registered'; |
||
102 | |||
103 | View Code Duplication | if ($appsMapper->save()) { |
|
104 | $this->notify(_('Your new app has been registered!'), 'success'); |
||
105 | } else { |
||
106 | $this->notify(_('App registration failed!'), 'error'); |
||
107 | } |
||
108 | |||
109 | $f3->reroute('@api_apps'); |
||
110 | } |
||
111 | |||
168 |