
| Current Path : /var/www/html/vendor/enlightn/security-checker/src/ |
Linux ift1.ift-informatik.de 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64 |
| Current File : /var/www/html/vendor/enlightn/security-checker/src/Composer.php |
<?php
namespace Enlightn\SecurityChecker;
use RuntimeException;
class Composer
{
/**
* @param string $composerLockPath
* @param false $excludeDev
* @return array
*/
public function getDependencies($composerLockPath, $excludeDev = false)
{
if (! is_file($composerLockPath)) {
throw new RuntimeException("File not found at [$composerLockPath]");
}
if (! ($lockFileContent = file_get_contents($composerLockPath))) {
throw new RuntimeException("Unable to read file");
}
$json = json_decode($lockFileContent, true);
if (is_null($json) || ! isset($json['packages'])) {
throw new RuntimeException("Invalid composer file format");
}
if ($excludeDev) {
$packages = $json['packages'];
} else {
$packages = array_merge($json['packages'], isset($json['packages-dev']) ? $json['packages-dev'] : []);
}
if (empty($packages)) {
return [];
}
return array_merge(...array_map(function ($package) {
return [$package['name'] => [
'version' => ltrim($package['version'], 'v'),
'time' => isset($package['time']) ? $package['time'] : null,
]];
}, $packages));
}
}