Skip to content

Commit

Permalink
Merge pull request #148 from creative-commoners/pulls/4/php81
Browse files Browse the repository at this point in the history
ENH PHP 8.1 compatibility
  • Loading branch information
GuySartorelli authored Apr 22, 2022
2 parents 6d56502 + 0bceb09 commit 8e3d6cb
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 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
8 changes: 4 additions & 4 deletions code/SideReportView.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ 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 = str_replace('$value', "__VAL__", $info['formatting'] ?? '');
$format = preg_replace('/\$([A-Za-z0-9-_]+)/', '$record->$1', $format ?? '');
$format = str_replace('__VAL__', '$val', $format ?? '');
$val = eval('return "' . $format . '";');
}

Expand All @@ -90,7 +90,7 @@ protected function formatValue($record, $source, $info)

$classClause = "";
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\"";
}

Expand Down

0 comments on commit 8e3d6cb

Please sign in to comment.