Skip to content

THRIFT-5983: Replace switch with match in PHP TProtocol::skip / skipBinary#3463

Merged
sveneld merged 1 commit into
apache:masterfrom
sveneld:THRIFT-5983
May 12, 2026
Merged

THRIFT-5983: Replace switch with match in PHP TProtocol::skip / skipBinary#3463
sveneld merged 1 commit into
apache:masterfrom
sveneld:THRIFT-5983

Conversation

@sveneld
Copy link
Copy Markdown
Contributor

@sveneld sveneld commented May 12, 2026

Refactor both type dispatchers in lib/php/lib/Protocol/TProtocol.php from switch to match expressions.

Why match:

  • Strict comparison (===) instead of loose equality.
  • No fall-through hazard — every arm is bounded.
  • Direct return of arm value — eliminates per-case return boilerplate.

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 errors
  • phpstan (level 1) — 0 errors
  • phpunit Unit Suite — 635 tests, 0 failures
  • phpunit Integration Suite — 108 tests, 0 failures

Part of the umbrella ticket THRIFT-5960 (PHP language modernization).

  • Did you create an Apache Jira ticket? — THRIFT-5983
  • PR title follows the pattern "THRIFT-NNNN: describe my issue"
  • Squashed to a single commit
  • No breaking changes (internal refactor, public API preserved)

Generated-by: Claude Opus 4.7

@mergeable mergeable Bot added the php label May 12, 2026
…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
@sveneld sveneld marked this pull request as ready for review May 12, 2026 18:27
@sveneld sveneld merged commit 9531544 into apache:master May 12, 2026
93 of 94 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant