| Conditions | 3 |
| Paths | 1 |
| Total Lines | 57 |
| Code Lines | 35 |
| 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 |
||
| 20 | public function rules() |
||
| 21 | { |
||
| 22 | $validatedClient = fn () => !$this->hasErrors('client_id'); |
||
| 23 | |||
| 24 | return [ |
||
| 25 | [ |
||
| 26 | [ |
||
| 27 | 'authorized', |
||
| 28 | 'client_id', |
||
| 29 | 'response_type', |
||
| 30 | 'state', |
||
| 31 | 'redirect_uri', |
||
| 32 | ], |
||
| 33 | 'required', |
||
| 34 | ], |
||
| 35 | [['authorized'], 'boolean'], |
||
| 36 | [['redirect_uri'], 'url'], |
||
| 37 | [ |
||
| 38 | [ |
||
| 39 | 'client_id', |
||
| 40 | 'scopes', |
||
| 41 | 'response_type', |
||
| 42 | 'state', |
||
| 43 | 'redirect_uri', |
||
| 44 | ], |
||
| 45 | 'string', |
||
| 46 | ], |
||
| 47 | [ |
||
| 48 | ['client_id'], |
||
| 49 | 'exist', |
||
| 50 | 'targetClass' => OauthClients::class, |
||
| 51 | ], |
||
| 52 | [ |
||
| 53 | ['scopes'], |
||
| 54 | function ($attribute) { |
||
| 55 | try { |
||
| 56 | $this->getScopesList(); |
||
| 57 | } catch (IntegrityException $e) { |
||
| 58 | $this->addError($atribute, $e->getMessage()); |
||
|
|
|||
| 59 | } |
||
| 60 | }, |
||
| 61 | 'when' => $validatedClient, |
||
| 62 | ], |
||
| 63 | [ |
||
| 64 | ['redirect_uri'], |
||
| 65 | function ($attribute) { |
||
| 66 | if ( |
||
| 67 | !$this->getClientModel() |
||
| 68 | ->validateUri($this->redirect_uri) |
||
| 69 | ) { |
||
| 70 | $this->addError( |
||
| 71 | $attribute, |
||
| 72 | "Redirection URI not recognized by client." |
||
| 73 | ); |
||
| 74 | } |
||
| 75 | }, |
||
| 76 | 'when' => $validatedClient, |
||
| 77 | ], |
||
| 109 |