| Conditions | 8 |
| Paths | 7 |
| Total Lines | 64 |
| Code Lines | 42 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
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 |
||
| 73 | public function userOrg(Request $request) |
||
| 74 | { |
||
| 75 | $client = new Client(['base_uri' => env('GRAFANA_URL').'/api/']); |
||
| 76 | if ($request->user() && (!($request->user()->principal->isEmpty())) && $request->user()->principal[0]->roles) { |
||
| 77 | dd($request->user()->principal[0]->roles->code); |
||
| 78 | switch ($request->user()->principal[0]->roles->code) { |
||
| 79 | case 'PRINCIPAL': |
||
| 80 | $response = $client->request('post','orgs/2/users',[ |
||
| 81 | 'headers' => [ |
||
| 82 | 'Authorization' => 'Bearer '.env('GRAFANA_KEY'), |
||
| 83 | 'Accept' => 'application/json', |
||
| 84 | 'Content-Type' => 'application/json' |
||
| 85 | ], |
||
| 86 | 'body' => [ |
||
| 87 | 'role' => 'Viewer', |
||
| 88 | 'loginOrEmail' => $request->user()->email |
||
| 89 | ] |
||
| 90 | ]); |
||
| 91 | dd($response); |
||
| 92 | if($response){ |
||
| 93 | $data = |
||
| 94 | [ |
||
| 95 | [ |
||
| 96 | "orgId" => 2, |
||
| 97 | "userId" => $request->user()->id, |
||
| 98 | "role" => 'Viewer', |
||
| 99 | "name" => 'Schools', |
||
| 100 | "email" => $request->user()->email, |
||
| 101 | "login" => 'Schools', |
||
| 102 | ] |
||
| 103 | ]; |
||
| 104 | } |
||
| 105 | break; |
||
| 106 | case 'PROVINCIAL_COORDINATOR': |
||
| 107 | $data = |
||
| 108 | [ |
||
| 109 | [ |
||
| 110 | "orgId" => 3, |
||
| 111 | "userId" => $request->user()->user()->id, |
||
| 112 | "role" => 'Viewer', |
||
| 113 | "name" => 'province', |
||
| 114 | "email" => $request->user()->user()->email, |
||
| 115 | "login" => 'province', |
||
| 116 | ] |
||
| 117 | ]; |
||
| 118 | case 'ZONAL_COORDINATOR': |
||
| 119 | $data = |
||
| 120 | [ |
||
| 121 | [ |
||
| 122 | "orgId" => 3, |
||
| 123 | "userId" => $request->user()->user()->id, |
||
| 124 | "role" => 'Viewer', |
||
| 125 | "name" => 'zone', |
||
| 126 | "email" => $request->user()->user()->email, |
||
| 127 | "login" => 'zone', |
||
| 128 | ] |
||
| 129 | ]; |
||
| 130 | default: |
||
| 131 | # code... |
||
| 132 | break; |
||
| 133 | } |
||
| 134 | |||
| 135 | } |
||
| 136 | return $data; |
||
| 137 | } |
||
| 139 |