Compare commits

...

2 Commits

Author SHA1 Message Date
Guy Sartorelli
3dc22e9c39
Merge pull request #338 from creative-commoners/pulls/3/php81
ENH PHP 8.1 compatibility
2022-04-26 17:58:35 +12:00
Steve Boyd
e7f9e60352 ENH PHP 8.1 compatibility 2022-04-13 10:22:29 +12:00
11 changed files with 35 additions and 27 deletions

View File

@ -100,7 +100,7 @@ class CommentAdmin extends LeftAndMain implements PermissionProvider
_t(
__CLASS__.'.NewComments',
'New ({count})',
['count' => count($newComments)]
['count' => count($newComments ?? [])]
),
$newGrid
),
@ -109,7 +109,7 @@ class CommentAdmin extends LeftAndMain implements PermissionProvider
_t(
__CLASS__.'.ApprovedComments',
'Approved ({count})',
['count' => count($approvedComments)]
['count' => count($approvedComments ?? [])]
),
$approvedGrid
),
@ -118,7 +118,7 @@ class CommentAdmin extends LeftAndMain implements PermissionProvider
_t(
__CLASS__.'.SpamComments',
'Spam ({count})',
['count' => count($spamComments)]
['count' => count($spamComments ?? [])]
),
$spamGrid
)

View File

