| Conditions | 3 |
| Paths | 1 |
| Total Lines | 56 |
| Code Lines | 33 |
| 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 |
||
| 62 | protected function registerClient(): void |
||
| 63 | { |
||
| 64 | $this->app->bind( |
||
| 65 | Formio::class, |
||
| 66 | function (Application $app) { |
||
| 67 | $formio = new Formio(Config::get('formio'), $app->make(Guzzle::class)); |
||
| 68 | |||
| 69 | $resourceIds = function () use ($formio) { |
||
| 70 | $id = $formio->login() |
||
| 71 | ->request('form?name=user')[0]['_id']; |
||
| 72 | |||
| 73 | $formio->logout(); |
||
| 74 | |||
| 75 | return $id; |
||
| 76 | }; |
||
| 77 | |||
| 78 | // If the formio id is null, then get it or a cached value for the user resource |
||
| 79 | if (empty(Config::get('formio.user.form'))) { |
||
| 80 | Config::set( |
||
| 81 | 'formio.user.form', |
||
| 82 | Cache::remember( |
||
| 83 | 'formio.id', |
||
| 84 | Carbon::now() |
||
| 85 | ->addDay(), |
||
| 86 | $resourceIds |
||
| 87 | ) |
||
| 88 | ); |
||
| 89 | |||
| 90 | $formio->setConfigs(Config::get('formio')); |
||
| 91 | } |
||
| 92 | |||
| 93 | $roleIds = function () use ($formio) { |
||
| 94 | $roles = (array)$formio->login() |
||
| 95 | ->request('role?title=Authenticated')[0]['_id']; |
||
| 96 | |||
| 97 | $formio->logout(); |
||
| 98 | |||
| 99 | return $roles; |
||
| 100 | }; |
||
| 101 | |||
| 102 | // If the user roles are null, then get it or a cached value for authenticated user |
||
| 103 | if (empty(Config::get('formio.user.roles'))) { |
||
| 104 | Config::set( |
||
| 105 | 'formio.user.roles', |
||
| 106 | Cache::remember( |
||
| 107 | 'formio.user.roles', |
||
| 108 | Carbon::now() |
||
| 109 | ->addDay(), |
||
| 110 | $roleIds |
||
| 111 | ) |
||
| 112 | ); |
||
| 113 | |||
| 114 | $formio->setConfigs(Config::get('formio')); |
||
| 115 | } |
||
| 116 | |||
| 117 | return $formio; |
||
| 118 | } |
||
| 122 |