| Conditions | 10 |
| Paths | 6 |
| Total Lines | 35 |
| Code Lines | 21 |
| 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 |
||
| 29 | public function retrieve($uri) |
||
| 30 | { |
||
| 31 | set_error_handler(function () use ($uri) { |
||
| 32 | throw new ResourceNotFoundException('Schema not found at ' . $uri); |
||
| 33 | }); |
||
| 34 | $response = file_get_contents($uri); |
||
| 35 | restore_error_handler(); |
||
| 36 | |||
| 37 | if (false === $response) { |
||
| 38 | throw new ResourceNotFoundException('Schema not found at ' . $uri); |
||
| 39 | } |
||
| 40 | if ($response == '' |
||
| 41 | && substr($uri, 0, 7) == 'file://' && substr($uri, -1) == '/' |
||
| 42 | ) { |
||
| 43 | throw new ResourceNotFoundException('Schema not found at ' . $uri); |
||
| 44 | } |
||
| 45 | $this->contentType = null; |
||
| 46 | if (preg_match('/\b(yml|yaml)\b/', $uri)) { |
||
| 47 | $data = Yaml::parse($response); |
||
| 48 | |||
| 49 | return json_encode($data); |
||
| 50 | } |
||
| 51 | if (!empty($http_response_header)) { |
||
| 52 | foreach ($http_response_header as $header) { |
||
| 53 | if (0 < preg_match("/Content-Type:(\V*)/ims", $header, $match)) { |
||
| 54 | $actualContentType = trim($match[1]); |
||
| 55 | if (strpos($actualContentType, 'yaml')) { |
||
| 56 | return json_encode(Yaml::parse($response)); |
||
| 57 | } |
||
| 58 | } |
||
| 59 | } |
||
| 60 | } |
||
| 61 | |||
| 62 | return $response; |
||
| 63 | } |
||
| 64 | } |
||
| 65 |