| Conditions | 11 |
| Paths | 4 |
| Total Lines | 27 |
| 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 |
||
| 22 | public static function getInstance(array $params, Client $client = null) |
||
| 23 | { |
||
| 24 | if(!isset($params[ControlPayParameterConst::CONTROLPAY_OAUTH_TYPE])) |
||
| 25 | throw new \Exception("Tipo de autenticação não especificado"); |
||
| 26 | |||
| 27 | switch ($params[ControlPayParameterConst::CONTROLPAY_OAUTH_TYPE]) |
||
| 28 | { |
||
| 29 | case BasicAuthentication::class: |
||
| 30 | return new BasicAuthentication( |
||
| 31 | isset($params[ControlPayParameterConst::CONTROLPAY_USER]) ?$params[ControlPayParameterConst::CONTROLPAY_USER] : null, |
||
| 32 | isset($params[ControlPayParameterConst::CONTROLPAY_PWD]) ?$params[ControlPayParameterConst::CONTROLPAY_PWD] : null, |
||
| 33 | isset($params[ControlPayParameterConst::CONTROLPAY_KEY]) ?$params[ControlPayParameterConst::CONTROLPAY_KEY] : null |
||
| 34 | ); |
||
| 35 | break; |
||
|
|
|||
| 36 | case KeyQueryStringAuthentication::class: |
||
| 37 | return new KeyQueryStringAuthentication( |
||
| 38 | isset($params[ControlPayParameterConst::CONTROLPAY_USER]) ?$params[ControlPayParameterConst::CONTROLPAY_USER] : null, |
||
| 39 | isset($params[ControlPayParameterConst::CONTROLPAY_PWD]) ?$params[ControlPayParameterConst::CONTROLPAY_PWD] : null, |
||
| 40 | isset($params[ControlPayParameterConst::CONTROLPAY_KEY]) ?$params[ControlPayParameterConst::CONTROLPAY_KEY] : null, |
||
| 41 | isset($params[ControlPayParameterConst::CONTROLPAY_DEFAULT_PESSOA_ID]) ?$params[ControlPayParameterConst::CONTROLPAY_DEFAULT_PESSOA_ID] : null, |
||
| 42 | $client |
||
| 43 | ); |
||
| 44 | break; |
||
| 45 | } |
||
| 46 | |||
| 47 | throw new \Exception("Implementação não tratada no factory"); |
||
| 48 | } |
||
| 49 | } |
The break statement is not necessary if it is preceded for example by a return statement:
If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.