Skip to content

Commit b90a3ab

Browse files
committed
Leverage the match expression
1 parent 8b3d14b commit b90a3ab

File tree

2 files changed

+23
-49
lines changed

2 files changed

+23
-49
lines changed

Session/Storage/Handler/PdoSessionHandler.php

Lines changed: 13 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -184,30 +184,19 @@ public function createTable()
184184
// connect if we are not yet
185185
$this->getConnection();
186186

187-
switch ($this->driver) {
188-
case 'mysql':
189-
// We use varbinary for the ID column because it prevents unwanted conversions:
190-
// - character set conversions between server and client
191-
// - trailing space removal
192-
// - case-insensitivity
193-
// - language processing like é == e
194-
$sql = "CREATE TABLE $this->table ($this->idCol VARBINARY(128) NOT NULL PRIMARY KEY, $this->dataCol BLOB NOT NULL, $this->lifetimeCol INTEGER UNSIGNED NOT NULL, $this->timeCol INTEGER UNSIGNED NOT NULL) COLLATE utf8mb4_bin, ENGINE = InnoDB";
195-
break;
196-
case 'sqlite':
197-
$sql = "CREATE TABLE $this->table ($this->idCol TEXT NOT NULL PRIMARY KEY, $this->dataCol BLOB NOT NULL, $this->lifetimeCol INTEGER NOT NULL, $this->timeCol INTEGER NOT NULL)";
198-
break;
199-
case 'pgsql':
200-
$sql = "CREATE TABLE $this->table ($this->idCol VARCHAR(128) NOT NULL PRIMARY KEY, $this->dataCol BYTEA NOT NULL, $this->lifetimeCol INTEGER NOT NULL, $this->timeCol INTEGER NOT NULL)";
201-
break;
202-
case 'oci':
203-
$sql = "CREATE TABLE $this->table ($this->idCol VARCHAR2(128) NOT NULL PRIMARY KEY, $this->dataCol BLOB NOT NULL, $this->lifetimeCol INTEGER NOT NULL, $this->timeCol INTEGER NOT NULL)";
204-
break;
205-
case 'sqlsrv':
206-
$sql = "CREATE TABLE $this->table ($this->idCol VARCHAR(128) NOT NULL PRIMARY KEY, $this->dataCol VARBINARY(MAX) NOT NULL, $this->lifetimeCol INTEGER NOT NULL, $this->timeCol INTEGER NOT NULL)";
207-
break;
208-
default:
209-
throw new \DomainException(sprintf('Creating the session table is currently not implemented for PDO driver "%s".', $this->driver));
210-
}
187+
$sql = match ($this->driver) {
188+
// We use varbinary for the ID column because it prevents unwanted conversions:
189+
// - character set conversions between server and client
190+
// - trailing space removal
191+
// - case-insensitivity
192+
// - language processing like é == e
193+
'mysql' => "CREATE TABLE $this->table ($this->idCol VARBINARY(128) NOT NULL PRIMARY KEY, $this->dataCol BLOB NOT NULL, $this->lifetimeCol INTEGER UNSIGNED NOT NULL, $this->timeCol INTEGER UNSIGNED NOT NULL) COLLATE utf8mb4_bin, ENGINE = InnoDB",
194+
'sqlite' => "CREATE TABLE $this->table ($this->idCol TEXT NOT NULL PRIMARY KEY, $this->dataCol BLOB NOT NULL, $this->lifetimeCol INTEGER NOT NULL, $this->timeCol INTEGER NOT NULL)",
195+
'pgsql' => "CREATE TABLE $this->table ($this->idCol VARCHAR(128) NOT NULL PRIMARY KEY, $this->dataCol BYTEA NOT NULL, $this->lifetimeCol INTEGER NOT NULL, $this->timeCol INTEGER NOT NULL)",
196+
'oci' => "CREATE TABLE $this->table ($this->idCol VARCHAR2(128) NOT NULL PRIMARY KEY, $this->dataCol BLOB NOT NULL, $this->lifetimeCol INTEGER NOT NULL, $this->timeCol INTEGER NOT NULL)",
197+
'sqlsrv' => "CREATE TABLE $this->table ($this->idCol VARCHAR(128) NOT NULL PRIMARY KEY, $this->dataCol VARBINARY(MAX) NOT NULL, $this->lifetimeCol INTEGER NOT NULL, $this->timeCol INTEGER NOT NULL)",
198+
default => throw new \DomainException(sprintf('Creating the session table is currently not implemented for PDO driver "%s".', $this->driver)),
199+
};
211200

212201
try {
213202
$this->pdo->exec($sql);

Tests/File/UploadedFileTest.php

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -173,31 +173,16 @@ public function failedUploadedFile()
173173
*/
174174
public function testMoveFailed(UploadedFile $file)
175175
{
176-
switch ($file->getError()) {
177-
case \UPLOAD_ERR_INI_SIZE:
178-
$exceptionClass = IniSizeFileException::class;
179-
break;
180-
case \UPLOAD_ERR_FORM_SIZE:
181-
$exceptionClass = FormSizeFileException::class;
182-
break;
183-
case \UPLOAD_ERR_PARTIAL:
184-
$exceptionClass = PartialFileException::class;
185-
break;
186-
case \UPLOAD_ERR_NO_FILE:
187-
$exceptionClass = NoFileException::class;
188-
break;
189-
case \UPLOAD_ERR_CANT_WRITE:
190-
$exceptionClass = CannotWriteFileException::class;
191-
break;
192-
case \UPLOAD_ERR_NO_TMP_DIR:
193-
$exceptionClass = NoTmpDirFileException::class;
194-
break;
195-
case \UPLOAD_ERR_EXTENSION:
196-
$exceptionClass = ExtensionFileException::class;
197-
break;
198-
default:
199-
$exceptionClass = FileException::class;
200-
}
176+
$exceptionClass = match ($file->getError()) {
177+
\UPLOAD_ERR_INI_SIZE => IniSizeFileException::class,
178+
\UPLOAD_ERR_FORM_SIZE => FormSizeFileException::class,
179+
\UPLOAD_ERR_PARTIAL => PartialFileException::class,
180+
\UPLOAD_ERR_NO_FILE => NoFileException::class,
181+
\UPLOAD_ERR_CANT_WRITE => CannotWriteFileException::class,
182+
\UPLOAD_ERR_NO_TMP_DIR => NoTmpDirFileException::class,
183+
\UPLOAD_ERR_EXTENSION => ExtensionFileException::class,
184+
default => FileException::class,
185+
};
201186

202187
$this->expectException($exceptionClass);
203188

0 commit comments

Comments
 (0)