Skip to content

Commit a011cff

Browse files
committed
fix: phpstan issues
1 parent 18bc9f4 commit a011cff

File tree

4 files changed

+71
-41
lines changed

4 files changed

+71
-41
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Tpetry\PostgresqlEnhanced\Backports;
6+
7+
use RuntimeException;
8+
9+
/**
10+
* To support some features these commits from laravel needed to be backported for older versions:
11+
* - [10.x] Escaping functionality within the Grammar (https://github.com/laravel/framework/commit/e953137280cdf6e0fe3c3e4c49d7209ad86c92c0).
12+
*/
13+
trait GrammarBackportEscape
14+
{
15+
/**
16+
* The connection used for escaping values.
17+
*
18+
* @var \Illuminate\Database\Connection
19+
*/
20+
protected $connection;
21+
22+
/**
23+
* Escapes a value for safe SQL embedding.
24+
*
25+
* @param string|float|int|bool|null $value
26+
* @param bool $binary
27+
*/
28+
public function escape($value, $binary = false): string
29+
{
30+
if (null === $this->connection) {
31+
throw new RuntimeException("The database driver's grammar implementation does not support escaping values.");
32+
}
33+
34+
return $this->connection->escape($value, $binary);
35+
}
36+
37+
/**
38+
* Set the grammar's database connection.
39+
*
40+
* @param \Illuminate\Database\Connection $connection
41+
*/
42+
public function setConnection($connection): static
43+
{
44+
$this->connection = $connection;
45+
46+
return $this;
47+
}
48+
}

src/Backports/GrammarBackport.php renamed to src/Backports/GrammarBackportSubstituteBindings.php

Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,13 @@
44

55
namespace Tpetry\PostgresqlEnhanced\Backports;
66

7-
use RuntimeException;
8-
97
/**
108
* To support some features these commits from laravel needed to be backported for older versions:
11-
* - [10.x] Escaping functionality within the Grammar (https://github.com/laravel/framework/commit/e953137280cdf6e0fe3c3e4c49d7209ad86c92c0).
129
* - [10.x] Add toRawSql, dumpRawSql() and ddRawSql() to Query Builders (https://github.com/laravel/framework/commit/830efbeeb815a5f1558433b673a58b0ddcbdc750).
1310
* - [11.x] Allow for custom Postgres operators to be added (https://github.com/laravel/framework/commit/029e993cb976e76a8d34d6b175eed8c8af1c3ed8)
1411
*/
15-
trait GrammarBackport
12+
trait GrammarBackportSubstituteBindings
1613
{
17-
/**
18-
* The connection used for escaping values.
19-
*
20-
* @var \Illuminate\Database\Connection
21-
*/
22-
protected $connection;
2314
/**
2415
* The Postgres grammar specific custom operators.
2516
*
@@ -37,21 +28,6 @@ public static function customOperators(array $operators): void
3728
);
3829
}
3930

40-
/**
41-
* Escapes a value for safe SQL embedding.
42-
*
43-
* @param string|float|int|bool|null $value
44-
* @param bool $binary
45-
*/
46-
public function escape($value, $binary = false): string
47-
{
48-
if (null === $this->connection) {
49-
throw new RuntimeException("The database driver's grammar implementation does not support escaping values.");
50-
}
51-
52-
return $this->connection->escape($value, $binary);
53-
}
54-
5531
/**
5632
* Get the Postgres grammar specific operators.
5733
*/
@@ -60,18 +36,6 @@ public function getOperators(): array
6036
return array_values(array_unique(array_merge($this->operators, static::$customOperators)));
6137
}
6238

63-
/**
64-
* Set the grammar's database connection.
65-
*
66-
* @param \Illuminate\Database\Connection $connection
67-
*/
68-
public function setConnection($connection): static
69-
{
70-
$this->connection = $connection;
71-
72-
return $this;
73-
}
74-
7539
/**
7640
* Substitute the given bindings into the given raw SQL query.
7741
*

src/Query/Grammar.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@
66

77
use Illuminate\Database\Query\Builder as BaseBuilder;
88
use Illuminate\Database\Query\Grammars\PostgresGrammar;
9-
use Tpetry\PostgresqlEnhanced\Backports\GrammarBackport;
9+
use Tpetry\PostgresqlEnhanced\Backports\GrammarBackportEscape;
10+
use Tpetry\PostgresqlEnhanced\Backports\GrammarBackportSubstituteBindings;
1011

1112
class Grammar extends PostgresGrammar
1213
{
13-
use GrammarBackport;
14+
use GrammarBackportEscape;
15+
use GrammarBackportSubstituteBindings;
1416
use GrammarCte;
1517
use GrammarFullText;
1618
use GrammarOrder;

src/Schema/Grammars/Grammar.php

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
namespace Tpetry\PostgresqlEnhanced\Schema\Grammars;
66

77
use Illuminate\Database\Schema\Grammars\PostgresGrammar;
8-
use Tpetry\PostgresqlEnhanced\Backports\GrammarBackport;
8+
use Tpetry\PostgresqlEnhanced\Backports\GrammarBackportEscape;
99

1010
class Grammar extends PostgresGrammar
1111
{
12-
use GrammarBackport;
12+
use GrammarBackportEscape;
1313
use GrammarIndex;
1414
use GrammarTable;
1515
use GrammarTrigger;
@@ -22,6 +22,22 @@ class Grammar extends PostgresGrammar
2222
*/
2323
protected $modifiers = ['Compression', 'Collate', 'Nullable', 'Default', 'VirtualAs', 'StoredAs', 'GeneratedAs', 'Increment'];
2424

25+
/**
26+
* Convert an array of columns with optional suffix keywords into a delimited string.
27+
*
28+
* @param array<int, string> $columns
29+
*/
30+
public function columnizeWithSuffix(array $columns): string
31+
{
32+
$columns = array_map(function (string $column): string {
33+
$parts = explode(' ', $column, 2);
34+
35+
return trim(\sprintf('%s %s', $this->wrap($parts[0]), $parts[1] ?? ''));
36+
}, $columns);
37+
38+
return implode(', ', $columns);
39+
}
40+
2541
/**
2642
* Convert an array of names into a delimited string.
2743
*/

0 commit comments

Comments
 (0)