Skip to content

Commit

Permalink
Add additional checks to ensure string is returned to avoid null bein…
Browse files Browse the repository at this point in the history
…g returned
  • Loading branch information
asgrim committed Apr 9, 2021
1 parent fea1102 commit 2fee014
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/Events/Metadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
use function class_exists;
use function getenv;
use function gethostname;
use function is_array;
use function is_string;
use function method_exists;
use function sprintf;

use const PHP_VERSION;
Expand Down Expand Up @@ -129,8 +131,12 @@ private function rootPackageGitSha(): string
return $herokuSlugCommit;
}

if (class_exists(InstalledVersions::class)) {
return InstalledVersions::getRootPackage()['reference'];
if (class_exists(InstalledVersions::class) && method_exists(InstalledVersions::class, 'getRootPackage')) {
/** @var mixed $rootPackage */
$rootPackage = InstalledVersions::getRootPackage();
if (is_array($rootPackage) && array_key_exists('reference', $rootPackage) && is_string($rootPackage['reference'])) {
return $rootPackage['reference'];
}
}

return '';
Expand Down

0 comments on commit 2fee014

Please sign in to comment.