| Conditions | 12 |
| Paths | 122 |
| Total Lines | 46 |
| Code Lines | 26 |
| 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 |
||
| 62 | public static function getThumbnailMeta(string $inputDomain, string $url): array |
||
| 63 | { |
||
| 64 | // Load JSON rule files. |
||
| 65 | $jsonFiles = ConfigManager::get('settings.rules_filename', ['rules.json']); |
||
| 66 | $allRules = []; |
||
| 67 | foreach ($jsonFiles as $file) { |
||
| 68 | $allRules = array_merge($allRules, DataUtils::loadJson(FileUtils::RESOURCES_PATH . $file)); |
||
| 69 | } |
||
| 70 | |||
| 71 | $domain = null; |
||
| 72 | |||
| 73 | foreach ($allRules as $value) { |
||
| 74 | static::checkMetaFormat($value); |
||
| 75 | |||
| 76 | $domainFound = false; |
||
| 77 | foreach ($value['domains'] as $domain) { |
||
| 78 | if (strpos($inputDomain, $domain) !== false) { |
||
| 79 | $domainFound = true; |
||
| 80 | break; |
||
| 81 | } |
||
| 82 | } |
||
| 83 | |||
| 84 | if (!$domainFound) { |
||
| 85 | continue; |
||
| 86 | } |
||
| 87 | |||
| 88 | if (!empty($value['url_exclude'])) { |
||
| 89 | preg_match(FinderUtils::buildRegex($value['url_exclude'], 'i'), $url, $match); |
||
| 90 | if (!empty($match)) { |
||
| 91 | continue; |
||
| 92 | } |
||
| 93 | } |
||
| 94 | |||
| 95 | if (!empty($value['url_require'])) { |
||
| 96 | preg_match(FinderUtils::buildRegex($value['url_require'], 'i'), $url, $match); |
||
| 97 | if (empty($match)) { |
||
| 98 | continue; |
||
| 99 | } |
||
| 100 | } |
||
| 101 | |||
| 102 | $value['rules'] = !empty($value['rules']) ? $value['rules'] : []; |
||
| 103 | $value['options'] = !empty($value['options']) ? $value['options'] : []; |
||
| 104 | return [$domain, $value['finder'], $value['rules'], $value['options']]; |
||
| 105 | } |
||
| 106 | |||
| 107 | throw new UnsupportedDomainException(); |
||
| 108 | } |
||
| 131 |