Skip to content

Commit 891337c

Browse files
Replace switch statement with match expression
- Remove now obsolete throw annotation and imports
1 parent 94364fa commit 891337c

File tree

1 file changed

+6
-20
lines changed

1 file changed

+6
-20
lines changed

src/QueryBuilder.php

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,10 @@
22

33
namespace ipl\Sql;
44

5-
use InvalidArgumentException;
65
use ipl\Sql\Adapter\Mssql;
76
use ipl\Sql\Contract\Adapter;
87
use ipl\Stdlib\Events;
98

10-
use function ipl\Stdlib\get_php_type;
11-
129
class QueryBuilder
1310
{
1411
use Events;
@@ -163,26 +160,15 @@ public function __construct(Adapter $adapter)
163160
* @param Delete|Insert|Select|Update $stmt
164161
*
165162
* @return array
166-
*
167-
* @throw InvalidArgumentException If statement type is invalid
168163
*/
169164
public function assemble(Select|Insert|Update|Delete $stmt): array
170165
{
171-
switch (true) {
172-
case $stmt instanceof Delete:
173-
return $this->assembleDelete($stmt);
174-
case $stmt instanceof Insert:
175-
return $this->assembleInsert($stmt);
176-
case $stmt instanceof Select:
177-
return $this->assembleSelect($stmt);
178-
case $stmt instanceof Update:
179-
return $this->assembleUpdate($stmt);
180-
default:
181-
throw new InvalidArgumentException(sprintf(
182-
__METHOD__ . ' expects instances of Delete, Insert, Select or Update. Got %s instead.',
183-
get_php_type($stmt)
184-
));
185-
}
166+
return match (true) {
167+
$stmt instanceof Delete => $this->assembleDelete($stmt),
168+
$stmt instanceof Insert => $this->assembleInsert($stmt),
169+
$stmt instanceof Select => $this->assembleSelect($stmt),
170+
$stmt instanceof Update => $this->assembleUpdate($stmt)
171+
};
186172
}
187173

188174
/**

0 commit comments

Comments
 (0)