Merge pull request #77 from creative-commoners/pulls/2/php81

ENH PHP 8.1 compatibility
This commit is contained in:
Guy Sartorelli 2022-04-26 17:58:36 +12:00 committed by GitHub
commit 164032af76
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 7 deletions

View File

@ -101,7 +101,7 @@ class CheckExternalLinksTask extends BuildTask
{ {
$class = $link->getAttribute('class'); $class = $link->getAttribute('class');
$href = $link->getAttribute('href'); $href = $link->getAttribute('href');
$markedBroken = preg_match('/\b(ss-broken)\b/', $class); $markedBroken = preg_match('/\b(ss-broken)\b/', $class ?? '');
// Check link // Check link
$httpCode = $this->linkChecker->checkLink($href); $httpCode = $this->linkChecker->checkLink($href);
@ -127,9 +127,9 @@ class CheckExternalLinksTask extends BuildTask
if ($foundBroken) { if ($foundBroken) {
$class .= ' ss-broken'; $class .= ' ss-broken';
} else { } else {
$class = preg_replace('/\s*\b(ss-broken)\b\s*/', ' ', $class); $class = preg_replace('/\s*\b(ss-broken)\b\s*/', ' ', $class ?? '');
} }
$link->setAttribute('class', trim($class)); $link->setAttribute('class', trim($class ?? ''));
} }
/** /**
@ -147,7 +147,7 @@ class CheckExternalLinksTask extends BuildTask
// do we have any whitelisted codes // do we have any whitelisted codes
$ignoreCodes = $this->config()->get('ignore_codes'); $ignoreCodes = $this->config()->get('ignore_codes');
if (is_array($ignoreCodes) && in_array($httpCode, $ignoreCodes)) { if (is_array($ignoreCodes) && in_array($httpCode, $ignoreCodes ?? [])) {
return false; return false;
} }

View File

@ -58,11 +58,11 @@ class CurlLinkChecker implements LinkChecker
public function checkLink($href) public function checkLink($href)
{ {
// Skip non-external links // Skip non-external links
if (!preg_match('/^https?[^:]*:\/\//', $href)) { if (!preg_match('/^https?[^:]*:\/\//', $href ?? '')) {
return null; return null;
} }
$cacheKey = md5($href); $cacheKey = md5($href ?? '');
if (!$this->config()->get('bypass_cache')) { if (!$this->config()->get('bypass_cache')) {
// Check if we have a cached result // Check if we have a cached result
$result = $this->getCache()->get($cacheKey, false); $result = $this->getCache()->get($cacheKey, false);

View File

@ -68,7 +68,7 @@ class ExternalLinksTest extends SapphireTest
'http://www.broken.com/url/thing', 'http://www.broken.com/url/thing',
'http://www.nodomain.com' 'http://www.nodomain.com'
), ),
array_values($links->map('ID', 'Link')->toArray()) array_values($links->map('ID', 'Link')->toArray() ?? [])
); );
// Check response codes are correct // Check response codes are correct