THRIFT-5983: Replace switch with match in PHP TProtocol::skip / skipBinary#3463
Merged
Conversation
…inary Client: php Convert both type dispatchers in lib/php/lib/Protocol/TProtocol.php from switch to match expressions: - skip() — match over TType constants, delegating compound types (STRUCT/MAP/SET/LIST) to dedicated private helpers since match arms must be single expressions. - skipBinary() — same pattern; merges arms with identical fixed-byte sizes (BOOL/BYTE, I64/DOUBLE, SET/LST) for compactness. Match expressions use strict comparison (===), forbid fall-through, and return values directly — eliminating the manual `return` boilerplate. Behavior is preserved; existing TProtocolException for unknown types remains as the default arm. Generated-by: Claude Opus 4.7
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Refactor both type dispatchers in
lib/php/lib/Protocol/TProtocol.phpfromswitchtomatchexpressions.Why match:
===) instead of loose equality.returnboilerplate.Structural changes:
skip()— match arms delegate compound type handling (STRUCT/MAP/SET/LIST) to private helper methods since match arms accept only single expressions, not procedural blocks.skipBinary()— same pattern; arms with identical fixed-byte sizes are merged (BOOL/BYTE,I64/DOUBLE,SET/LST).Behavior is preserved. The default arm still throws
TProtocolException, matching the original API contract.Validation (Docker
thrift-php-dev:local):phpcs— 0 errorsphpstan(level 1) — 0 errorsphpunitUnit Suite — 635 tests, 0 failuresphpunitIntegration Suite — 108 tests, 0 failuresPart of the umbrella ticket THRIFT-5960 (PHP language modernization).
Generated-by: Claude Opus 4.7