Skip to content

Commit

Permalink
Use match expressions in mapLegacyValues (#31)
Browse files Browse the repository at this point in the history
Co-authored-by: Jack Fletcher <[email protected]>
  • Loading branch information
kauhat and Jack Fletcher authored Sep 6, 2024
1 parent 6b67c14 commit 4560651
Show file tree
Hide file tree
Showing 27 changed files with 173 additions and 132 deletions.
5 changes: 4 additions & 1 deletion src/Google/Enumerators/BarcodeRenderEncoding.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ public static function values(): array

public function mapLegacyValues(string $value): string
{
return str_replace(['UTF_8'], [self::UTF_8], $value);
return match ($value) {
'UTF_8' => self::UTF_8,
default => $value,
};
}
}
51 changes: 18 additions & 33 deletions src/Google/Enumerators/BarcodeType.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,38 +66,23 @@ public static function values(): array

public function mapLegacyValues(string $value): string
{
return str_replace([
'aztec',
'code39',
'code128',
'codabar',
'dataMatrix',
'ean8',
'ean13',
'EAN13',
'itf14',
'pdf417',
'PDF417',
'qrCode',
'qrcode',
'upcA',
'textOnly',
], [
self::AZTEC,
self::CODE_39,
self::CODE_128,
self::CODABAR,
self::DATA_MATRIX,
self::EAN_8,
self::EAN_13,
self::EAN_13,
self::ITF_14,
self::PDF_417,
self::PDF_417,
self::QR_CODE,
self::QR_CODE,
self::UPC_A,
self::TEXT_ONLY,
], $value);
return match ($value) {
'aztec' => self::AZTEC,
'code39' => self::CODE_39,
'code128' => self::CODE_128,
'codabar' => self::CODABAR,
'dataMatrix' => self::DATA_MATRIX,
'ean8' => self::EAN_8,
'ean13' => self::EAN_13,
'EAN13' => self::EAN_13,
'itf14' => self::ITF_14,
'pdf417' => self::PDF_417,
'PDF417' => self::PDF_417,
'qrCode' => self::QR_CODE,
'qrcode' => self::QR_CODE,
'upcA' => self::UPC_A,
'textOnly' => self::TEXT_ONLY,
default => $value,
};
}
}
15 changes: 8 additions & 7 deletions src/Google/Enumerators/DateFormat.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,13 @@ public static function values(): array

public function mapLegacyValues(string $value): string
{
return str_replace([
'dateTime',
'dateOnly',
'timeOnly',
'dateTimeYear',
'dateYear',
], [self::DATE_TIME, self::DATE_ONLY, self::TIME_ONLY, self::DATE_TIME_YEAR, self::DATE_YEAR], $value);
return match ($value) {
'dateTime' => self::DATE_TIME,
'dateOnly' => self::DATE_ONLY,
'timeOnly' => self::TIME_ONLY,
'dateTimeYear' => self::DATE_TIME_YEAR,
'dateYear' => self::DATE_YEAR,
default => $value,
};
}
}
6 changes: 5 additions & 1 deletion src/Google/Enumerators/DoorsOpenLabel.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ public static function values(): array

public function mapLegacyValues(string $value): string
{
return str_replace(['doorsOpen', 'gatesOpen'], [self::DOORS_OPEN, self::GATES_OPEN], $value);
return match ($value) {
'doorsOpen' => self::DOORS_OPEN,
'gatesOpen' => self::GATES_OPEN,
default => $value,
};
}
}
13 changes: 7 additions & 6 deletions src/Google/Enumerators/EventTicket/ConfirmationCodeLabel.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,12 @@ public static function values(): array

public function mapLegacyValues(string $value): string
{
return str_replace(['confirmationCode', 'confirmationNumber', 'orderNumber', 'reservationNumber'], [
self::CONFIRMATION_CODE,
self::CONFIRMATION_NUMBER,
self::ORDER_NUMBER,
self::RESERVATION_NUMBER,
], $value);
return match ($value) {
'confirmationCode' => self::CONFIRMATION_CODE,
'confirmationNumber' => self::CONFIRMATION_NUMBER,
'orderNumber' => self::ORDER_NUMBER,
'reservationNumber' => self::RESERVATION_NUMBER,
default => $value,
};
}
}
7 changes: 6 additions & 1 deletion src/Google/Enumerators/EventTicket/GateLabel.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ public static function values(): array

