Compare commits

...

2 Commits

Author SHA1 Message Date
Guy Sartorelli
164032af76
Merge pull request #77 from creative-commoners/pulls/2/php81
ENH PHP 8.1 compatibility
2022-04-26 17:58:36 +12:00
Steve Boyd
1bfaf12909 ENH PHP 8.1 compatibility 2022-04-13 10:29:57 +12:00
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