@ -19,7 +19,7 @@ class CommentsGridFieldAction implements GridField_ColumnProvider, GridField_Act
*/
public function augmentColumns($gridField, &$columns)
{
if (!in_array('Actions', $columns)) {
if (!in_array('Actions', $columns ?? [])) {
$columns[] = 'Actions';
}
}

View File

@ -20,7 +20,7 @@ class CommentsGridFieldApproveAction implements
*/
public function augmentColumns($gridField, &$columns)
{
if (!in_array('Actions', $columns)) {
if (!in_array('Actions', $columns ?? [])) {
$columns[] = 'Actions';
}
}

View File

@ -20,7 +20,7 @@ class CommentsGridFieldSpamAction implements
*/
public function augmentColumns($gridField, &$columns)
{
if (!in_array('Actions', $columns)) {
if (!in_array('Actions', $columns ?? [])) {
$columns[] = 'Actions';
}
}

View File

@ -115,7 +115,7 @@ class CommentingController extends Controller
*/
public function encodeClassName($input)
{
return str_replace('\\', '-', $input);
return str_replace('\\', '-', $input ?? '');
}
/**
@ -126,7 +126,7 @@ class CommentingController extends Controller
*/
public function decodeClassName($input)
{
return str_replace('-', '\\', $input);
return str_replace('-', '\\', $input ?? '');
}
/**

View File

@ -583,9 +583,9 @@ class CommentsExtension extends DataExtension
CommentsGridFieldConfig::create()
);
$newCount = '(' . count($newComments) . ')';
$approvedCount = '(' . count($approvedComments) . ')';
$spamCount = '(' . count($spamComments) . ')';
$newCount = '(' . count($newComments ?? []) . ')';
$approvedCount = '(' . count($approvedComments ?? []) . ')';
$spamCount = '(' . count($spamComments ?? []) . ')';
if ($fields->hasTabSet()) {
$tabs = TabSet::create(

View File

@ -145,8 +145,8 @@ class CommentForm extends Form
}
// load user data from previous form request back into form.
if (array_key_exists('UserData', $data)) {
$formData = json_decode($data['UserData'], true);
if (array_key_exists('UserData', $data ?? [])) {
$formData = json_decode($data['UserData'] ?? '', true);
$this->loadDataFrom([
'Name' => isset($formData['Name']) ? $formData['Name'] : '',
@ -156,7 +156,7 @@ class CommentForm extends Form
}
// allow previous value to fill if comment
if (array_key_exists('Comment', $data)) {
if (array_key_exists('Comment', $data ?? [])) {
$prevComment = $data['Comment'];
if ($prevComment && $prevComment != '') {

View File

@ -608,7 +608,7 @@ class Comment extends DataObject
*/
public function getTitle()
{
$title = sprintf(_t(__CLASS__ . '.COMMENTBY', 'Comment by %s', 'Name'), $this->getAuthorName());
$title = sprintf(_t(__CLASS__ . '.COMMENTBY', 'Comment by %s', 'Name') ?? '', $this->getAuthorName());
if ($parent = $this->Parent()) {
if ($parent->Title) {
@ -726,7 +726,7 @@ class Comment extends DataObject
}
// This injector cannot be set unless the 'p' element is allowed
if (in_array('p', $allowedElements)) {
if (in_array('p', $allowedElements ?? [])) {
$config->set('AutoFormat.AutoParagraph', true);
}
@ -747,7 +747,7 @@ class Comment extends DataObject
$use_gravatar = $this->getOption('use_gravatar');
if ($use_gravatar) {
$gravatar = 'https://www.gravatar.com/avatar/' . md5(strtolower(trim($this->Email)));
$gravatar = 'https://www.gravatar.com/avatar/' . md5(strtolower(trim($this->Email ?? '')));
$gravatarsize = $this->getOption('gravatar_size');
$gravatardefault = $this->getOption('gravatar_default');
$gravatarrating = $this->getOption('gravatar_rating');

View File

@ -37,7 +37,7 @@ class SecurityToken
*/
protected function getToken($salt)
{
return hash_pbkdf2('sha256', $this->secret, $salt, 1000, 30);
return hash_pbkdf2('sha256', $this->secret ?? '', $salt ?? '', 1000, 30);
}
/**
@ -74,8 +74,8 @@ class SecurityToken
$url,
sprintf(
'?t=%s&s=%s',
urlencode($token),
urlencode($salt)
urlencode($token ?? ''),
urlencode($salt ?? '')
)
);
}
@ -113,7 +113,7 @@ class SecurityToken
$generator = new RandomGenerator();
$result = $generator->randomToken('sha256');
if ($length !== null) {
return substr($result, 0, $length);
return substr($result ?? '', 0, $length);
}
return $result;
}

View File

@ -179,21 +179,29 @@ class CommentingControllerTest extends FunctionalTest
// comments sitewide
$response = $this->get('comments/rss');
$comment = "10 approved, non spam comments on page 1";
$this->assertEquals(10, substr_count($response->getBody(), "<item>"), $comment);
$this->assertEquals(10, substr_count($response->getBody() ?? '', "<item>"), $comment);
$response = $this->get('comments/rss?start=10');
$this->assertEquals(4, substr_count($response->getBody(), "<item>"), "3 approved, non spam comments on page 2");
$this->assertEquals(
4,
substr_count($response->getBody() ?? '', "<item>"),
"3 approved, non spam comments on page 2"
);
// all comments on a type
$response = $this->get('comments/rss/SilverStripe-Comments-Tests-Stubs-CommentableItem');
$this->assertEquals(10, substr_count($response->getBody(), "<item>"));
$this->assertEquals(10, substr_count($response->getBody() ?? '', "<item>"));
$response = $this->get('comments/rss/SilverStripe-Comments-Tests-Stubs-CommentableItem?start=10');
$this->assertEquals(4, substr_count($response->getBody(), "<item>"), "3 approved, non spam comments on page 2");
$this->assertEquals(
4,
substr_count($response->getBody() ?? '', "<item>"),
"3 approved, non spam comments on page 2"
);
// specific page
$response = $this->get('comments/rss/SilverStripe-Comments-Tests-Stubs-CommentableItem/'.$item->ID);
$this->assertEquals(1, substr_count($response->getBody(), "<item>"));
$this->assertEquals(1, substr_count($response->getBody() ?? '', "<item>"));
$this->assertStringContainsString('<dc:creator>FA</dc:creator>', $response->getBody());
// test accessing comments on a type that doesn't exist

View File

@ -343,7 +343,7 @@ class CommentsExtensionTest extends FunctionalTest
$results[0]->Comment
);
$this->assertEquals(4, sizeof($results));
$this->assertEquals(4, sizeof($results ?? []));
}
public function testUpdateModerationFields()