diff --git a/src/CwpSearchResult.php b/src/CwpSearchResult.php index bd42c79..19d9540 100644 --- a/src/CwpSearchResult.php +++ b/src/CwpSearchResult.php @@ -200,9 +200,9 @@ 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; } @@ -210,6 +210,6 @@ protected function getLink($terms, $format = null) 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 ?? []); } } diff --git a/src/Extensions/SynonymValidator.php b/src/Extensions/SynonymValidator.php index af5d35b..ca0511c 100644 --- a/src/Extensions/SynonymValidator.php +++ b/src/Extensions/SynonymValidator.php @@ -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] !== '#'; }); @@ -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)) { @@ -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)) { @@ -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; } diff --git a/src/Solr/CwpSolr.php b/src/Solr/CwpSolr.php index bbd8e6d..af0cf31 100644 --- a/src/Solr/CwpSolr.php +++ b/src/Solr/CwpSolr.php @@ -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'; diff --git a/src/Solr/CwpSolrConfigStore.php b/src/Solr/CwpSolrConfigStore.php index ae659e7..57d8851 100644 --- a/src/Solr/CwpSolrConfigStore.php +++ b/src/Solr/CwpSolrConfigStore.php @@ -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 ?? '')); } /**