Skip to content

Commit 201bed5

Browse files
committed
Refactoring
1 parent 324fe86 commit 201bed5

File tree

3 files changed

+32
-30
lines changed

3 files changed

+32
-30
lines changed

src/Facades/Schema.php

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -61,31 +61,33 @@ public static function connection($name)
6161
*/
6262
public static function getSchemaBuilder(Connection $connection)
6363
{
64-
$driver = $connection->getDriverName();
65-
66-
switch ($driver) {
67-
case 'mysql':
68-
$connection->setSchemaGrammar($connection->withTablePrefix(new MySqlGrammar()));
69-
70-
return new MySqlBuilder($connection);
71-
case 'mariadb':
72-
$connection->setSchemaGrammar($connection->withTablePrefix(new MariaDbGrammar()));
73-
74-
return new MariaDbBuilder($connection);
75-
case 'pgsql':
76-
$connection->setSchemaGrammar($connection->withTablePrefix(new PostgresGrammar()));
77-
78-
return new PostgresBuilder($connection);
79-
case 'sqlite':
80-
$connection->setSchemaGrammar($connection->withTablePrefix(new SQLiteGrammar()));
81-
82-
return new SQLiteBuilder($connection);
83-
case 'sqlsrv':
84-
$connection->setSchemaGrammar($connection->withTablePrefix(new SqlServerGrammar()));
85-
86-
return new SqlServerBuilder($connection);
87-
}
88-
89-
throw new RuntimeException('This database is not supported.'); // @codeCoverageIgnore
64+
return match ($connection->getDriverName()) {
65+
'mysql' => new MySqlBuilder(
66+
$connection->setSchemaGrammar(
67+
$connection->withTablePrefix(new MySqlGrammar())
68+
)
69+
),
70+
'mariadb' => new MariaDbBuilder(
71+
$connection->setSchemaGrammar(
72+
$connection->withTablePrefix(new MariaDbGrammar())
73+
)
74+
),
75+
'pgsql' => new PostgresBuilder(
76+
$connection->setSchemaGrammar(
77+
$connection->withTablePrefix(new PostgresGrammar())
78+
)
79+
),
80+
'sqlite' => new SQLiteBuilder(
81+
$connection->setSchemaGrammar(
82+
$connection->withTablePrefix(new SQLiteGrammar())
83+
)
84+
),
85+
'sqlsrv' => new SqlServerBuilder(
86+
$connection->setSchemaGrammar(
87+
$connection->withTablePrefix(new SqlServerGrammar())
88+
)
89+
),
90+
default => throw new RuntimeException('This database is not supported.'), // @codeCoverageIgnore
91+
};
9092
}
9193
}

src/Schema/Builders/ManagesViews.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,13 @@ protected function stringifyBindings(array $bindings)
8282
{
8383
$bindings = $this->connection->prepareBindings($bindings);
8484

85-
foreach ($bindings as &$binding) {
85+
foreach ($bindings as $key => $binding) {
8686
if (is_object($binding)) {
8787
$binding = (string) $binding;
8888
}
8989

9090
if (is_string($binding)) {
91-
$binding = $this->connection->getPdo()->quote($binding);
91+
$bindings[$key] = $this->connection->getPdo()->quote($binding);
9292
}
9393
}
9494

src/Schema/Builders/PostgresBuilder.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ class PostgresBuilder extends Base
1818
*/
1919
protected function stringifyBindings(array $bindings)
2020
{
21-
foreach ($bindings as &$binding) {
21+
foreach ($bindings as $key => $binding) {
2222
if (is_bool($binding)) {
23-
$binding = $binding ? 'true' : 'false';
23+
$bindings[$key] = $binding ? 'true' : 'false';
2424
}
2525
}
2626

0 commit comments

Comments
 (0)