Skip to content

Commit e05c6c4

Browse files
committed
php-cs-fixer
1 parent 58aae1e commit e05c6c4

15 files changed

+56
-111
lines changed

src/Commands/ManageIndexes.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@ public function __construct(IndexService $indexService)
4040
* Execute the console command.
4141
*
4242
* @param Dispatcher $events
43+
*
4344
* @return mixed
4445
*/
4546
public function handle(Dispatcher $events)
4647
{
47-
4848
$events->listen(Events\ModelIndexCreated::class, function ($event) {
4949
$this->comment("Index '$event->indexName' created with fields: $event->indexFields");
5050
});
@@ -64,19 +64,16 @@ public function handle(Dispatcher $events)
6464
$model = $this->argument('model');
6565
$drop = $this->option('drop');
6666

67-
if(! $model) {
67+
if (!$model) {
6868
$modelDirectories = config('scout.mysql.model_directories');
6969
$searchableModels = $this->indexService->getAllSearchableModels($modelDirectories);
7070

7171
foreach ($searchableModels as $searchableModel) {
7272
$drop ? $this->dropModelIndex($searchableModel) : $this->createOrUpdateModelIndex($searchableModel);
7373
}
74-
75-
}
76-
else {
74+
} else {
7775
$drop ? $this->dropModelIndex($model) : $this->createOrUpdateModelIndex($model);
7876
}
79-
8077
}
8178

8279
private function createOrUpdateModelIndex($searchableModel)
@@ -92,5 +89,4 @@ private function dropModelIndex($searchableModel)
9289
$this->indexService->setModel($searchableModel);
9390
$this->indexService->dropIndex();
9491
}
95-
9692
}

src/Engines/Modes/Boolean.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,10 @@
77

