From 19d7db244d0169af7ae0e35fe17d24a28fa137d4 Mon Sep 17 00:00:00 2001 From: Tom Lingham Date: Sat, 14 May 2016 11:32:14 +1000 Subject: [PATCH] Just some tlc --- src/Matchers/BaseMatcher.php | 3 +-- src/SearchBuilder.php | 20 +++++++++----------- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/src/Matchers/BaseMatcher.php b/src/Matchers/BaseMatcher.php index 720f8af..30ad9c1 100755 --- a/src/Matchers/BaseMatcher.php +++ b/src/Matchers/BaseMatcher.php @@ -27,9 +27,8 @@ abstract class BaseMatcher implements MatcherInterface */ public function buildQueryString($column, $searchString) { - if (method_exists($this, 'formatSearchString')) { + if (method_exists($this, 'formatSearchString')) $searchString = $this->formatSearchString($searchString); - } return "IF($column {$this->operator} '$searchString', {$this->multiplier}, 0)"; } diff --git a/src/SearchBuilder.php b/src/SearchBuilder.php index 7b11fb5..57ff74a 100755 --- a/src/SearchBuilder.php +++ b/src/SearchBuilder.php @@ -42,11 +42,10 @@ class SearchBuilder */ public function search($searchable) { - if (is_object($searchable) && method_exists($searchable, 'getTable')) { - $this->table = $searchable->getTable(); - } else { - $this->table = $searchable; - } + // Check if table name or Eloquent + $isEloquent = is_object($searchable) && method_exists($searchable, 'getTable'); + + $this->table = $isEloquent ? $searchable->getTable() : $searchable; return $this; } @@ -95,18 +94,17 @@ class SearchBuilder // Check if default driver is being overridden, otherwise // load the default - if ($this->driverName) { - $driverName = $this->driverName; - } else { - $driverName = $this->config->get('searchy.default'); - } + $driverName = $this->driverName ? $this->driverName : $this->config->get('searchy.default'); // Gets the details for the selected driver from the configuration file $driver = $this->config->get("searchy.drivers.$driverName")['class']; // Create a new instance of the selected drivers 'class' and pass // through table and fields to search - $driverInstance = new $driver($this->table, $this->searchFields, $relevanceFieldName, ['*']); + $driverInstance = new $driver( $this->table, + $this->searchFields, + $relevanceFieldName, + ['*']); return $driverInstance; }