Conditions | 10 |
Paths | 49 |
Total Lines | 35 |
Code Lines | 24 |
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 | public static function fromJson($json): Response |
||
66 | { |
||
67 | $responseData = Json::decode($json); |
||
68 | |||
69 | if (!$responseData) { |
||
70 | return new Response(false, [VerifyReCaptcha::E_INVALID_JSON]); |
||
71 | } |
||
72 | |||
73 | $hostname = isset($responseData['hostname']) ? $responseData['hostname'] : null; |
||
74 | $challengeTs = isset($responseData['challenge_ts']) ? $responseData['challenge_ts'] : null; |
||
75 | $score = isset($responseData['score']) ? floatval($responseData['score']) : null; |
||
76 | $action = isset($responseData['action']) ? $responseData['action'] : null; |
||
77 | |||
78 | if (isset($responseData['success']) && $responseData['success'] == true) { |
||
79 | return new Response(true, [], $hostname, $challengeTs, $score, $action); |
||
80 | } |
||
81 | |||
82 | if (isset($responseData['error-codes']) && is_array($responseData['error-codes'])) { |
||
83 | return new Response( |
||
84 | false, |
||
85 | $responseData['error-codes'], |
||
86 | $hostname, |
||
87 | $challengeTs, |
||
88 | $score, |
||
89 | $action |
||
90 | ); |
||
91 | } |
||
92 | |||
93 | return new Response( |
||
94 | false, |
||
95 | [VerifyReCaptcha::E_UNKNOWN_ERROR], |
||
96 | $hostname, |
||
97 | $challengeTs, |
||
98 | $score, |
||
99 | $action |
||
100 | ); |
||
204 |