88
class Boolean extends Mode
99
{
10-
1110
public function buildWhereRawString(Builder $builder)
1211
{
1312
$queryString = '';
1413

15-
1614
$queryString .= $this->buildWheres($builder);
1715

1816
$indexFields = implode(',', $this->modelService->setModel($builder->model)->getFullTextIndexFields());
@@ -24,8 +22,8 @@ public function buildWhereRawString(Builder $builder)
2422

2523
public function buildParams(Builder $builder)
2624
{
27-
2825
$this->whereParams['_search'] = $builder->query;
26+
2927
return $this->whereParams;
3028
}
3129

src/Engines/Modes/Like.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22

33
namespace DamianTW\MySQLScout\Engines\Modes;
4+
45
use Laravel\Scout\Builder;
56
use DamianTW\MySQLScout\Services\ModelService;
67

@@ -10,7 +11,6 @@ class Like extends Mode
1011

1112
public function buildWhereRawString(Builder $builder)
1213
{
13-
1414
$queryString = '';
1515

1616
$this->fields = $this->modelService->setModel($builder->model)->getSearchableFields();
@@ -22,20 +22,19 @@ public function buildWhereRawString(Builder $builder)
2222
$itr = 0;
2323
foreach ($this->fields as $field) {
2424
$queryString .= "`$field` LIKE :_search$itr OR ";
25-
$itr++;
25+
++$itr;
2626
}
2727

2828
$queryString = trim($queryString, 'OR ');
2929
$queryString .= ')';
3030

3131
return $queryString;
32-
3332
}
3433

3534
public function buildParams(Builder $builder)
3635
{
37-
for ($itr = 0; $itr < count($this->fields); $itr++) {
38-
$this->whereParams["_search$itr"] = '%' . $builder->query . '%';
36+
for ($itr = 0; $itr < count($this->fields); ++$itr) {
37+
$this->whereParams["_search$itr"] = '%'.$builder->query.'%';
3938
}
4039

4140
return $this->whereParams;
@@ -45,4 +44,4 @@ public function isFullText()
4544
{
4645
return false;
4746
}
48-
}
47+
}

src/Engines/Modes/LikeExpanded.php

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,10 @@
77

88
class LikeExpanded extends Mode
99
{
10-
1110
protected $fields;
1211

1312
public function buildWhereRawString(Builder $builder)
1413
{
15-
1614
$queryString = '';
1715

1816
$this->fields = $this->modelService->setModel($builder->model)->getSearchableFields();
@@ -28,35 +26,33 @@ public function buildWhereRawString(Builder $builder)
2826
foreach ($this->fields as $field) {
2927
foreach ($words as $word) {
3028
$queryString .= "`$field` LIKE :_search$itr OR ";
31-
$itr++;
29+
++$itr;
3230
}
3331
}
3432

3533
$queryString = trim($queryString, 'OR ');
3634
$queryString .= ')';
3735

3836
return$queryString;
39-
4037
}
4138

4239
public function buildParams(Builder $builder)
4340
{
4441
$words = explode(' ', $builder->query);
4542

4643
$itr = 0;
47-
for ($i = 0; $i < count($this->fields); $i++) {
44+
for ($i = 0; $i < count($this->fields); ++$i) {
4845
foreach ($words as $word) {
49-
$this->whereParams["_search$itr"] = '%' . $word . '%';
50-
$itr ++;
46+
$this->whereParams["_search$itr"] = '%'.$word.'%';
47+
++$itr;
5148
}
5249
}
5350

5451
return $this->whereParams;
55-
5652
}
5753

5854
public function isFullText()
5955
{
6056
return false;
6157
}
62-
}
58+
}

src/Engines/Modes/Mode.php

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,11 @@
77

88
abstract class Mode
99
{
10-
1110
protected $whereParams = [];
1211

1312
protected $modelService;
1413

15-
function __construct()
14+
public function __construct()
1615
{
1716
$this->modelService = resolve(ModelService::class);
1817
}
@@ -25,13 +24,11 @@ abstract public function isFullText();
2524

2625
protected function buildWheres(Builder $builder)
2726
{
28-
2927
$queryString = '';
3028

3129
$parsedWheres = $this->parseWheres($builder->wheres);
3230

3331
foreach ($parsedWheres as $parsedWhere) {
34-
3532
$field = $parsedWhere[0];
3633
$operator = $parsedWhere[1];
3734
$value = $parsedWhere[2];
@@ -46,14 +43,14 @@ protected function buildWheres(Builder $builder)
4643

4744
private function parseWheres($wheres)
4845
{
49-
$pattern = '/([A-Za-z_]+[A-Za-z_0-9]?)[ ]?(<>|!=|=|<=|<|>=|>)/';
46+
$pattern = '/([A-Za-z_]+[A-Za-z_0-9]?)[ ]?(<>|!=|=|<=|<|>=|>)/';
5047

5148
$result = array();
52-
foreach($wheres as $field => $value) {
49+
foreach ($wheres as $field => $value) {
5350
preg_match($pattern, $field, $matches);
54-
$result []= !empty($matches) ? array($matches[1], $matches[2], $value) : array($field, '=', $value);
51+
$result [] = !empty($matches) ? array($matches[1], $matches[2], $value) : array($field, '=', $value);
5552
}
53+
5654
return $result;
5755
}
58-
5956
}

src/Engines/Modes/ModeContainer.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,15 @@
22

33
namespace DamianTW\MySQLScout\Engines\Modes;
44

5-
65
class ModeContainer
76
{
87
public $mode;
98

109
public $fallbackMode;
1110

12-
function __construct($mode, $fallbackMode)
11+
public function __construct($mode, $fallbackMode)
1312
{
1413
$this->mode = $mode;
1514
$this->fallbackMode = $fallbackMode;
1615
}
17-
}
16+
}

src/Engines/Modes/NaturalLanguage.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
class NaturalLanguage extends Mode
88
{
9-
109
public function buildWhereRawString(Builder $builder)
1110
{
1211
$queryString = '';
@@ -17,25 +16,24 @@ public function buildWhereRawString(Builder $builder)
1716

1817
$queryString .= "MATCH($indexFields) AGAINST(:_search IN NATURAL LANGUAGE MODE";
1918

20-
if(config('scout.mysql.query_expansion')) {
19+
if (config('scout.mysql.query_expansion')) {
2120
$queryString .= ' WITH QUERY EXPANSION';
2221
}
2322

2423
$queryString .= ')';
2524

2625
return $queryString;
27-
2826
}
2927

3028
public function buildParams(Builder $builder)
3129
{
32-
3330
$this->whereParams['_search'] = $builder->query;
31+
3432
return $this->whereParams;
3533
}
3634

3735
public function isFullText()
3836
{
3937
return true;
4038
}
41-
}
39+
}

src/Engines/MySQLEngine.php

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,22 @@
99

1010
class MySQLEngine extends Engine
1111
{
12-
1312
protected $mode;
1413

1514
protected $fallbackMode;
1615

17-
function __construct(ModeContainer $modeContainer)
16+
public function __construct(ModeContainer $modeContainer)
1817
{
1918
$this->mode = $modeContainer->mode;
2019
$this->fallbackMode = $modeContainer->fallbackMode;
2120
}
2221

2322
public function update($models)
2423
{
25-
2624
}
2725

2826
public function delete($models)
2927
{
30-
3128
}
3229

3330
/**
@@ -39,12 +36,12 @@ public function delete($models)
3936
*/
4037
public function search(Builder $builder)
4138
{
42-
4339
$result = [];
4440

45-
if($this->shouldNotRun($builder)) {
41+
if ($this->shouldNotRun($builder)) {
4642
$result['results'] = Collection::make();
4743
$result['count'] = 0;
44+
4845
return $result;
4946
}
5047

@@ -64,18 +61,17 @@ public function search(Builder $builder)
6461
}
6562
}
6663

67-
if($builder->limit) {
64+
if ($builder->limit) {
6865
$query = $query->take($builder->limit);
6966
}
7067

71-
if(property_exists($builder, 'offset') && $builder->offset) {
68+
if (property_exists($builder, 'offset') && $builder->offset) {
7269
$query = $query->skip($builder->offset);
7370
}
7471

7572
$result['results'] = $query->get();
7673

7774
return $result;
78-
7975
}
8076

8177
/**
@@ -91,6 +87,7 @@ public function paginate(Builder $builder, $perPage, $page)
9187
{
9288
$builder->limit = $perPage;
9389
$builder->offset = ($perPage * $page) - $perPage;
90+
9491
return $this->search($builder);
9592
}
9693

@@ -129,5 +126,4 @@ protected function shouldUseFallback($builder)
129126
return $this->mode->isFullText() &&
130127
strlen($builder->query) < config('scout.mysql.min_fulltext_search_length');
131128
}
132-
133129
}

src/Events/ModelIndexCreated.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@
22

33
namespace DamianTW\MySQLScout\Events;
44

5-
65
class ModelIndexCreated
76
{
8-
97
public $indexName;
108
public $indexFields;
119

@@ -14,12 +12,10 @@ class ModelIndexCreated
1412
*
1513
* @param $indexName
1614
* @param $indexFields
17-
* @return void
1815
*/
1916
public function __construct($indexName, $indexFields)
2017
{
2118
$this->indexName = $indexName;
2219
$this->indexFields = $indexFields;
2320
}
24-
2521
}

src/Events/ModelIndexDropped.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,17 @@
22

33
namespace DamianTW\MySQLScout\Events;
44

5-
65
class ModelIndexDropped
76
{
8-
97
public $indexName;
108

119
/**
1210
* Create a new event instance.
1311
*
1412
* @param $indexName
15-
* @return void
1613
*/
1714
public function __construct($indexName)
1815
{
1916
$this->indexName = $indexName;
2017
}
21-
2218
}

0 commit comments

Comments
 (0)