| Conditions | 13 |
| Paths | 21 |
| Total Lines | 55 |
| Code Lines | 29 |
| 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 |
||
| 163 | public function getLocation(string $path, string $baseDir = 'src') |
||
| 164 | { |
||
| 165 | if (false !== \strpos($path, '..')) { |
||
| 166 | throw new \RuntimeException(\sprintf('File name "%s" contains invalid characters (..).', $path)); |
||
| 167 | } |
||
| 168 | |||
| 169 | if ('@' === $path[0]) { |
||
| 170 | [$bundleName, $path] = \explode('/', \substr($path, 1), 2); |
||
| 171 | |||
| 172 | if (isset($this->loadedExtensionPaths[$bundleName])) { |
||
| 173 | return $this->loadedExtensionPaths[$bundleName] . '/' . $path; |
||
| 174 | } |
||
| 175 | |||
| 176 | if (null !== $extension = $this->getExtension($bundleName)) { |
||
| 177 | $bundleName = \get_class($extension); |
||
| 178 | } |
||
| 179 | |||
| 180 | try { |
||
| 181 | $ref = new \ReflectionClass($bundleName); |
||
| 182 | $directory = \str_replace('\\', '/', \dirname($ref->getFileName())); |
||
| 183 | } catch (\ReflectionException $e) { |
||
| 184 | throw new ContainerResolutionException(\sprintf('Resource path is not supported for %s', $bundleName), 0, $e); |
||
| 185 | } |
||
| 186 | |||
| 187 | if ($pos = \strpos($directory, $baseDir)) { |
||
| 188 | $directory = \substr($directory, 0, $pos + \strlen($baseDir)); |
||
| 189 | |||
| 190 | if (!\file_exists($directory)) { |
||
| 191 | $directory = \substr_replace($directory, '', $pos, 3); |
||
| 192 | } |
||
| 193 | |||
| 194 | return ($this->loadedExtensionPaths[$bundleName] = \substr($directory, 0, $pos + \strlen($baseDir))) . '/' . $path; |
||
| 195 | } |
||
| 196 | |||
| 197 | if (\class_exists(InstalledVersions::class)) { |
||
| 198 | $rootPath = InstalledVersions::getRootPackage()['install_path'] ?? false; |
||
| 199 | |||
| 200 | if ($rootPath && $rPos = \strpos($rootPath, 'composer')) { |
||
| 201 | $rootPath = \substr($rootPath, 0, $rPos); |
||
| 202 | |||
| 203 | if (!$pos = \strpos($directory, $rootPath)) { |
||
| 204 | throw new \UnexpectedValueException(sprintf('Looks like package "%s" does not live in composer\'s directory "%s".', InstalledVersions::getRootPackage()['name'], $rootPath)); |
||
| 205 | } |
||
| 206 | |||
| 207 | $parts = \explode('/', \substr($directory, $pos)); |
||
| 208 | $directory = InstalledVersions::getInstallPath($parts[1] . '/' . $parts[2]); |
||
| 209 | |||
| 210 | if (null !== $directory) { |
||
| 211 | return ($this->loadedExtensionPaths[$bundleName] = FileSystem::normalizePath($directory)) . '/' . $path; |
||
| 212 | } |
||
| 213 | } |
||
| 214 | } |
||
| 215 | } |
||
| 216 | |||
| 217 | throw new \InvalidArgumentException(\sprintf('Unable to find file "%s".', $path)); |
||
| 218 | } |
||
| 220 |
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