Conditions | 10 |
Paths | 7 |
Total Lines | 41 |
Code Lines | 29 |
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 |
||
65 | private function create401ErrorMessage(RequestException $exception) |
||
66 | { |
||
67 | $request = $exception->getRequest(); |
||
68 | $response = $exception->getResponse(); |
||
69 | |||
70 | $uri = $request->getUri(); |
||
71 | $queryParams = \GuzzleHttp\Psr7\parse_query($uri->getQuery()); |
||
72 | |||
73 | if ( |
||
74 | !$request->hasHeader('Authorization') |
||
75 | && !$request->hasHeader('Authentication') |
||
76 | && !array_key_exists('jwt', $queryParams) |
||
77 | && empty($queryParams['jwt']) |
||
78 | ) { |
||
79 | return 'Authentication Required'; |
||
80 | } |
||
81 | |||
82 | switch ($response->getHeader('X-Seraph-LoginReason')) { |
||
83 | case 'AUTHENTICATED_FAILED': |
||
84 | $msg = 'Could not be authenticated'; |
||
85 | break; |
||
86 | |||
87 | case 'AUTHENTICATION_DENIED': |
||
88 | $msg = 'Not allowed to login'; |
||
89 | break; |
||
90 | |||
91 | case 'AUTHORIZATION_FAILED': |
||
92 | case 'AUTHORISATION_FAILED': |
||
93 | $msg = 'Could not be authorised'; |
||
94 | break; |
||
95 | |||
96 | case 'OUT': |
||
97 | $msg = 'Logged out'; |
||
98 | break; |
||
99 | default: |
||
100 | $msg = 'Invalid Credentials'; |
||
101 | break; |
||
102 | } |
||
103 | |||
104 | return $msg; |
||
105 | } |
||
106 | } |
||
107 |