1 | <?php |
||
13 | final class FallbackVersions |
||
14 | { |
||
15 | private function __construct() |
||
18 | |||
19 | /** |
||
20 | * @param string $packageName |
||
21 | * |
||
22 | * @return string |
||
23 | * |
||
24 | * @throws \OutOfBoundsException if a version cannot be located |
||
25 | * @throws \UnexpectedValueException if the composer.lock file could not be located |
||
26 | */ |
||
27 | 1 | public static function getVersion(string $packageName) : string |
|
39 | |||
40 | /** |
||
41 | * @return string |
||
42 | * |
||
43 | * @throws \UnexpectedValueException |
||
44 | */ |
||
45 | 1 | private static function getComposerLockPath() : string |
|
46 | { |
||
47 | // bold assumption, but there's not here to fix everyone's problems. |
||
48 | 1 | $checkedPaths = [__DIR__ . '/../../../../../composer.lock', __DIR__ . '/../../composer.lock']; |
|
49 | |||
50 | 1 | foreach ($checkedPaths as $path) { |
|
51 | 1 | if (file_exists($path)) { |
|
52 | 1 | return $path; |
|
53 | } |
||
54 | } |
||
55 | |||
56 | 1 | throw new \UnexpectedValueException(sprintf( |
|
57 | 'PackageVersions could not locate your `composer.lock` location. This is assumed to be in %s. ' |
||
58 | . 'If you customized your composer vendor directory and ran composer installation with --no-scripts, ' |
||
59 | 1 | . 'then you are on your own, and we can\'t really help you. Fix your shit and cut the tooling some slack.', |
|
60 | 1 | json_encode($checkedPaths) |
|
61 | )); |
||
62 | } |
||
63 | |||
64 | private static function getVersions(string $composerLockFile) : \Generator |
||
78 | } |
||
79 |