| Conditions | 4 |
| Paths | 10 |
| Total Lines | 51 |
| Code Lines | 35 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 |
||
| 47 | public function handle(IdFilter $IdFilter, Closure $next) |
||
| 48 | { |
||
| 49 | if (!$IdFilter->isSuccessful()) { |
||
| 50 | |||
| 51 | $secKey = $this->generateKey($this->partnerId, $this->apiKey); |
||
| 52 | $jobId = md5(time() . rand()); |
||
| 53 | |||
| 54 | $body = [ |
||
| 55 | 'partner_id' => $this->partnerId, |
||
| 56 | 'sec_key' => $secKey[0], |
||
| 57 | 'timestamp' => $secKey[1], |
||
| 58 | 'country' => strtoupper($IdFilter->getCountry()), |
||
| 59 | 'id_type' => $IdFilter->getIdType(), |
||
| 60 | 'id_number' => $IdFilter->getIdNumber(), |
||
| 61 | 'first_name' => $IdFilter->getFirstName(), |
||
| 62 | 'last_name' => $IdFilter->getLastName(), |
||
| 63 | 'dob' => $IdFilter->getDOB(), |
||
| 64 | 'phone_number' => $IdFilter->getPhoneNumber(), |
||
| 65 | 'company' => $IdFilter->getCompany(), |
||
| 66 | 'partner_params' => [ |
||
| 67 | 'job_type' => 5, |
||
| 68 | 'job_id' => $jobId, |
||
| 69 | 'user_id' => $IdFilter->getUserId() |
||
| 70 | ] |
||
| 71 | ]; |
||
| 72 | |||
| 73 | try { |
||
| 74 | $response = $this->process('POST', '/v1/id_verification', array_filter($body)); |
||
| 75 | |||
| 76 | $result = $response->getResponse(); |
||
| 77 | |||
| 78 | if ($result['IsFinalResult']) { |
||
| 79 | $IdFilter->confirmSuccess(); |
||
| 80 | $IdFilter->setHandler($this->handler); |
||
| 81 | |||
| 82 | $IdFilter->setData([ |
||
| 83 | 'handler' => $IdFilter->getHandler(), |
||
| 84 | 'country' => $IdFilter->getCountry(), |
||
| 85 | 'message' => $IdFilter->getIDType() . ' Verified' . ' Successfully', |
||
| 86 | 'data' => $result |
||
| 87 | ]); |
||
| 88 | |||
| 89 | return $IdFilter->getData(); |
||
| 90 | } |
||
| 91 | } catch (\Exception $e) { |
||
| 92 | $IdFilter->setError(['error' => $e->getMessage()]); |
||
| 93 | |||
| 94 | return $next($IdFilter); |
||
| 95 | } |
||
| 96 | } |
||
| 97 | return $next($IdFilter); |
||
| 98 | } |
||
| 121 |