| Conditions | 11 |
| Paths | 29 |
| Total Lines | 38 |
| Code Lines | 21 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 2 |
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 |
||
| 27 | public function filter(array $videos, array $selectedFormats = []) : array |
||
| 28 | { |
||
| 29 | $outVideos = []; |
||
| 30 | sort($selectedFormats, SORT_NUMERIC); |
||
| 31 | |||
| 32 | foreach ($videos as $video) { |
||
| 33 | if (isset($video['format'])) { |
||
| 34 | $formatFound = $this->checkContainsAudioAndVideoFormat($video['format']); |
||
| 35 | if (isset($formatFound)) { |
||
| 36 | if (array_key_exists($formatFound, $outVideos)) { |
||
| 37 | continue; |
||
| 38 | } |
||
| 39 | if ($this->hasValidator()) { |
||
| 40 | if ($this->getValidator()->isValid($video['url'])) { |
||
| 41 | $outVideos[$formatFound] = $video['url']; |
||
| 42 | } |
||
| 43 | } else { |
||
| 44 | $outVideos[$formatFound] = $video['url']; |
||
| 45 | } |
||
| 46 | |||
| 47 | if($selectedFormats != []) { |
||
| 48 | foreach ($selectedFormats as $selectedFormat) { |
||
| 49 | if (array_key_exists($selectedFormat, $outVideos)) { |
||
| 50 | return [$selectedFormat => $outVideos[$selectedFormat]]; |
||
| 51 | } |
||
| 52 | } |
||
| 53 | } |
||
| 54 | } |
||
| 55 | } |
||
| 56 | } |
||
| 57 | |||
| 58 | if ($outVideos == []) { |
||
| 59 | throw YoutubeDownloaderException::videoURLsNotFound(); |
||
| 60 | } |
||
| 61 | |||
| 62 | ksort($outVideos, SORT_NUMERIC); |
||
| 63 | |||
| 64 | return $outVideos; |
||
| 65 | } |
||
| 80 |