Skip to content

THRIFT-6005: Raise PHPStan level from 5 to 6 on PHP library#3484

Merged
sveneld merged 1 commit into
apache:masterfrom
sveneld:THRIFT-6005
May 15, 2026
Merged

THRIFT-6005: Raise PHPStan level from 5 to 6 on PHP library#3484
sveneld merged 1 commit into
apache:masterfrom
sveneld:THRIFT-6005

Conversation

@sveneld
Copy link
Copy Markdown
Contributor

@sveneld sveneld commented May 15, 2026

Step lib/php/phpstan.neon level from 5 to 6 and address every issue PHPStan surfaces along the way. Final phase of the umbrella ticket THRIFT-5960 PHP modernization (after THRIFT-6000 / THRIFT-6001 / THRIFT-6004).

Library typing fixes

  • TBinarySerializer::serialize(object $object): string
  • TBinarySerializer::deserialize(string $string_object, class-string $class_name, int $buffer_size = 8192): object
  • TServer::__construct(object $processor, …)
  • TSocket / TSSLSocket constructor: documented $debugHandler as callable|string|null via PHPDoc.
  • TSocketPool::__construct(array $hosts, int|array $ports, bool $persist, …) with list<string> / int|list<int> shape PHPDoc.
  • TJSONProtocol static array properties get a native array declaration plus @var element-type docblocks ($JSON_CHAR_TABLE, $ESCAPE_CHARS, $ESCAPE_CHAR_VALS).
  • TBase / TException internal helpers (readMap, readList, readStruct, writeMap, writeList, writeStruct, __construct, bridge ctor) gain @param array<…> shape documentation so PHPStan can reason about $spec / $vals / $var element types.

Bug fixes

  • TBase::__wakeup() previously round-tripped through $this->__construct(get_object_vars($this)). That call short-circuited inside the body (second parameter was null) but tripped strict-mode type checks under tighter array-shape PHPDoc. PHP restores object state automatically on unserialize, so the body is now empty with a comment.
  • ThriftClassLoader::findFileInApcu() now uses a clear two-step fetch-or-recompute pattern and narrows the return via is_string(), eliminating the unreachable else-arm flagged by PHPStan.

Baseline

Regex pattern updated for the four unreachable dead-code arms in TBase / TException writeMap that mirror Thrift IDL map<Struct, V> semantics PHP arrays cannot represent — phpstan now reports the type as array<int|string, mixed> instead of bare array.

Validation (Docker thrift-php-dev:local)

  • phpcs — 0 errors
  • phpstan (level 6) — 0 errors
  • phpunit Unit Suite — 637 tests, 0 failures
  • phpunit Integration Suite — 108 tests, 0 failures

Closes the typing trajectory started by THRIFT-5960.

  • Apache Jira ticket — THRIFT-6005
  • PR title follows the pattern "THRIFT-NNNN: …"
  • Squashed to a single commit
  • No behaviour changes: __wakeup no-op was already a no-op due to body short-circuit; findFileInApcu returns the same string/null contract; library API surface untouched.

Generated-by: Claude Opus 4.7

Client: php

Step lib/php/phpstan.neon level from 5 to 6 and address every issue
PHPStan surfaces along the way.

Library typing fixes
--------------------

* TBinarySerializer::serialize(object $object): string
* TBinarySerializer::deserialize(string $string_object, class-string
  $class_name, int $buffer_size = 8192): object
* TServer::__construct(object $processor, ...)
* TSocket / TSSLSocket __construct: documented $debugHandler as
  callable|string|null via PHPDoc.
* TSocketPool::__construct: tightened to (array $hosts, int|array
  $ports, bool $persist, ...) with list shape PHPDoc.
* TJSONProtocol static array properties get a native `array` declaration
  plus `@var` element-type docblocks.
* TBase / TException internal helpers — readMap, readList, readStruct,
  writeMap, writeList, writeStruct, __construct, plus TException bridge
  ctor — gain `@param array<...>` shape documentation so PHPStan can
  reason about $spec / $vals / $var element types.

Bug fixes
---------

* TBase::__wakeup() previously round-tripped through
  $this->__construct(get_object_vars($this)). That call short-circuited
  inside the body (second parameter was null) but tripped strict-mode
  type checks under tighter array-shape PHPDoc. PHP restores object
  state automatically on unserialize, so the body is now empty with a
  comment.
* ThriftClassLoader::findFileInApcu() now uses a clear two-step
  fetch-or-recompute pattern and narrows the return via is_string(),
  eliminating the unreachable else-arm flagged by PHPStan.

Baseline regex updated to match the new "expects array<int|string,
mixed>, int|string given" wording for the four unreachable dead-code
arms in TBase / TException writeMap that mirror Thrift IDL `map<Struct,
V>` semantics PHP arrays cannot represent.

Final phase of the umbrella THRIFT-5960 PHP modernization.

Generated-by: Claude Opus 4.7
@mergeable mergeable Bot added the php label May 15, 2026
@sveneld sveneld marked this pull request as ready for review May 15, 2026 16:46
@sveneld sveneld merged commit b11de4b into apache:master May 15, 2026
94 of 95 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