public function mapLegacyValues(string $value): string
{
return str_replace(['gate', 'door', 'entrance'], [self::GATE, self::DOOR, self::ENTRANCE], $value);
return match ($value) {
'gate' => self::GATE,
'door' => self::DOOR,
'entrance' => self::ENTRANCE,
default => $value,
};
}
}
5 changes: 4 additions & 1 deletion src/Google/Enumerators/EventTicket/RowLabel.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ public static function values(): array

public function mapLegacyValues(string $value): string
{
return str_replace(['row'], [self::ROW], $value);
return match ($value) {
'row' => self::ROW,
default => $value,
};
}
}
5 changes: 4 additions & 1 deletion src/Google/Enumerators/EventTicket/SeatLabel.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ public static function values(): array

public function mapLegacyValues(string $value): string
{
return str_replace(['seat'], [self::SEAT], $value);
return match ($value) {
'seat' => self::SEAT,
default => $value,
};
}
}
6 changes: 5 additions & 1 deletion src/Google/Enumerators/EventTicket/SectionLabel.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ public static function values(): array

public function mapLegacyValues(string $value): string
{
return str_replace(['section', 'theater'], [self::SECTION, self::THEATER], $value);
return match ($value) {
'section' => self::SECTION,
'theater' => self::THEATER,
default => $value,
};
}
}
6 changes: 5 additions & 1 deletion src/Google/Enumerators/Flight/BoardingDoor.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ public static function values(): array

public function mapLegacyValues(string $value): string
{
return str_replace(['front', 'back'], [self::FRONT, self::BACK], $value);
return match ($value) {
'front' => self::FRONT,
'back' => self::BACK,
default => $value,
};
}
}
11 changes: 6 additions & 5 deletions src/Google/Enumerators/Flight/BoardingPolicy.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@ public static function values(): array

public function mapLegacyValues(string $value): string
{
return str_replace([
'zoneBased',
'groupBased',
'boardingPolicyOther',
], [self::ZONE_BASED, self::GROUP_BASED, self::BOARDING_POLICY_OTHER], $value);
return match ($value) {
'zoneBased' => self::ZONE_BASED,
'groupBased' => self::GROUP_BASED,
'boardingPolicyOther' => self::BOARDING_POLICY_OTHER,
default => $value,
};
}
}
17 changes: 9 additions & 8 deletions src/Google/Enumerators/Flight/FlightStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,14 @@ public static function values(): array

public function mapLegacyValues(string $value): string
{
return str_replace(['scheduled', 'active', 'landed', 'cancelled', 'redirected', 'diverted'], [
self::SCHEDULED,
self::ACTIVE,
self::LANDED,
self::CANCELLED,
self::REDIRECTED,
self::DIVERTED,
], $value);
return match ($value) {
'scheduled' => self::SCHEDULED,
'active' => self::ACTIVE,
'landed' => self::LANDED,
'cancelled' => self::CANCELLED,
'redirected' => self::REDIRECTED,
'diverted' => self::DIVERTED,
default => $value,
};
}
}
13 changes: 7 additions & 6 deletions src/Google/Enumerators/Flight/SeatClassPolicy.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,12 @@ public static function values(): array

public function mapLegacyValues(string $value): string
{
return str_replace([
'cabinBased',
'classBased',
'tierBased',
'seatClassPolicyOther',
], [self::CABIN_BASED, self::CLASS_BASED, self::TIER_BASED, self::SEAT_CLASS_POLICY_OTHER], $value);
return match ($value) {
'cabinBased' => self::CABIN_BASED,
'classBased' => self::CLASS_BASED,
'tierBased' => self::TIER_BASED,
'seatClassPolicyOther' => self::SEAT_CLASS_POLICY_OTHER,
default => $value,
};
}
}
11 changes: 6 additions & 5 deletions src/Google/Enumerators/Loyalty/VisibilityState.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ public static function values(): array

public function mapLegacyValues(string $value): string
{
return str_replace([
'trustedTesters',
'live',
'disabled',
], [self::TRUSTED_TESTERS, self::LIVE, self::DISABLED], $value);
return match ($value) {
'trustedTesters' => self::TRUSTED_TESTERS,
'live' => self::LIVE,
'disabled' => self::DISABLED,
default => $value,
};
}
}
9 changes: 5 additions & 4 deletions src/Google/Enumerators/MessageType.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ public static function values(): array

