Skip to content

Commit 63c3b68

Browse files
committed
fix(utils): fail gracefully if composer.json can't be parsed
Fixes: #57
1 parent 790a68c commit 63c3b68

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/SumUp/Utils/Headers.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,16 @@ public static function getTrk()
6767
public static function getProjectVersion()
6868
{
6969
if (is_null(self::$cacheVersion)) {
70-
$pathToComposer = realpath(dirname(__FILE__) . '/../../../composer.json');
71-
$content = file_get_contents($pathToComposer);
72-
$content = json_decode($content, true);
73-
self::$cacheVersion = $content['version'];
70+
self::$cacheVersion = 'unknown';
71+
$pathToComposer = dirname(__FILE__) . '/../../../composer.json';
72+
73+
if (is_readable($pathToComposer)) {
74+
$content = file_get_contents($pathToComposer);
75+
$content = json_decode($content, true);
76+
if (is_array($content) && !empty($content['version'])) {
77+
self::$cacheVersion = $content['version'];
78+
}
79+
}
7480
}
7581

7682
return self::$cacheVersion;

0 commit comments

Comments
 (0)