ENH PHP 8.1 compatibility

This commit is contained in:
Steve Boyd 2022-04-14 15:16:37 +12:00
parent f8988ad5c3
commit 8f3778f77f
10 changed files with 21 additions and 21 deletions

View File

@ -61,7 +61,7 @@ class GridFieldMergeAction implements GridField_ColumnProvider, GridField_Action
*/ */
public function augmentColumns($gridField, &$columns) public function augmentColumns($gridField, &$columns)
{ {
if (!in_array('MergeAction', $columns)) { if (!in_array('MergeAction', $columns ?? [])) {
$columns[] = 'MergeAction'; $columns[] = 'MergeAction';
} }

View File

@ -47,7 +47,7 @@ class GridFieldBlogPostState extends GridFieldSiteTreeState
*/ */
$publishDate = $record->dbObject('PublishDate'); $publishDate = $record->dbObject('PublishDate');
if (strtotime($record->PublishDate) > time()) { if (strtotime($record->PublishDate ?? '') > time()) {
return '<i class="font-icon-clock mr-2"></i> ' . _t( return '<i class="font-icon-clock mr-2"></i> ' . _t(
__CLASS__ . '.Timer', __CLASS__ . '.Timer',
'Publish at {date}', 'Publish at {date}',
@ -83,7 +83,7 @@ class GridFieldBlogPostState extends GridFieldSiteTreeState
if (!$published) { if (!$published) {
$class = 'gridfield-icon draft'; $class = 'gridfield-icon draft';
} elseif (strtotime($record->PublishDate) > time()) { } elseif (strtotime($record->PublishDate ?? '') > time()) {
$class = 'gridfield-icon timer'; $class = 'gridfield-icon timer';
} else { } else {
$class = 'gridfield-icon published'; $class = 'gridfield-icon published';

View File

@ -263,7 +263,7 @@ class Blog extends Page implements PermissionProvider
} }
if ($relation instanceof UnsavedRelationList) { if ($relation instanceof UnsavedRelationList) {
return in_array($member->ID, $relation->getIDList()); return in_array($member->ID, $relation->getIDList() ?? []);
} }
return $relation->byID($member->ID) !== null; return $relation->byID($member->ID) !== null;

View File

@ -112,7 +112,7 @@ class BlogController extends PageController
// url encode unless it's multibyte (already pre-encoded in the database) // url encode unless it's multibyte (already pre-encoded in the database)
// see https://github.com/silverstripe/silverstripe-cms/pull/2384 // see https://github.com/silverstripe/silverstripe-cms/pull/2384
if (!$filter->getAllowMultibyte()) { if (!$filter->getAllowMultibyte()) {
$urlSegment = rawurlencode($urlSegment); $urlSegment = rawurlencode($urlSegment ?? '');
} }
return Member::get() return Member::get()
@ -201,9 +201,9 @@ class BlogController extends PageController
{ {
$month = $this->request->param('Month'); $month = $this->request->param('Month');
if (preg_match('/^[0-9]{1,2}$/', $month)) { if (preg_match('/^[0-9]{1,2}$/', $month ?? '')) {
if ($month > 0 && $month < 13) { if ($month > 0 && $month < 13) {
if (checkdate($month, 01, $this->getArchiveYear())) { if (checkdate($month ?? 0, 01, $this->getArchiveYear() ?? 0)) {
return (int) $month; return (int) $month;
} }
} }
@ -221,8 +221,8 @@ class BlogController extends PageController
{ {
$day = $this->request->param('Day'); $day = $this->request->param('Day');
if (preg_match('/^[0-9]{1,2}$/', $day)) { if (preg_match('/^[0-9]{1,2}$/', $day ?? '')) {
if (checkdate($this->getArchiveMonth(), $day, $this->getArchiveYear())) { if (checkdate($this->getArchiveMonth() ?? 0, $day ?? 0, $this->getArchiveYear() ?? 0)) {
return (int) $day; return (int) $day;
} }
} }
@ -271,7 +271,7 @@ class BlogController extends PageController
// url encode unless it's multibyte (already pre-encoded in the database) // url encode unless it's multibyte (already pre-encoded in the database)
// see https://github.com/silverstripe/silverstripe-cms/pull/2384 // see https://github.com/silverstripe/silverstripe-cms/pull/2384
if (!$filter->getAllowMultibyte()) { if (!$filter->getAllowMultibyte()) {
$tag = rawurlencode($tag); $tag = rawurlencode($tag ?? '');
} }
return $dataRecord->Tags() return $dataRecord->Tags()
@ -321,7 +321,7 @@ class BlogController extends PageController
// url encode unless it's multibyte (already pre-encoded in the database) // url encode unless it's multibyte (already pre-encoded in the database)
// see https://github.com/silverstripe/silverstripe-cms/pull/2384 // see https://github.com/silverstripe/silverstripe-cms/pull/2384
if (!$filter->getAllowMultibyte()) { if (!$filter->getAllowMultibyte()) {
$category = rawurlencode($category); $category = rawurlencode($category ?? '');
} }
return $dataRecord->Categories() return $dataRecord->Categories()
@ -582,6 +582,6 @@ class BlogController extends PageController
protected function isRSS() protected function isRSS()
{ {
$rss = $this->request->param('Rss'); $rss = $this->request->param('Rss');
return (is_string($rss) && strcasecmp($rss, 'rss') == 0); return (is_string($rss) && strcasecmp($rss ?? '', 'rss') == 0);
} }
} }

View File

@ -54,7 +54,7 @@ class BlogFilter extends Lumberjack
*/ */
protected function subclassForBlog() protected function subclassForBlog()
{ {
return in_array(get_class($this->owner), ClassInfo::subclassesFor(Blog::class)); return in_array(get_class($this->owner), ClassInfo::subclassesFor(Blog::class) ?? []);
} }
/** /**

View File

@ -56,7 +56,7 @@ class BlogMemberExtension extends DataExtension
$this->owner->URLSegment = $this->generateURLSegment(); $this->owner->URLSegment = $this->generateURLSegment();
while (!$this->validURLSegment()) { while (!$this->validURLSegment()) {
$this->owner->URLSegment = preg_replace('/-[0-9]+$/', '', $this->owner->URLSegment) . '-' . $count; $this->owner->URLSegment = preg_replace('/-[0-9]+$/', '', $this->owner->URLSegment ?? '') . '-' . $count;
$count++; $count++;
} }

View File

@ -239,7 +239,7 @@ class BlogPost extends Page
$list = $this->Authors(); $list = $this->Authors();
if ($list instanceof UnsavedRelationList) { if ($list instanceof UnsavedRelationList) {
return in_array($member->ID, $list->getIDList()); return in_array($member->ID, $list->getIDList() ?? []);
} }
return $list->byID($member->ID) !== null; return $list->byID($member->ID) !== null;
@ -740,7 +740,7 @@ class BlogPost extends Page
{ {
$items = ArrayList::create(); $items = ArrayList::create();
$authors = array_filter(preg_split('/\s*,\s*/', $this->AuthorNames)); $authors = array_filter(preg_split('/\s*,\s*/', $this->AuthorNames ?? '') ?? []);
foreach ($authors as $author) { foreach ($authors as $author) {
$item = ArrayData::create([ $item = ArrayData::create([
@ -809,7 +809,7 @@ class BlogPost extends Page
throw new \InvalidArgumentException(sprintf("Expecting integer but got %s instead", gettype($wpm))); throw new \InvalidArgumentException(sprintf("Expecting integer but got %s instead", gettype($wpm)));
} }
$wordCount = str_word_count(strip_tags($this->Content)); $wordCount = str_word_count(strip_tags($this->Content ?? ''));
if ($wordCount < $wpm) { if ($wordCount < $wpm) {
return 0; return 0;

View File

@ -85,7 +85,7 @@ class BlogArchiveWidget extends Widget
$type = $archiveType->enumValues(); $type = $archiveType->enumValues();
foreach ($type as $k => $v) { foreach ($type as $k => $v) {
$type[$k] = _t(__CLASS__ .'.' . ucfirst(strtolower($v)), $v); $type[$k] = _t(__CLASS__ .'.' . ucfirst(strtolower($v ?? '')), $v);
} }
/** /**
@ -139,7 +139,7 @@ class BlogArchiveWidget extends Widget
$title = $year; $title = $year;
} else { } else {
$date = DBDate::create(); $date = DBDate::create();
$date->setValue(strtotime($post['PublishDate'])); $date->setValue(strtotime($post['PublishDate'] ?? ''));
$year = $date->Format('y'); $year = $date->Format('y');
$month = $date->Format('MM'); $month = $date->Format('MM');

View File

@ -58,7 +58,7 @@ class FeatureContext extends SilverStripeContext
$this->getSession()->evaluateScript(sprintf( $this->getSession()->evaluateScript(sprintf(
"jQuery('#%s').entwine('ss').getEditor().setContent('%s')", "jQuery('#%s').entwine('ss').getEditor().setContent('%s')",
$field->getAttribute('id'), $field->getAttribute('id'),
addcslashes($value, "'") addcslashes($value ?? '', "'")
)); ));
$this->getSession()->evaluateScript(sprintf( $this->getSession()->evaluateScript(sprintf(
"jQuery('#%s').entwine('ss').getEditor().save()", "jQuery('#%s').entwine('ss').getEditor().save()",

View File

@ -371,6 +371,6 @@ class BlogTest extends SapphireTest
} }
asort($left); asort($left);
asort($right); asort($right);
$this->assertEquals(array_values($left), array_values($right)); $this->assertEquals(array_values($left ?? []), array_values($right ?? []));
} }
} }