Conditions | 11 |
Paths | 16 |
Total Lines | 58 |
Code Lines | 39 |
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 |
||
41 | public function render(){ |
||
42 | if ($this->getStatus() === Http::STATUS_NOT_FOUND){ |
||
43 | return ''; |
||
44 | } |
||
45 | $info = $this->view->getFileInfo($this->path); |
||
46 | $this->ETag = $info['etag']; |
||
47 | |||
48 | $content = $this->view->file_get_contents($this->path); |
||
49 | $data = \OCA\Documents\Filter::read($content, $info['mimetype']); |
||
50 | $size = strlen($data['content']); |
||
51 | |||
52 | |||
53 | if (isset($this->request->server['HTTP_RANGE']) && !is_null($this->request->server['HTTP_RANGE'])){ |
||
54 | $isValidRange = preg_match('/^bytes=\d*-\d*(,\d*-\d*)*$/', $this->request->server['HTTP_RANGE']); |
||
55 | if (!$isValidRange){ |
||
56 | return $this->sendRangeNotSatisfiable($size); |
||
57 | } |
||
58 | |||
59 | $ranges = explode(',', substr($this->request->server['HTTP_RANGE'], 6)); |
||
60 | foreach ($ranges as $range){ |
||
61 | $parts = explode('-', $range); |
||
62 | |||
63 | if ($parts[0]==='' && $parts[1]=='') { |
||
64 | $this->sendNotSatisfiable($size); |
||
65 | } |
||
66 | if ($parts[0]==='') { |
||
67 | $start = $size - $parts[1]; |
||
68 | $end = $size - 1; |
||
69 | } else { |
||
70 | $start = $parts[0]; |
||
71 | $end = ($parts[1]==='') ? $size - 1 : $parts[1]; |
||
72 | } |
||
73 | |||
74 | if ($start > $end){ |
||
75 | $this->sendNotSatisfiable($size); |
||
76 | } |
||
77 | |||
78 | $buffer = substr($data['content'], $start, $end - $start); |
||
79 | $md5Sum = md5($buffer); |
||
80 | |||
81 | // send the headers and data |
||
82 | $this->addHeader('Content-Length', $end - $start); |
||
83 | $this->addHeader('Content-md5', $md5Sum); |
||
84 | $this->addHeader('Accept-Ranges', 'bytes'); |
||
85 | $this->addHeader('Content-Range', 'bytes ' . $start . '-' . ($end) . '/' . $size); |
||
86 | $this->addHeader('Connection', 'close'); |
||
87 | $this->addHeader('Content-Type', $data['mimetype']); |
||
88 | $this->addContentDispositionHeader(); |
||
89 | return $buffer; |
||
90 | } |
||
91 | } |
||
92 | |||
93 | $this->addHeader('Content-Type', $data['mimetype']); |
||
94 | $this->addContentDispositionHeader(); |
||
95 | $this->addHeader('Content-Length', $size); |
||
96 | |||
97 | return $data['content']; |
||
98 | } |
||
99 | |||
126 |