mirror of
https://github.com/silverstripe/silverstripe-externallinks.git
synced 2024-10-22 17:05:44 +02:00
Merge pull request #77 from creative-commoners/pulls/2/php81
ENH PHP 8.1 compatibility
This commit is contained in:
commit
164032af76
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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);
|
||||||
|
@ -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
|
||||||
|
Loading…
Reference in New Issue
Block a user