Skip to content

Commit

Permalink
Merge pull request #675 from creative-commoners/pulls/3/php81
Browse files Browse the repository at this point in the history
ENH PHP 8.1 compatibility
  • Loading branch information
GuySartorelli authored Apr 26, 2022
2 parents f8988ad + 8f3778f commit 2e0ac9e
Show file tree
Hide file tree
Showing 10 changed files with 21 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/Admin/GridFieldMergeAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function __construct($records, $parentType, $parentMethod, $childMethod)
*/
public function augmentColumns($gridField, &$columns)
{
if (!in_array('MergeAction', $columns)) {
if (!in_array('MergeAction', $columns ?? [])) {
$columns[] = 'MergeAction';
}

Expand Down
4 changes: 2 additions & 2 deletions src/Forms/GridField/GridFieldBlogPostState.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function getColumnContent($gridField, $record, $columnName)
*/
$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}',
Expand Down Expand Up @@ -83,7 +83,7 @@ public function getColumnAttributes($gridField, $record, $columnName)

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';
Expand Down
2 changes: 1 addition & 1 deletion src/Model/Blog.php
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ protected function isMemberOf($member, $relation)
}

if ($relation instanceof UnsavedRelationList) {
return in_array($member->ID, $relation->getIDList());
return in_array($member->ID, $relation->getIDList() ?? []);
}

return $relation->byID($member->ID) !== null;
Expand Down
16 changes: 8 additions & 8 deletions src/Model/BlogController.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public function getCurrentProfile()
// 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()
Expand Down Expand Up @@ -201,9 +201,9 @@ public function getArchiveMonth()
{
$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;
}
}
Expand All @@ -221,8 +221,8 @@ public function getArchiveDay()
{
$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;
}
}
Expand Down Expand Up @@ -271,7 +271,7 @@ public function getCurrentTag()
// 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()
Expand Down Expand Up @@ -321,7 +321,7 @@ public function getCurrentCategory()
// 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()
Expand Down Expand Up @@ -582,6 +582,6 @@ protected function rssFeed($blogPosts, $link)
protected function isRSS()
{
$rss = $this->request->param('Rss');
return (is_string($rss) && strcasecmp($rss, 'rss') == 0);
return (is_string($rss) && strcasecmp($rss ?? '', 'rss') == 0);
}
}
2 changes: 1 addition & 1 deletion src/Model/BlogFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function stageChildren($showAll = false)
*/
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) ?? []);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Model/BlogMemberExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function onBeforeWrite()
$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++;
}

Expand Down
6 changes: 3 additions & 3 deletions src/Model/BlogPost.php
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ public function isAuthor($member = null)
$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;
Expand Down Expand Up @@ -740,7 +740,7 @@ protected function getStaticCredits()
{
$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([
Expand Down Expand Up @@ -809,7 +809,7 @@ public function MinutesToRead($wpm = null)
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;
Expand Down
4 changes: 2 additions & 2 deletions src/Widgets/BlogArchiveWidget.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public function getCMSFields()
$type = $archiveType->enumValues();

foreach ($type as $k => $v) {
$type[$k] = _t(__CLASS__ .'.' . ucfirst(strtolower($v)), $v);
$type[$k] = _t(__CLASS__ .'.' . ucfirst(strtolower($v ?? '')), $v);
}

/**
Expand Down Expand Up @@ -139,7 +139,7 @@ public function getArchive()
$title = $year;
} else {
$date = DBDate::create();
$date->setValue(strtotime($post['PublishDate']));
$date->setValue(strtotime($post['PublishDate'] ?? ''));

$year = $date->Format('y');
$month = $date->Format('MM');
Expand Down
2 changes: 1 addition & 1 deletion tests/behat/src/FeatureContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function stepIFillInTheHtmlFieldWith($widgetTitle, $fieldTitle, $value)
$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()",
Expand Down
2 changes: 1 addition & 1 deletion tests/php/BlogTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,6 @@ protected function assertIDsEquals($left, $right)
}
asort($left);
asort($right);
$this->assertEquals(array_values($left), array_values($right));
$this->assertEquals(array_values($left ?? []), array_values($right ?? []));
}
}

0 comments on commit 2e0ac9e

Please sign in to comment.