| Conditions | 10 |
| Paths | 45 |
| Total Lines | 30 |
| Code Lines | 17 |
| 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 |
||
| 111 | private function createElement($name, StreamInterface $stream, $filename, array $headers) |
||
| 112 | { |
||
| 113 | // Set a default content-disposition header if one was no provided |
||
| 114 | $disposition = $this->getHeader($headers, 'content-disposition'); |
||
| 115 | if (!$disposition) { |
||
| 116 | $headers['Content-Disposition'] = ($filename === '0' || $filename) |
||
| 117 | ? sprintf('form-data; name="%s"; filename="%s"', |
||
| 118 | $name, |
||
| 119 | basename($filename)) |
||
| 120 | : "form-data; name=\"{$name}\""; |
||
| 121 | } |
||
| 122 | |||
| 123 | // Set a default content-length header if one was no provided |
||
| 124 | $length = $this->getHeader($headers, 'content-length'); |
||
| 125 | if (!$length) { |
||
| 126 | if ($length = $stream->getSize()) { |
||
| 127 | $headers['Content-Length'] = (string) $length; |
||
| 128 | } |
||
| 129 | } |
||
| 130 | |||
| 131 | // Set a default Content-Type if one was not supplied |
||
| 132 | $type = $this->getHeader($headers, 'content-type'); |
||
| 133 | if (!$type && ($filename === '0' || $filename)) { |
||
| 134 | if ($type = mimetype_from_filename($filename)) { |
||
| 135 | $headers['Content-Type'] = $type; |
||
| 136 | } |
||
| 137 | } |
||
| 138 | |||
| 139 | return [$stream, $headers]; |
||
| 140 | } |
||
| 141 | |||
| 154 |