| Conditions | 19 |
| Paths | 963 |
| Total Lines | 97 |
| Code Lines | 56 |
| 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 |
||
| 23 | public function parseNzbFileList(string $nzb, array $options = []): array |
||
| 24 | { |
||
| 25 | $defaults = [ |
||
| 26 | 'no-file-key' => true, |
||
| 27 | 'strip-count' => false, |
||
| 28 | ]; |
||
| 29 | $options += $defaults; |
||
| 30 | |||
| 31 | $i = 0; |
||
| 32 | $result = []; |
||
| 33 | |||
| 34 | if (! $nzb) { |
||
| 35 | return $result; |
||
| 36 | } |
||
| 37 | |||
| 38 | $xml = @simplexml_load_string(str_replace("\x0F", '', $nzb)); |
||
| 39 | if (! $xml || strtolower($xml->getName()) !== 'nzb') { |
||
| 40 | return $result; |
||
| 41 | } |
||
| 42 | |||
| 43 | foreach ($xml->file as $file) { |
||
| 44 | // Subject. |
||
| 45 | $title = (string) $file->attributes()->subject; |
||
|
|
|||
| 46 | |||
| 47 | if ($options['no-file-key'] === false) { |
||
| 48 | $i = $title; |
||
| 49 | if ($options['strip-count']) { |
||
| 50 | // Strip file / part count to get proper sorting. |
||
| 51 | $i = preg_replace('#\d+[- ._]?(/|\||[o0]f)[- ._]?\d+?(?![- ._]\d)#i', '', $i); |
||
| 52 | // Change .rar and .par2 to be sorted before .part0x.rar and .volxxx+xxx.par2 |
||
| 53 | if (str_contains($i, '.par2') && ! preg_match('#\.vol\d+\+\d+\.par2#i', $i)) { |
||
| 54 | $i = str_replace('.par2', '.vol0.par2', $i); |
||
| 55 | } elseif (preg_match('#\.rar[^a-z0-9]#i', $i) && ! preg_match('#\.part\d+\.rar$#i', $i)) { |
||
| 56 | $i = preg_replace('#\.rar(?:[^a-z0-9])#i', '.part0.rar', $i); |
||
| 57 | } |
||
| 58 | } |
||
| 59 | } |
||
| 60 | |||
| 61 | $result[$i]['title'] = $title; |
||
| 62 | |||
| 63 | // Extensions. |
||
| 64 | if (preg_match( |
||
| 65 | '/\.(\d{2,3}|7z|ace|ai7|srr|srt|sub|aiff|asc|avi|audio|bin|bz2|' |
||
| 66 | .'c|cfc|cfm|chm|class|conf|cpp|cs|css|csv|cue|deb|divx|doc|dot|' |
||
| 67 | .'eml|enc|exe|file|gif|gz|hlp|htm|html|image|iso|jar|java|jpeg|' |
||
| 68 | .'jpg|js|lua|m|m3u|mkv|mm|mov|mp3|mp4|mpg|nfo|nzb|odc|odf|odg|odi|odp|' |
||
| 69 | .'ods|odt|ogg|par2|parity|pdf|pgp|php|pl|png|ppt|ps|py|r\d{2,3}|' |
||
| 70 | .'ram|rar|rb|rm|rpm|rtf|sfv|sig|sql|srs|swf|sxc|sxd|sxi|sxw|tar|' |
||
| 71 | .'tex|tgz|txt|vcf|video|vsd|wav|wma|wmv|xls|xml|xpi|xvid|zip7|zip)' |
||
| 72 | .'[" ](?!([\)|\-]))/i', |
||
| 73 | $title, |
||
| 74 | $ext |
||
| 75 | ) |
||
| 76 | ) { |
||
| 77 | if (preg_match('/\.r\d{2,3}/i', $ext[0])) { |
||
| 78 | $ext[1] = 'rar'; |
||
| 79 | } |
||
| 80 | $result[$i]['ext'] = strtolower($ext[1]); |
||
| 81 | } else { |
||
| 82 | $result[$i]['ext'] = ''; |
||
| 83 | } |
||
| 84 | |||
| 85 | $fileSize = $numSegments = 0; |
||
| 86 | |||
| 87 | // Parts. |
||
| 88 | if (! isset($result[$i]['segments'])) { |
||
| 89 | $result[$i]['segments'] = []; |
||
| 90 | } |
||
| 91 | |||
| 92 | // File size. |
||
| 93 | foreach ($file->segments->segment as $segment) { |
||
| 94 | $result[$i]['segments'][] = (string) $segment; |
||
| 95 | $fileSize += $segment->attributes()->bytes; |
||
| 96 | $numSegments++; |
||
| 97 | } |
||
| 98 | $result[$i]['size'] = $fileSize; |
||
| 99 | |||
| 100 | // File completion. |
||
| 101 | if (preg_match('/(\d+)\)$/', $title, $parts)) { |
||
| 102 | $result[$i]['partstotal'] = $parts[1]; |
||
| 103 | } |
||
| 104 | $result[$i]['partsactual'] = $numSegments; |
||
| 105 | |||
| 106 | // Groups. |
||
| 107 | if (! isset($result[$i]['groups'])) { |
||
| 108 | $result[$i]['groups'] = []; |
||
| 109 | } |
||
| 110 | foreach ($file->groups->group as $g) { |
||
| 111 | $result[$i]['groups'][] = (string) $g; |
||
| 112 | } |
||
| 113 | |||
| 114 | if ($options['no-file-key']) { |
||
| 115 | $i++; |
||
| 116 | } |
||
| 117 | } |
||
| 118 | |||
| 119 | return $result; |
||
| 120 | } |
||
| 311 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.