Skip to content

Commit

Permalink
Merge pull request #42 from creative-commoners/pulls/1/php81
Browse files Browse the repository at this point in the history
ENH PHP 8.1 compatibility
  • Loading branch information
GuySartorelli authored Apr 26, 2022
2 parents 2ededf5 + a884a2a commit 7d16067
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 16 deletions.
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

0 comments on commit 7d16067

Please sign in to comment.