public function mapLegacyValues(string $value): string
{
return str_replace([
'text',
'expirationNotification',
], [self::TEXT, self::EXPIRATION_NOTIFICATION], $value);
return match ($value) {
'text' => self::TEXT,
'expirationNotification' => self::EXPIRATION_NOTIFICATION,
default => $value,
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@ public static function values(): array

public function mapLegacyValues(string $value): string
{
return str_replace([
'multipleHolders',
'oneUserAllDevices',
'oneUserOneDevice',
], [self::MULTIPLE_HOLDERS, self::ONE_USER_ALL_DEVICES, self::ONE_USER_ONE_DEVICE], $value);
return match ($value) {
'multipleHolders' => self::MULTIPLE_HOLDERS,
'oneUserAllDevices' => self::ONE_USER_ALL_DEVICES,
'oneUserOneDevice' => self::ONE_USER_ONE_DEVICE,
default => $value,
};
}
}
13 changes: 7 additions & 6 deletions src/Google/Enumerators/Offer/RedemptionChannel.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,12 @@ public static function values(): array

public function mapLegacyValues(string $value): string
{
return str_replace([
'instore',
'online',
'both',
'temporaryPriceReduction',
], [self::INSTORE, self::ONLINE, self::BOTH, self::TEMPORARY_PRICE_REDUCTION], $value);
return match ($value) {
'instore' => self::INSTORE,
'online' => self::ONLINE,
'both' => self::BOTH,
'temporaryPriceReduction' => self::TEMPORARY_PRICE_REDUCTION,
default => $value,
};
}
}
9 changes: 5 additions & 4 deletions src/Google/Enumerators/PredefinedItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ public static function values(): array

public function mapLegacyValues(string $value): string
{
return str_replace(['frequentFlyerProgramNameAndNumber', 'flightNumberAndOperatingFlightNumber'], [
self::FREQUENT_FLYER_PROGRAM_NAME_AND_NUMBER,
self::FLIGHT_NUMBER_AND_OPERATING_FLIGHT_NUMBER,
], $value);
return match ($value) {
'frequentFlyerProgramNameAndNumber' => self::FREQUENT_FLYER_PROGRAM_NAME_AND_NUMBER,
'flightNumberAndOperatingFlightNumber' => self::FLIGHT_NUMBER_AND_OPERATING_FLIGHT_NUMBER,
default => $value,
};
}
}
13 changes: 7 additions & 6 deletions src/Google/Enumerators/ReviewStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,12 @@ public static function values(): array

public function mapLegacyValues(string $value): string
{
return str_replace([
'underReview',
'approved',
'rejected',
'draft',
], [self::UNDER_REVIEW, self::APPROVED, self::REJECTED, self::DRAFT], $value);
return match ($value) {
'underReview' => self::UNDER_REVIEW,
'approved' => self::APPROVED,
'rejected' => self::REJECTED,
'draft' => self::DRAFT,
default => $value,
};
}
}
13 changes: 7 additions & 6 deletions src/Google/Enumerators/State.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,12 @@ public static function values(): array

public function mapLegacyValues(string $value): string
{
return str_replace([
'active',
'completed',
'expired',
'inactive',
], [self::ACTIVE, self::COMPLETED, self::EXPIRED, self::INACTIVE], $value);
return match ($value) {
'active' => self::ACTIVE,
'completed' => self::COMPLETED,
'expired' => self::EXPIRED,
'inactive' => self::INACTIVE,
default => $value,
};
}
}
7 changes: 6 additions & 1 deletion src/Google/Enumerators/Transit/ConcessionCategory.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ public static function values(): array

public function mapLegacyValues(string $value): string
{
return str_replace(['adult', 'child', 'senior'], [self::ADULT, self::CHILD, self::SENIOR], $value);
return match ($value) {
'adult' => self::ADULT,
'child' => self::CHILD,
'senior' => self::SENIOR,
default => $value,
};
}
}
7 changes: 6 additions & 1 deletion src/Google/Enumerators/Transit/FareClass.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ public static function values(): array

public function mapLegacyValues(string $value): string
{
return str_replace(['economy', 'first', 'business'], [self::ECONOMY, self::FIRST, self::BUSINESS], $value);
return match ($value) {
'economy' => self::ECONOMY,
'first' => self::FIRST,
'business' => self::BUSINESS,
default => $value,
};
}
}
9 changes: 5 additions & 4 deletions src/Google/Enumerators/Transit/PassengerType.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ public static function values(): array

public function mapLegacyValues(string $value): string
{
return str_replace([
'singlePassenger',
'multiplePassengers',
], [self::SINGLE_PASSENGER, self::MULTIPLE_PASSENGERS], $value);
return match ($value) {
'singlePassenger' => self::SINGLE_PASSENGER,
'multiplePassengers' => self::MULTIPLE_PASSENGERS,
default => $value,
};
}
}
Loading

0 comments on commit 4560651

Please sign in to comment.