| Conditions | 13 |
| Paths | 78 |
| Total Lines | 58 |
| Code Lines | 33 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 1 | 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 |
||
| 38 | public function getCodecovCoverage() |
||
| 39 | { |
||
| 40 | $slug = $this->getSuite()->getRepositorySlug(); |
||
| 41 | try { |
||
| 42 | $result = $this->getRequestClient() |
||
| 43 | ->get('https://codecov.io/api/gh/' . $slug . '/branches') |
||
| 44 | ->getBody(); |
||
| 45 | } catch (Exception $ex) { |
||
| 46 | if ($logger = $this->getSuite()->getLogger()) { |
||
| 47 | $logger->debug($ex->getMessage()); |
||
| 48 | } |
||
| 49 | $result = ''; |
||
| 50 | } |
||
| 51 | $response = json_decode($result, true); |
||
| 52 | |||
| 53 | // Fetch failure |
||
| 54 | if (!$response) { |
||
| 55 | return false; |
||
| 56 | } |
||
| 57 | |||
| 58 | // Not set up (404) |
||
| 59 | if (isset($response['meta']['status']) && (int) $response['meta']['status'] !== 200) { |
||
| 60 | return false; |
||
| 61 | } |
||
| 62 | |||
| 63 | $defaultBranch = 'master'; |
||
| 64 | if (isset($response['repo']['branch'])) { |
||
| 65 | $defaultBranch = $response['repo']['branch']; |
||
| 66 | } |
||
| 67 | |||
| 68 | try { |
||
| 69 | $result = $this->getRequestClient() |
||
| 70 | ->get('https://codecov.io/api/gh/' . $slug . '/branch/' . $defaultBranch) |
||
| 71 | ->getBody(); |
||
| 72 | } catch (Exception $ex) { |
||
| 73 | if ($logger = $this->getSuite()->getLogger()) { |
||
| 74 | $logger->debug($ex->getMessage()); |
||
| 75 | } |
||
| 76 | $result = ''; |
||
| 77 | } |
||
| 78 | $response = json_decode($result, true); |
||
| 79 | |||
| 80 | // Fetch failure |
||
| 81 | if (!$response) { |
||
| 82 | return false; |
||
| 83 | } |
||
| 84 | |||
| 85 | // Not set up (404) |
||
| 86 | if (isset($response['meta']['status']) && (int) $response['meta']['status'] !== 200) { |
||
| 87 | return false; |
||
| 88 | } |
||
| 89 | |||
| 90 | // Get coverage result |
||
| 91 | if (isset($response['commit']['totals']['c'])) { |
||
| 92 | return $response['commit']['totals']['c']; |
||
| 93 | } |
||
| 94 | |||
| 95 | return 0; |
||
| 96 | } |
||
| 163 |