Skip to content

Commit

Permalink
ENH PHP 8.1 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
emteknetnz committed Apr 4, 2022
1 parent 6d56502 commit 7ee441d
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions code/Report.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ public function getLink($action = null)
*/
protected function sanitiseClassName($class)
{
return str_replace('\\', '-', $class);
return str_replace('\\', '-', $class ?: '');
}


Expand Down Expand Up @@ -286,12 +286,12 @@ public static function get_reports()
$reports = ClassInfo::subclassesFor(get_called_class());

$reportsArray = [];
if ($reports && count($reports) > 0) {
if ($reports && count($reports ?: []) > 0) {
$excludedReports = static::get_excluded_reports();
// Collect reports into array with an attribute for 'sort'
foreach ($reports as $report) {
// Don't use the Report superclass, or any excluded report classes
if (in_array($report, $excludedReports)) {
if (in_array($report, $excludedReports ?: [])) {
continue;
}
$reflectionClass = new ReflectionClass($report);
Expand Down Expand Up @@ -484,7 +484,7 @@ public function extendedCan($methodName, $member)
$results = $this->extend($methodName, $member);
if ($results && is_array($results)) {
// Remove NULLs
$results = array_filter($results, function ($v) {
$results = array_filter($results ?: [], function ($v) {
return !is_null($v);
});
// If there are any non-NULL responses, then return the lowest one of them.
Expand Down
4 changes: 2 additions & 2 deletions code/ReportAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public function handleAction($request, $action)
*/
protected function unsanitiseClassName($class)
{
return str_replace('-', '\\', $class);
return str_replace('-', '\\', $class ?: '');
}

/**
Expand All @@ -155,7 +155,7 @@ protected function unsanitiseClassName($class)
*/
public static function has_reports()
{
return sizeof(Report::get_reports()) > 0;
return sizeof(Report::get_reports() ?: []) > 0;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions code/SideReportView.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ protected function formatValue($record, $source, $info)
// Formatting, a la TableListField
if (!empty($info['formatting'])) {
$format = str_replace('$value', "__VAL__", $info['formatting']);
$format = preg_replace('/\$([A-Za-z0-9-_]+)/', '$record->$1', $format);
$format = str_replace('__VAL__', '$val', $format);
$format = preg_replace('/\$([A-Za-z0-9-_]+)/', '$record->$1', $format ?: '');
$format = str_replace('__VAL__', '$val', $format ?: '');
$val = eval('return "' . $format . '";');
}

Expand Down

0 comments on commit 7ee441d

Please sign in to comment.