ENH PHP 8.1 compatibility

This commit is contained in:
Steve Boyd 2022-04-13 17:39:46 +12:00
parent 6d565028c8
commit 0bceb0903c
3 changed files with 10 additions and 10 deletions

View File

@ -218,7 +218,7 @@ class Report extends ViewableData
*/ */
protected function sanitiseClassName($class) protected function sanitiseClassName($class)
{ {
return str_replace('\\', '-', $class); return str_replace('\\', '-', $class ?? '');
} }
@ -286,12 +286,12 @@ class Report extends ViewableData
$reports = ClassInfo::subclassesFor(get_called_class()); $reports = ClassInfo::subclassesFor(get_called_class());
$reportsArray = []; $reportsArray = [];
if ($reports && count($reports) > 0) { if ($reports && count($reports ?? []) > 0) {
$excludedReports = static::get_excluded_reports(); $excludedReports = static::get_excluded_reports();
// Collect reports into array with an attribute for 'sort' // Collect reports into array with an attribute for 'sort'
foreach ($reports as $report) { foreach ($reports as $report) {
// Don't use the Report superclass, or any excluded report classes // Don't use the Report superclass, or any excluded report classes
if (in_array($report, $excludedReports)) { if (in_array($report, $excludedReports ?? [])) {
continue; continue;
} }
$reflectionClass = new ReflectionClass($report); $reflectionClass = new ReflectionClass($report);
@ -484,7 +484,7 @@ class Report extends ViewableData
$results = $this->extend($methodName, $member); $results = $this->extend($methodName, $member);
if ($results && is_array($results)) { if ($results && is_array($results)) {
// Remove NULLs // Remove NULLs
$results = array_filter($results, function ($v) { $results = array_filter($results ?? [], function ($v) {
return !is_null($v); return !is_null($v);
}); });
// If there are any non-NULL responses, then return the lowest one of them. // If there are any non-NULL responses, then return the lowest one of them.

View File

@ -139,7 +139,7 @@ class ReportAdmin extends LeftAndMain implements PermissionProvider
*/ */
protected function unsanitiseClassName($class) protected function unsanitiseClassName($class)
{ {
return str_replace('-', '\\', $class); return str_replace('-', '\\', $class ?? '');
} }
/** /**
@ -155,7 +155,7 @@ class ReportAdmin extends LeftAndMain implements PermissionProvider
*/ */
public static function has_reports() public static function has_reports()
{ {
return sizeof(Report::get_reports()) > 0; return sizeof(Report::get_reports() ?? []) > 0;
} }
/** /**

View File

@ -79,9 +79,9 @@ class SideReportView extends ViewableData
// Formatting, a la TableListField // Formatting, a la TableListField
if (!empty($info['formatting'])) { if (!empty($info['formatting'])) {
$format = str_replace('$value', "__VAL__", $info['formatting']); $format = str_replace('$value', "__VAL__", $info['formatting'] ?? '');
$format = preg_replace('/\$([A-Za-z0-9-_]+)/', '$record->$1', $format); $format = preg_replace('/\$([A-Za-z0-9-_]+)/', '$record->$1', $format ?? '');
$format = str_replace('__VAL__', '$val', $format); $format = str_replace('__VAL__', '$val', $format ?? '');
$val = eval('return "' . $format . '";'); $val = eval('return "' . $format . '";');
} }
@ -90,7 +90,7 @@ class SideReportView extends ViewableData
$classClause = ""; $classClause = "";
if (isset($info['title'])) { if (isset($info['title'])) {
$cssClass = preg_replace('/[^A-Za-z0-9]+/', '', $info['title']); $cssClass = preg_replace('/[^A-Za-z0-9]+/', '', $info['title'] ?? '');
$classClause = "class=\"$cssClass\""; $classClause = "class=\"$cssClass\"";
} }