Skip to content

Commit f213bc8

Browse files
authored
Merge pull request #285 from phparkitect/fix-version
fix bug when a wrong composer.json was used to read the version number
2 parents 2016000 + 506225a commit f213bc8

File tree

1 file changed

+5
-22
lines changed

1 file changed

+5
-22
lines changed

src/CLI/Version.php

+5-22
Original file line numberDiff line numberDiff line change
@@ -6,36 +6,19 @@
66

77
class Version
88
{
9-
private const COMPOSER_PATHS = [
10-
'composer.json',
11-
'../composer.json',
12-
'../../composer.json',
13-
'../../../composer.json',
14-
'./vendor/phparkitect/phparkitect/composer.json',
15-
];
16-
179
public static function get(): string
1810
{
1911
$pharPath = \Phar::running();
2012

2113
if ($pharPath) {
2214
$content = file_get_contents("$pharPath/composer.json");
23-
$composerData = json_decode($content, true);
24-
25-
return $composerData['version'] ?? 'UNKNOWN';
15+
} else {
16+
$phparkitectRootPath = __DIR__.'/../../';
17+
$content = file_get_contents($phparkitectRootPath.'composer.json');
2618
}
2719

28-
foreach (self::COMPOSER_PATHS as $composerPath) {
29-
if (!file_exists($composerPath)) {
30-
continue;
31-
}
32-
33-
$content = file_get_contents($composerPath);
34-
$composerData = json_decode($content, true);
35-
36-
return $composerData['version'] ?? 'UNKNOWN';
37-
}
20+
$composerData = json_decode($content, true);
3821

39-
return 'UNKNOWN';
22+
return $composerData['version'] ?? 'UNKNOWN';
4023
}
4124
}

0 commit comments

Comments
 (0)