Merge pull request #675 from creative-commoners/pulls/3/php81

ENH PHP 8.1 compatibility
This commit is contained in:
Guy Sartorelli 2022-04-27 09:56:28 +12:00 committed by GitHub
commit 2e0ac9e6c0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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)
{
if (!in_array('MergeAction', $columns)) {
if (!in_array('MergeAction', $columns ?? [])) {
$columns[] = 'MergeAction';
}

View File

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

View File

@ -263,7 +263,7 @@ class Blog extends Page implements PermissionProvider
}
if ($relation instanceof UnsavedRelationList) {
return in_array($member->ID, $relation->getIDList());
return in_array($member->ID, $relation->getIDList() ?? []);
}
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)
// see https://github.com/silverstripe/silverstripe-cms/pull/2384
if (!$filter->getAllowMultibyte()) {
$urlSegment = rawurlencode($urlSegment);
$urlSegment = rawurlencode($urlSegment ?? '');
}
return Member::get()
@ -201,9 +201,9 @@ class BlogController extends PageController
{
$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 (checkdate($month, 01, $this->getArchiveYear())) {
if (checkdate($month ?? 0, 01, $this->getArchiveYear() ?? 0)) {
return (int) $month;
}
}
@ -221,8 +221,8 @@ class BlogController extends PageController
{
$day = $this->request->param('Day');
if (preg_match('/^[0-9]{1,2}$/', $day)) {
if (checkdate($this->getArchiveMonth(), $day, $this->getArchiveYear())) {
if (preg_match('/^[0-9]{1,2}$/', $day ?? '')) {
if (checkdate($this->getArchiveMonth() ?? 0, $day ?? 0, $this->getArchiveYear() ?? 0)) {
return (int) $day;
}
}
@ -271,7 +271,7 @@ class BlogController extends PageController
// url encode unless it's multibyte (already pre-encoded in the database)
// see https://github.com/silverstripe/silverstripe-cms/pull/2384
if (!$filter->getAllowMultibyte()) {
$tag = rawurlencode($tag);
$tag = rawurlencode($tag ?? '');
}
return $dataRecord->Tags()
@ -321,7 +321,7 @@ class BlogController extends PageController
// url encode unless it's multibyte (already pre-encoded in the database)
// see https://github.com/silverstripe/silverstripe-cms/pull/2384
if (!$filter->getAllowMultibyte()) {
$category = rawurlencode($category);
$category = rawurlencode($category ?? '');
}
return $dataRecord->Categories()
@ -582,6 +582,6 @@ class BlogController extends PageController
protected function isRSS()
{
$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()
{
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();
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++;
}

View File

@ -239,7 +239,7 @@ class BlogPost extends Page
$list = $this->Authors();
if ($list instanceof UnsavedRelationList) {
return in_array($member->ID, $list->getIDList());
return in_array($member->ID, $list->getIDList() ?? []);
}
return $list->byID($member->ID) !== null;
@ -740,7 +740,7 @@ class BlogPost extends Page
{
$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) {
$item = ArrayData::create([
@ -809,7 +809,7 @@ class BlogPost extends Page
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) {
return 0;

View File

@ -85,7 +85,7 @@ class BlogArchiveWidget extends Widget
$type = $archiveType->enumValues();
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;
} else {
$date = DBDate::create();
$date->setValue(strtotime($post['PublishDate']));
$date->setValue(strtotime($post['PublishDate'] ?? ''));
$year = $date->Format('y');
$month = $date->Format('MM');

View File

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

View File

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