build: analyse with PHPStan 2 - #10
Draft
galatanovidiu wants to merge 1 commit into
Draft
Conversation
`phpstan/phpstan` moves to `^2.0`. `level: max` is level 10 there, and `src/` analyses clean at it. `asStringArray()` narrows each element before converting it: scalars and null convert directly, an object declaring `__toString()` converts through it, and anything else raises `InvalidArgumentException`. Arrays and objects without `__toString()` therefore no longer reach a string cast. That is the one behavior change; every value that already converted cleanly converts to the same string as before. Hydration of DTO arrays passes each element through `self::asArray()`, which asserts `array<string, mixed>` and so satisfies the `fromArray()` parameter. The single-DTO hydration paths take the same route. `treatPhpDocTypesAsCertain` is off. PHPDoc types on untyped PHP 7.4 properties describe the wire contract, not the runtime value: serialization accepts an already-serialized array where the PHPDoc names a DTO union, so the checks guarding that are reachable.
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.
Raises the PHPStan dev dependency to
^2.0.level: maxis level 10 there, andsrc/analyses clean at it.How it works
Three adjustments cover the stricter rules.
asStringArray()narrows each element before converting it. Scalars and null convert directly, an object declaring__toString()converts through it, and anything else raisesInvalidArgumentException. Nothing reaches a cast frommixed.Hydration of DTO arrays passes each element through
self::asArray(), which assertsarray<string, mixed>and so satisfies thefromArray()parameter. The single-DTO hydration paths take the same route.treatPhpDocTypesAsCertainis off. PHPDoc types on untyped PHP 7.4 properties describe the wire contract, not the runtime value: serialization accepts an already-serialized array where the PHPDoc names a DTO union, so the checks guarding that are reachable.Compatibility
PHPStan 2 runs on PHP 7.4 and 8.x, so the CI matrix is unchanged.
asStringArray()carries the one behavior change. Every value that converts cleanly keeps its result:['a', 'b']['a', 'b'][1, 2]['1', '2'][1.5]['1.5'][true, false]['1', ''][null]['']__toString()[[1, 2]],[new stdClass()]InvalidArgumentExceptionThe last row is the change: an array or an object with no
__toString()is rejected rather than converted.Note for reviewers
src/is generator output. The generator change and the regenerated PHP are committed together so a cleannpm run generatereproduces the tree.This branch and
#9overlap on 10 generated files and on bothgenerator/src/generators/dto.tsandgenerator/src/writers/index.ts, so the ordering is worth stating. A trial merge of the two runs clean, a freshnpm run generatefrom the merged generator reproduces the merged tree byte for byte, andcomposer analyseis clean on the combined result. Either can land first.