Skip to content

Commit fda6d6f

Browse files
committed
improvements
1 parent 96325a8 commit fda6d6f

File tree

4 files changed

+10
-7
lines changed

4 files changed

+10
-7
lines changed

src/Query/BuilderWhere.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ public function orWhereIntegerArrayMatches($column, string $query): static
6363
*
6464
* @param Expression|string $column
6565
* @param Expression|string $value
66+
* @param bool $caseSensitive
6667
*/
6768
public function orWhereLike($column, $value, $caseSensitive = false): static
6869
{
@@ -181,7 +182,9 @@ public function whereIntegerArrayMatches($column, string $query): static
181182
*
182183
* @param Expression|string $column
183184
* @param Expression|string $value
185+
* @param bool $caseSensitive
184186
* @param string $boolean
187+
* @param bool $not
185188
*/
186189
public function whereLike($column, $value, $caseSensitive = false, $boolean = 'and', $not = false): static
187190
{

src/Query/GrammarWhere.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,10 @@ public function whereAny(Builder $query, $where): string
5050
*/
5151
public function whereLike(Builder $query, $where): string
5252
{
53-
$where['operator'] = $where['not'] ? 'not ' : '';
54-
$where['operator'] .= $where['caseSensitive'] ? 'like' : 'ilike';
55-
56-
return "{$this->wrap($where['column'])} {$where['operator']} {$this->parameter($where['value'])}";
53+
return match ($where['caseSensitive']) {
54+
true => "{$this->wrap($where['column'])} like {$this->parameter($where['value'])}",
55+
false => "{$this->wrap($where['column'])} ilike {$this->parameter($where['value'])}",
56+
};
5757
}
5858

5959
/**

src/Schema/Grammars/GrammarTable.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
namespace Tpetry\PostgresqlEnhanced\Schema\Grammars;
66

7+
use Arr;
78
use Illuminate\Database\Schema\Blueprint;
8-
use Illuminate\Support\Arr;
99
use Illuminate\Support\Fluent;
1010

1111
trait GrammarTable

tests/Query/WhereTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public function testOrWhereLike(): void
9999
$this->getConnection()->table('example')->orWhereLike('str', 'OamekKIC', true)->orWhereLike('str', 'HmC3xURl', true)->get();
100100
});
101101
$this->assertEquals(
102-
['select * from "example" where "str" like ? or "str" like ?', 'select * from "example" where "str" ilike ? or "str" ilike ?'],
102+
['select * from "example" where "str" ilike ? or "str" ilike ?', 'select * from "example" where "str" like ? or "str" like ?'],
103103
array_column($queries, 'query'),
104104
);
105105
$this->assertEquals(
@@ -258,7 +258,7 @@ public function testWhereLike(): void
258258
$this->getConnection()->table('example')->whereLike('str', 'IcuC5Cqz', true)->get();
259259
});
260260
$this->assertEquals(
261-
['select * from "example" where "str" like ?', 'select * from "example" where "str" ilike ?'],
261+
['select * from "example" where "str" ilike ?', 'select * from "example" where "str" like ?'],
262262
array_column($queries, 'query'),
263263
);
264264
$this->assertEquals(

0 commit comments

Comments
 (0)