| Conditions | 12 |
| Paths | 576 |
| Total Lines | 47 |
| Code Lines | 31 |
| 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 declare(strict_types=1); |
||
| 31 | public function __construct(string $url) { |
||
| 32 | parent::__construct(); |
||
| 33 | |||
| 34 | $this->url = $url; |
||
| 35 | $this->contentLength = null; |
||
| 36 | |||
| 37 | $reqHeaders = []; |
||
| 38 | if (isset($_SERVER['HTTP_ACCEPT'])) { |
||
| 39 | $reqHeaders['Accept'] = $_SERVER['HTTP_ACCEPT']; |
||
| 40 | } |
||
| 41 | if (isset($_SERVER['HTTP_RANGE'])) { |
||
| 42 | $reqHeaders['Range'] = $_SERVER['HTTP_RANGE']; |
||
| 43 | } |
||
| 44 | |||
| 45 | $this->context = HttpUtil::createContext(null, $reqHeaders, /*maxRedirects=*/0); |
||
| 46 | |||
| 47 | // Get headers from the source and relay the important ones to our client. Handle the redirection manually |
||
| 48 | // since the platform redirection didn't seem to work in all cases, see https://github.com/owncloud/music/issues/1209. |
||
| 49 | $redirectsAllowed = 20; |
||
| 50 | do { |
||
| 51 | $sourceHeaders = HttpUtil::getUrlHeaders($this->url, $this->context, /*convertKeysToLower=*/true); |
||
| 52 | $status = $sourceHeaders['status_code']; |
||
| 53 | $redirect = ($status >= 300 && $status < 400 && isset($sourceHeaders['location'])); |
||
| 54 | if ($redirect) { |
||
| 55 | if ($redirectsAllowed-- > 0) { |
||
| 56 | $this->url = $sourceHeaders['location']; |
||
| 57 | } else { |
||
| 58 | $redirect = false; |
||
| 59 | $status = Http::STATUS_LOOP_DETECTED; |
||
| 60 | } |
||
| 61 | } |
||
| 62 | } while ($redirect); |
||
| 63 | |||
| 64 | $this->setStatus($status); |
||
| 65 | |||
| 66 | if (isset($sourceHeaders['content-type'])) { |
||
| 67 | $this->addHeader('Content-Type', $sourceHeaders['content-type']); |
||
| 68 | } |
||
| 69 | if (isset($sourceHeaders['accept-ranges'])) { |
||
| 70 | $this->addHeader('Accept-Ranges', $sourceHeaders['accept-ranges']); |
||
| 71 | } |
||
| 72 | if (isset($sourceHeaders['content-range'])) { |
||
| 73 | $this->addHeader('Content-Range', $sourceHeaders['content-range']); |
||
| 74 | } |
||
| 75 | if (isset($sourceHeaders['content-length'])) { |
||
| 76 | $this->addHeader('Content-Length', $sourceHeaders['content-length']); |
||
| 77 | $this->contentLength = (int)$sourceHeaders['content-length']; |
||
| 78 | } |
||
| 98 |