| Total Complexity | 54 |
| Total Lines | 199 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
Complex classes like InstalledVersions often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use InstalledVersions, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 8 | class InstalledVersions |
||
| 9 | { |
||
| 10 | /** |
||
| 11 | @psalm-var |
||
| 12 | */ |
||
| 13 | private static $installed; |
||
| 14 | private static $canGetVendors; |
||
| 15 | /** |
||
| 16 | @psalm-var |
||
| 17 | */ |
||
| 18 | private static $installedByVendor = array(); |
||
| 19 | /** |
||
| 20 | @psalm-return |
||
| 21 | */ |
||
| 22 | public static function getInstalledPackages() |
||
| 23 | { |
||
| 24 | $packages = array(); |
||
| 25 | foreach (self::getInstalled() as $installed) { |
||
| 26 | $packages[] = \array_keys($installed['versions']); |
||
| 27 | } |
||
| 28 | if (1 === \count($packages)) { |
||
| 29 | return $packages[0]; |
||
| 30 | } |
||
| 31 | return \array_keys(\array_flip(\call_user_func_array('HumbugBox451\\array_merge', $packages))); |
||
| 32 | } |
||
| 33 | /** |
||
| 34 | @psalm-return |
||
| 35 | */ |
||
| 36 | public static function getInstalledPackagesByType($type) |
||
| 37 | { |
||
| 38 | $packagesByType = array(); |
||
| 39 | foreach (self::getInstalled() as $installed) { |
||
| 40 | foreach ($installed['versions'] as $name => $package) { |
||
| 41 | if (isset($package['type']) && $package['type'] === $type) { |
||
| 42 | $packagesByType[] = $name; |
||
| 43 | } |
||
| 44 | } |
||
| 45 | } |
||
| 46 | return $packagesByType; |
||
| 47 | } |
||
| 48 | public static function isInstalled($packageName, $includeDevRequirements = \true) |
||
| 56 | } |
||
| 57 | public static function satisfies(VersionParser $parser, $packageName, $constraint) |
||
| 58 | { |
||
| 59 | $constraint = $parser->parseConstraints((string) $constraint); |
||
| 60 | $provided = $parser->parseConstraints(self::getVersionRanges($packageName)); |
||
| 61 | return $provided->matches($constraint); |
||
| 62 | } |
||
| 63 | public static function getVersionRanges($packageName) |
||
| 64 | { |
||
| 65 | foreach (self::getInstalled() as $installed) { |
||
| 66 | if (!isset($installed['versions'][$packageName])) { |
||
| 67 | continue; |
||
| 68 | } |
||
| 69 | $ranges = array(); |
||
| 70 | if (isset($installed['versions'][$packageName]['pretty_version'])) { |
||
| 71 | $ranges[] = $installed['versions'][$packageName]['pretty_version']; |
||
| 72 | } |
||
| 73 | if (\array_key_exists('aliases', $installed['versions'][$packageName])) { |
||
| 74 | $ranges = \array_merge($ranges, $installed['versions'][$packageName]['aliases']); |
||
| 75 | } |
||
| 76 | if (\array_key_exists('replaced', $installed['versions'][$packageName])) { |
||
| 77 | $ranges = \array_merge($ranges, $installed['versions'][$packageName]['replaced']); |
||
| 78 | } |
||
| 79 | if (\array_key_exists('provided', $installed['versions'][$packageName])) { |
||
| 80 | $ranges = \array_merge($ranges, $installed['versions'][$packageName]['provided']); |
||
| 81 | } |
||
| 82 | return \implode(' || ', $ranges); |
||
| 83 | } |
||
| 84 | throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed'); |
||
| 85 | } |
||
| 86 | public static function getVersion($packageName) |
||
| 87 | { |
||
| 88 | foreach (self::getInstalled() as $installed) { |
||
| 89 | if (!isset($installed['versions'][$packageName])) { |
||
| 90 | continue; |
||
| 91 | } |
||
| 92 | if (!isset($installed['versions'][$packageName]['version'])) { |
||
| 93 | return null; |
||
| 94 | } |
||
| 95 | return $installed['versions'][$packageName]['version']; |
||
| 96 | } |
||
| 97 | throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed'); |
||
| 98 | } |
||
| 99 | public static function getPrettyVersion($packageName) |
||
| 100 | { |
||
| 101 | foreach (self::getInstalled() as $installed) { |
||
| 102 | if (!isset($installed['versions'][$packageName])) { |
||
| 103 | continue; |
||
| 104 | } |
||
| 105 | if (!isset($installed['versions'][$packageName]['pretty_version'])) { |
||
| 106 | return null; |
||
| 107 | } |
||
| 108 | return $installed['versions'][$packageName]['pretty_version']; |
||
| 109 | } |
||
| 110 | throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed'); |
||
| 111 | } |
||
| 112 | public static function getReference($packageName) |
||
| 113 | { |
||
| 114 | foreach (self::getInstalled() as $installed) { |
||
| 115 | if (!isset($installed['versions'][$packageName])) { |
||
| 116 | continue; |
||
| 117 | } |
||
| 118 | if (!isset($installed['versions'][$packageName]['reference'])) { |
||
| 119 | return null; |
||
| 120 | } |
||
| 121 | return $installed['versions'][$packageName]['reference']; |
||
| 122 | } |
||
| 123 | throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed'); |
||
| 124 | } |
||
| 125 | public static function getInstallPath($packageName) |
||
| 126 | { |
||
| 127 | foreach (self::getInstalled() as $installed) { |
||
| 128 | if (!isset($installed['versions'][$packageName])) { |
||
| 129 | continue; |
||
| 130 | } |
||
| 131 | return isset($installed['versions'][$packageName]['install_path']) ? $installed['versions'][$packageName]['install_path'] : null; |
||
| 132 | } |
||
| 133 | throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed'); |
||
| 134 | } |
||
| 135 | /** |
||
| 136 | @psalm-return |
||
| 137 | */ |
||
| 138 | public static function getRootPackage() |
||
| 139 | { |
||
| 140 | $installed = self::getInstalled(); |
||
| 141 | return $installed[0]['root']; |
||
| 142 | } |
||
| 143 | /** |
||
| 144 | @psalm-return |
||
| 145 | */ |
||
| 146 | public static function getRawData() |
||
| 157 | } |
||
| 158 | /** |
||
| 159 | @psalm-return |
||
| 160 | */ |
||
| 161 | public static function getAllRawData() |
||
| 162 | { |
||
| 163 | return self::getInstalled(); |
||
| 164 | } |
||
| 165 | /** |
||
| 166 | @psalm-param |
||
| 167 | */ |
||
| 168 | public static function reload($data) |
||
| 172 | } |
||
| 173 | /** |
||
| 174 | @psalm-return |
||
| 175 | */ |
||
| 176 | private static function getInstalled() |
||
| 177 | { |
||
| 209 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths