Skip to content

Commit cf27556

Browse files
committed
fix(phpfatalerror): fixed uncaught error to member function getRisk()
changes Signed-off-by: Ritankar Saha <[email protected]> php space fixes Signed-off-by: Ritankar Saha <[email protected]>
1 parent db10a21 commit cf27556

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

src/lib/php/Report/LicenseMainGetter.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,17 @@ protected function getStatements($uploadId, $uploadTreeTableName, $groupId = nul
3939
$allStatements = array();
4040
foreach ($mainLicIds as $originLicenseId) {
4141
$allLicenseCols = $this->licenseDao->getLicenseById($originLicenseId, $groupId);
42+
// Null-check: if the license is missing, log and skip this ID.
43+
if ($allLicenseCols === null) {
44+
error_log("Warning: License ID " . $originLicenseId . " not found in the database.");
45+
continue;
46+
}
4247
$allStatements[] = array(
4348
'licenseId' => $originLicenseId,
4449
'risk' => $allLicenseCols->getRisk(),
4550
'content' => $licenseMap->getProjectedSpdxId($originLicenseId),
4651
'text' => $allLicenseCols->getText(),
47-
'name' => $licenseMap->getProjectedShortname($originLicenseId,
48-
$allLicenseCols->getShortName())
52+
'name' => $licenseMap->getProjectedShortname($originLicenseId, $allLicenseCols->getShortName())
4953
);
5054
}
5155
return $allStatements;

src/spdx/agent/spdx.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -224,23 +224,24 @@ function processUploadId($uploadId)
224224
}
225225
$this->licenseMap = new LicenseMap($this->dbManager, $this->groupId, LicenseMap::REPORT, true);
226226
$this->computeUri($uploadId);
227-
228227
$docLicense = $this->licenseDao->getLicenseByShortName(self::DATA_LICENSE);
228+
if ($docLicense === null) {
229+
error_log("Warning: License with short name " . self::DATA_LICENSE . " not found in the database. Using fallback license.");
230+
$docLicense = new License(0, self::DATA_LICENSE, "Fallback License", "Unknown", "No license text available", "", "", "");
231+
}
229232
$docLicenseId = $docLicense->getId() . "-" . md5($docLicense->getText());
230233
$this->licensesInDocument[$docLicenseId] = (new SpdxLicenseInfo())
231234
->setLicenseObj($docLicense)
232235
->setListedLicense(true)
233236
->setCustomText(false)
234237
->setTextPrinted(true);
235-
236238
$packageNodes = $this->renderPackage($uploadId);
237239
$additionalUploadIds = array_key_exists(self::UPLOAD_ADDS,$args) ? explode(',',$args[self::UPLOAD_ADDS]) : array();
238240
$packageIds = array($uploadId);
239241
foreach ($additionalUploadIds as $additionalId) {
240242
$packageNodes .= $this->renderPackage($additionalId);
241243
$packageIds[] = $additionalId;
242244
}
243-
244245
$this->writeReport($packageNodes, $packageIds, $uploadId);
245246
return true;
246247
}

0 commit comments

Comments
 (0)