Qual: Precise typing for Societeaccount's fields property #28758
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.
Qual: Precise typing for Societeaccount's fields property
Better typing helps static analysis and fixes the message: PhanTypeMismatchArgumentInternal Argument 2 ($array) is $object->fields['site']['arrayofkeyval'] of type null but \array_key_exists() takes array
Discussion
$field is redefined in the child classes of CommonObject, but IMHO these assignments should be made in the constructor of the child classes, not by redefining the fields.
For 'fields', to enhance readability, there could be a class constant for the initialiser that is used in the constructor for initialisation.
As the typing in CommonObject is different from the types specified in the subclasses, phpstan complains about this difference in level 3. The solution is not to remove the specific typing from CommonObject, as phpstan will also "need" this more specific typing to avoid other false positives in it's higher verification levels. And the goal is to help the static tools detect bugs, not avoid that they highlight (potential) issues.