convert `switch` to `match`
This commit is contained in:
parent
fdddd63aae
commit
3d88ae7916
|
@ -27,19 +27,14 @@ function angeltypes_controller()
|
|||
{
|
||||
$action = strip_request_item('action', 'list');
|
||||
|
||||
switch ($action) {
|
||||
case 'view':
|
||||
return angeltype_controller();
|
||||
case 'edit':
|
||||
return angeltype_edit_controller();
|
||||
case 'delete':
|
||||
return angeltype_delete_controller();
|
||||
case 'about':
|
||||
return angeltypes_about_controller();
|
||||
case 'list':
|
||||
default:
|
||||
return angeltypes_list_controller();
|
||||
}
|
||||
return match ($action) {
|
||||
'view' => angeltype_controller(),
|
||||
'edit' => angeltype_edit_controller(),
|
||||
'delete' => angeltype_delete_controller(),
|
||||
'about' => angeltypes_about_controller(),
|
||||
'list' => angeltypes_list_controller(),
|
||||
default => angeltypes_list_controller(),
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -71,15 +71,11 @@ function rooms_controller(): array
|
|||
$action = 'list';
|
||||
}
|
||||
|
||||
switch ($action) {
|
||||
case 'view':
|
||||
return room_controller();
|
||||
case 'list':
|
||||
default:
|
||||
throw_redirect(page_link_to('admin_rooms'));
|
||||
}
|
||||
|
||||
return ['', ''];
|
||||
return match ($action) {
|
||||
'view' => room_controller(),
|
||||
'list' => throw_redirect(page_link_to('admin_rooms')),
|
||||
default => throw_redirect(page_link_to('admin_rooms')),
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -24,14 +24,11 @@ function shift_entries_controller(): array
|
|||
throw_redirect(user_link($user->id));
|
||||
}
|
||||
|
||||
switch ($action) {
|
||||
case 'create':
|
||||
return shift_entry_create_controller();
|
||||
case 'delete':
|
||||
return shift_entry_delete_controller();
|
||||
}
|
||||
|
||||
return ['', ''];
|
||||
return match ($action) {
|
||||
'create' => shift_entry_create_controller(),
|
||||
'delete' => shift_entry_delete_controller(),
|
||||
default => ['', ''],
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -334,7 +334,7 @@ function shift_controller()
|
|||
}
|
||||
|
||||
/**
|
||||
* @return array|false
|
||||
* @return array
|
||||
*/
|
||||
function shifts_controller()
|
||||
{
|
||||
|
@ -343,18 +343,11 @@ function shifts_controller()
|
|||
throw_redirect(page_link_to('user_shifts'));
|
||||
}
|
||||
|
||||
switch ($request->input('action')) {
|
||||
case 'view':
|
||||
return shift_controller();
|
||||
/** @noinspection PhpMissingBreakStatementInspection */
|
||||
case 'next':
|
||||
shift_next_controller();
|
||||
// fall through
|
||||
default:
|
||||
throw_redirect(page_link_to('/'));
|
||||
}
|
||||
|
||||
return false;
|
||||
return match ($request->input('action')) {
|
||||
'view' => shift_controller(),
|
||||
'next' => shift_next_controller(), // throw_redirect
|
||||
default => throw_redirect(page_link_to('/')),
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -153,15 +153,11 @@ function shifttypes_controller()
|
|||
$action = $request->input('action');
|
||||
}
|
||||
|
||||
switch ($action) {
|
||||
case 'view':
|
||||
return shifttype_controller();
|
||||
case 'edit':
|
||||
return shifttype_edit_controller();
|
||||
case 'delete':
|
||||
return shifttype_delete_controller();
|
||||
case 'list':
|
||||
default:
|
||||
return shifttypes_list_controller();
|
||||
}
|
||||
return match ($action) {
|
||||
'view' => shifttype_controller(),
|
||||
'edit' => shifttype_edit_controller(),
|
||||
'delete' => shifttype_delete_controller(),
|
||||
'list' => shifttypes_list_controller(),
|
||||
default => shifttypes_list_controller(),
|
||||
};
|
||||
}
|
||||
|
|
|
@ -467,22 +467,13 @@ function user_angeltypes_controller(): array
|
|||
throw_redirect(page_link_to('angeltypes'));
|
||||
}
|
||||
|
||||
switch ($request->input('action')) {
|
||||
case 'delete_all':
|
||||
return user_angeltypes_delete_all_controller();
|
||||
case 'confirm_all':
|
||||
return user_angeltypes_confirm_all_controller();
|
||||
case 'confirm':
|
||||
return user_angeltype_confirm_controller();
|
||||
case 'delete':
|
||||
return user_angeltype_delete_controller();
|
||||
case 'update':
|
||||
return user_angeltype_update_controller();
|
||||
case 'add':
|
||||
return user_angeltype_add_controller();
|
||||
default:
|
||||
throw_redirect(page_link_to('angeltypes'));
|
||||
}
|
||||
|
||||
return ['', ''];
|
||||
return match ($request->input('action')) {
|
||||
'delete_all' => user_angeltypes_delete_all_controller(),
|
||||
'confirm_all' => user_angeltypes_confirm_all_controller(),
|
||||
'confirm' => user_angeltype_confirm_controller(),
|
||||
'delete' => user_angeltype_delete_controller(),
|
||||
'update' => user_angeltype_update_controller(),
|
||||
'add' => user_angeltype_add_controller(),
|
||||
default => throw_redirect(page_link_to('angeltyps')),
|
||||
};
|
||||
}
|
||||
|
|
|
@ -45,11 +45,10 @@ function user_driver_licenses_controller()
|
|||
|
||||
$action = strip_request_item('action', 'edit');
|
||||
|
||||
switch ($action) {
|
||||
default:
|
||||
case 'edit':
|
||||
return user_driver_license_edit_controller();
|
||||
}
|
||||
return match ($action) {
|
||||
'edit' => user_driver_license_edit_controller(),
|
||||
default => user_driver_license_edit_controller(),
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -27,17 +27,13 @@ function users_controller()
|
|||
$action = $request->input('action');
|
||||
}
|
||||
|
||||
switch ($action) {
|
||||
case 'view':
|
||||
return user_controller();
|
||||
case 'delete':
|
||||
return user_delete_controller();
|
||||
case 'edit_vouchers':
|
||||
return user_edit_vouchers_controller();
|
||||
case 'list':
|
||||
default:
|
||||
return users_list_controller();
|
||||
}
|
||||
return match ($action) {
|
||||
'view' => user_controller(),
|
||||
'delete' => user_delete_controller(),
|
||||
'edit_vouchers' => user_edit_vouchers_controller(),
|
||||
'list' => users_list_controller(),
|
||||
default => users_list_controller(),
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -87,29 +87,14 @@ class ShiftSignupState
|
|||
*/
|
||||
private function valueForState($state)
|
||||
{
|
||||
switch ($state) {
|
||||
case ShiftSignupState::NOT_ARRIVED:
|
||||
case ShiftSignupState::NOT_YET:
|
||||
case ShiftSignupState::SHIFT_ENDED:
|
||||
return 100;
|
||||
|
||||
case ShiftSignupState::SIGNED_UP:
|
||||
return 90;
|
||||
|
||||
case ShiftSignupState::FREE:
|
||||
return 80;
|
||||
|
||||
case ShiftSignupState::ANGELTYPE:
|
||||
case ShiftSignupState::COLLIDES:
|
||||
return 70;
|
||||
|
||||
case ShiftSignupState::OCCUPIED:
|
||||
case ShiftSignupState::ADMIN:
|
||||
return 60;
|
||||
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
return match ($state) {
|
||||
ShiftSignupState::NOT_ARRIVED, ShiftSignupState::NOT_YET, ShiftSignupState::SHIFT_ENDED => 100,
|
||||
ShiftSignupState::SIGNED_UP => 90,
|
||||
ShiftSignupState::FREE => 80,
|
||||
ShiftSignupState::ANGELTYPE, ShiftSignupState::COLLIDES => 70,
|
||||
ShiftSignupState::OCCUPIED, ShiftSignupState::ADMIN => 60,
|
||||
default => 0,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -119,13 +104,10 @@ class ShiftSignupState
|
|||
*/
|
||||
public function isSignupAllowed()
|
||||
{
|
||||
switch ($this->state) {
|
||||
case ShiftSignupState::FREE:
|
||||
case ShiftSignupState::ADMIN:
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
return match ($this->state) {
|
||||
ShiftSignupState::FREE, ShiftSignupState::ADMIN => true,
|
||||
default => false,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -71,28 +71,14 @@ class ShiftCalendarShiftRenderer
|
|||
*/
|
||||
private function classForSignupState(ShiftSignupState $shiftSignupState)
|
||||
{
|
||||
switch ($shiftSignupState->getState()) {
|
||||
case ShiftSignupState::ADMIN:
|
||||
case ShiftSignupState::OCCUPIED:
|
||||
return 'success';
|
||||
|
||||
case ShiftSignupState::SIGNED_UP:
|
||||
return 'primary';
|
||||
|
||||
case ShiftSignupState::NOT_ARRIVED:
|
||||
case ShiftSignupState::NOT_YET:
|
||||
case ShiftSignupState::SHIFT_ENDED:
|
||||
return 'secondary';
|
||||
|
||||
case ShiftSignupState::ANGELTYPE:
|
||||
case ShiftSignupState::COLLIDES:
|
||||
return 'warning';
|
||||
|
||||
case ShiftSignupState::FREE:
|
||||
return 'danger';
|
||||
default:
|
||||
return 'light';
|
||||
}
|
||||
return match ($shiftSignupState->getState()) {
|
||||
ShiftSignupState::ADMIN, ShiftSignupState::OCCUPIED => 'success',
|
||||
ShiftSignupState::SIGNED_UP => 'primary',
|
||||
ShiftSignupState::NOT_ARRIVED, ShiftSignupState::NOT_YET, ShiftSignupState::SHIFT_ENDED => 'secondary',
|
||||
ShiftSignupState::ANGELTYPE, ShiftSignupState::COLLIDES => 'warning',
|
||||
ShiftSignupState::FREE => 'danger',
|
||||
default => 'light',
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -90,24 +90,13 @@ class Stats
|
|||
|
||||
public function email(string $type): int
|
||||
{
|
||||
switch ($type) {
|
||||
case 'system':
|
||||
$query = Settings::whereEmailShiftinfo(true);
|
||||
break;
|
||||
case 'humans':
|
||||
$query = Settings::whereEmailHuman(true);
|
||||
break;
|
||||
case 'goody':
|
||||
$query = Settings::whereEmailGoody(true);
|
||||
break;
|
||||
case 'news':
|
||||
$query = Settings::whereEmailNews(true);
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
|
||||
return $query->count();
|
||||
return match ($type) {
|
||||
'system' => Settings::whereEmailShiftinfo(true)->count(),
|
||||
'humans' => Settings::whereEmailHuman(true)->count(),
|
||||
'goody' => Settings::whereEmailGoody(true)->count(),
|
||||
'news' => Settings::whereEmailNews(true)->count(),
|
||||
default => 0,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -50,26 +50,7 @@ class LegacyDevelopment extends Legacy
|
|||
|
||||
$args = [];
|
||||
foreach (($trace['args'] ?? []) as $arg) {
|
||||
// @codeCoverageIgnoreStart
|
||||
switch (gettype($arg)) {
|
||||
case 'string':
|
||||
case 'integer':
|
||||
case 'double':
|
||||
$args[] = $arg;
|
||||
break;
|
||||
case 'boolean':
|
||||
$args[] = $arg ? 'true' : 'false';
|
||||
break;
|
||||
case 'object':
|
||||
$args[] = get_class($arg);
|
||||
break;
|
||||
case 'resource':
|
||||
$args[] = get_resource_type($arg);
|
||||
break;
|
||||
default:
|
||||
$args[] = gettype($arg);
|
||||
// @codeCoverageIgnoreEnd
|
||||
}
|
||||
$args[] = $this->getDisplayNameOfValue($arg);
|
||||
}
|
||||
|
||||
$return[] = [
|
||||
|
@ -80,4 +61,19 @@ class LegacyDevelopment extends Legacy
|
|||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $arg
|
||||
* @return string
|
||||
*/
|
||||
private function getDisplayNameOfValue(mixed $arg): string
|
||||
{
|
||||
return match (gettype($arg)) {
|
||||
'string', 'integer', 'double' => (string)$arg,
|
||||
'boolean' => $arg ? 'true' : 'false',
|
||||
'object' => get_class($arg),
|
||||
'resource' => get_resource_type($arg), // @codeCoverageIgnore
|
||||
default => gettype($arg),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -49,12 +49,10 @@ class SessionServiceProvider extends ServiceProvider
|
|||
$config = $this->app->get('config');
|
||||
$sessionConfig = $config->get('session');
|
||||
|
||||
$handler = null;
|
||||
switch ($sessionConfig['driver']) {
|
||||
case 'pdo':
|
||||
$handler = $this->app->make(DatabaseHandler::class);
|
||||
break;
|
||||
}
|
||||
$handler = match ($sessionConfig['driver']) {
|
||||
'pdo' => $this->app->make(DatabaseHandler::class),
|
||||
default => null,
|
||||
};
|
||||
|
||||
return $this->app->make(NativeSessionStorage::class, [
|
||||
'options' => [
|
||||
|
|
|
@ -46,17 +46,12 @@ class MailerServiceProvider extends ServiceProvider
|
|||
|
||||
protected function getTransport(?string $transport, array $config): TransportInterface
|
||||
{
|
||||
switch ($transport) {
|
||||
case 'log':
|
||||
return $this->app->make(LogTransport::class);
|
||||
case 'mail':
|
||||
case 'sendmail':
|
||||
return $this->app->make(SendmailTransport::class, ['command' => $config['sendmail'] ?? null]);
|
||||
case 'smtp':
|
||||
return $this->getSmtpTransport($config);
|
||||
default:
|
||||
return Transport::fromDsn($transport ?? '');
|
||||
}
|
||||
return match ($transport) {
|
||||
'log' => $this->app->make(LogTransport::class),
|
||||
'mail', 'sendmail' => $this->app->make(SendmailTransport::class, ['command' => $config['sendmail'] ?? null]),
|
||||
'smtp' => $this->getSmtpTransport($config),
|
||||
default => Transport::fromDsn($transport ?? ''),
|
||||
};
|
||||
}
|
||||
|
||||
protected function getSmtpTransport(array $config): SmtpTransport
|
||||
|
|
|
@ -51,12 +51,11 @@ class EventConfig extends BaseModel
|
|||
|
||||
/** @see \Illuminate\Database\Eloquent\Concerns\HasAttributes::castAttribute */
|
||||
if (!empty($value)) {
|
||||
switch ($this->getValueCast($this->name)) {
|
||||
case 'datetime_human':
|
||||
return Carbon::make($value);
|
||||
case 'datetime':
|
||||
return Carbon::createFromFormat(Carbon::ISO8601, $value);
|
||||
}
|
||||
return match ($this->getValueCast($this->name)) {
|
||||
'datetime_human' => Carbon::make($value),
|
||||
'datetime' => Carbon::createFromFormat(Carbon::ISO8601, $value),
|
||||
default => $value,
|
||||
};
|
||||
}
|
||||
|
||||
return $value;
|
||||
|
@ -70,16 +69,13 @@ class EventConfig extends BaseModel
|
|||
public function setValueAttribute(mixed $value): static
|
||||
{
|
||||
if (!empty($value)) {
|
||||
switch ($this->getValueCast($this->name)) {
|
||||
case 'datetime_human':
|
||||
$value = match ($this->getValueCast($this->name)) {
|
||||
/** @var Carbon $value */
|
||||
$value = $value->toDateTimeString('minute');
|
||||
break;
|
||||
case 'datetime':
|
||||
'datetime_human' => $value->toDateTimeString('minute'),
|
||||
/** @var Carbon $value */
|
||||
$value = $value->toIso8601String();
|
||||
break;
|
||||
}
|
||||
'datetime' => $value->toIso8601String(),
|
||||
default => $value,
|
||||
};
|
||||
}
|
||||
|
||||
$value = $this->castAttributeAsJson('value', $value);
|
||||
|
|
|
@ -11,8 +11,9 @@ use PHPUnit\Framework\TestCase;
|
|||
class LegacyDevelopmentTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @covers \Engelsystem\Exceptions\Handlers\LegacyDevelopment::formatStackTrace()
|
||||
* @covers \Engelsystem\Exceptions\Handlers\LegacyDevelopment::render()
|
||||
* @covers \Engelsystem\Exceptions\Handlers\LegacyDevelopment::formatStackTrace
|
||||
* @covers \Engelsystem\Exceptions\Handlers\LegacyDevelopment::render
|
||||
* @covers \Engelsystem\Exceptions\Handlers\LegacyDevelopment::getDisplayNameOfValue
|
||||
*/
|
||||
public function testRender(): void
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue