Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH PHP 8.1 compatibility #42

Merged
merged 1 commit into from
Apr 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/CwpSearchResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,16 +200,16 @@ protected function getLink($terms, $format = null)
if (!$terms) {
return null;
}
$link = 'search/SearchForm?Search='.rawurlencode($terms);
$link = 'search/SearchForm?Search='.rawurlencode($terms ?? '');
if ($format) {
$link .= '&format='.rawurlencode($format);
$link .= '&format='.rawurlencode($format ?? '');
}
return $link;
}

public function hasField($field)
{
// Fix customise not detecting custom field getters
return array_key_exists($field, $this->config()->casting);
return array_key_exists($field, $this->config()->casting ?? []);
}
}
22 changes: 11 additions & 11 deletions src/Extensions/SynonymValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,12 @@ protected function validateValue($value)
{
// strip empty lines
$lines = array_filter(
explode("\n", $value)
explode("\n", $value ?? '')
);

// strip comments (lines beginning with "#")
$lines = array_filter($lines, function ($line) {
$line = trim($line);
$lines = array_filter($lines ?? [], function ($line) {
$line = trim($line ?? '');

return !empty($line) && $line[0] !== '#';
});
Expand All @@ -100,10 +100,10 @@ protected function validateValue($value)
*/
protected function validateLine($line)
{
$line = trim($line);
$line = trim($line ?? '');

$parts = explode(',', $line);
$parts = array_filter($parts);
$parts = explode(',', $line ?? '');
$parts = array_filter($parts ?? []);

foreach ($parts as $part) {
if (!$this->validatePart($part)) {
Expand All @@ -123,9 +123,9 @@ protected function validateLine($line)
*/
protected function validatePart($part)
{
if (strpos($part, '=>') !== false) {
$subs = explode('=>', $part);
$subs = array_filter($subs);
if (strpos($part ?? '', '=>') !== false) {
$subs = explode('=>', $part ?? '');
$subs = array_filter($subs ?? []);

foreach ($subs as $sub) {
if (!$this->validateNoSpaces($sub)) {
Expand All @@ -147,10 +147,10 @@ protected function validatePart($part)
protected function validateNoSpaces($value)
{
// allow spaces at the beginning and end of the value
$value = trim($value);
$value = trim($value ?? '');

// does the value contain 1 or more whitespace characters?
if (preg_match('/\s+/', $value)) {
if (preg_match('/\s+/', $value ?? '')) {
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Solr/CwpSolr.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public static function configure()

// Allow users to override extras path.
// CAUTION: CWP does not permit usage of customised solrconfig.xml.
if (isset($options['extraspath']) && file_exists($options['extraspath'])) {
if (isset($options['extraspath']) && file_exists($options['extraspath'] ?? '')) {
$solrOptions['extraspath'] = $options['extraspath'];
} elseif (file_exists(BASE_PATH . '/app/conf/extras')) {
$solrOptions['extraspath'] = BASE_PATH . '/app/conf/extras';
Expand Down
2 changes: 1 addition & 1 deletion src/Solr/CwpSolrConfigStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function __construct($config)
*/
public function uploadFile($index, $file)
{
$this->uploadString($index, basename($file), file_get_contents($file));
$this->uploadString($index, basename($file ?? ''), file_get_contents($file ?? ''));
}

/**
Expand Down