THRIFT-6005: Raise PHPStan level from 5 to 6 on PHP library#3484
Merged
Conversation
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
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.
Step
lib/php/phpstan.neonlevel 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): stringTBinarySerializer::deserialize(string $string_object, class-string $class_name, int $buffer_size = 8192): objectTServer::__construct(object $processor, …)TSocket/TSSLSocketconstructor: documented$debugHandlerascallable|string|nullvia PHPDoc.TSocketPool::__construct(array $hosts, int|array $ports, bool $persist, …)withlist<string>/int|list<int>shape PHPDoc.TJSONProtocolstatic array properties get a nativearraydeclaration plus@varelement-type docblocks ($JSON_CHAR_TABLE,$ESCAPE_CHARS,$ESCAPE_CHAR_VALS).TBase/TExceptioninternal helpers (readMap,readList,readStruct,writeMap,writeList,writeStruct,__construct, bridge ctor) gain@param array<…>shape documentation so PHPStan can reason about$spec/$vals/$varelement 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 onunserialize, 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 viais_string(), eliminating the unreachable else-arm flagged by PHPStan.Baseline
Regex pattern updated for the four unreachable dead-code arms in TBase / TException
writeMapthat mirror Thrift IDLmap<Struct, V>semantics PHP arrays cannot represent — phpstan now reports the type asarray<int|string, mixed>instead of barearray.Validation (Docker
thrift-php-dev:local)phpcs— 0 errorsphpstan(level 6) — 0 errorsphpunitUnit Suite — 637 tests, 0 failuresphpunitIntegration Suite — 108 tests, 0 failuresCloses the typing trajectory started by THRIFT-5960.
__wakeupno-op was already a no-op due to body short-circuit;findFileInApcureturns the same string/null contract; library API surface untouched.Generated-by: Claude Opus 4.7