Merge pull request #148 from creative-commoners/pulls/4/php81

ENH PHP 8.1 compatibility
This commit is contained in:
Guy Sartorelli 2022-04-22 16:18:26 +12:00 committed by GitHub
commit 8e3d6cb3eb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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\"";
} }