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 |
||
34 | public function filter(array $videos, array $selectedFormats = []) : array |
||
35 | { |
||
36 | $outVideos = []; |
||
37 | sort($selectedFormats, SORT_NUMERIC); |
||
38 | |||
39 | foreach ($videos as $video) { |
||
40 | if (isset($video['format'])) { |
||
41 | $formatFound = $this->checkContainsAudioAndVideoFormat($video['format']); |
||
42 | if (isset($formatFound)) { |
||
43 | if (array_key_exists($formatFound, $outVideos)) { |
||
44 | continue; |
||
45 | } |
||
46 | if ($this->hasValidator()) { |
||
47 | if ($this->getValidator()->isValid($video['url'])) { |
||
48 | $outVideos[$formatFound] = $video['url']; |
||
49 | } |
||
50 | } else { |
||
51 | $outVideos[$formatFound] = $video['url']; |
||
52 | } |
||
53 | |||
54 | if($selectedFormats != []) { |
||
55 | foreach ($selectedFormats as $selectedFormat) { |
||
56 | if (array_key_exists($selectedFormat, $outVideos)) { |
||
57 | return [$selectedFormat => $outVideos[$selectedFormat]]; |
||
58 | } |
||
59 | } |
||
60 | } |
||
61 | } |
||
62 | } |
||
63 | } |
||
64 | |||
65 | if ($outVideos == []) { |
||
66 | throw YoutubeDownloaderException::videoURLsNotFound(); |
||
67 | } |
||
68 | |||
69 | ksort($outVideos, SORT_NUMERIC); |
||
70 | |||
71 | return $outVideos; |
||
72 | } |
||
89 |