Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Qual: Precise typing for Societeaccount's fields property #28758

Conversation

mdeweerd
Copy link
Contributor

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.

@mdeweerd mdeweerd marked this pull request as ready for review March 11, 2024 10:21
@mdeweerd mdeweerd force-pushed the fix/websiteaccount/PhanTypeMismatchArgumentInternal branch from 0fd9e93 to bf1408c Compare March 11, 2024 12:16
# 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
@mdeweerd mdeweerd force-pushed the fix/websiteaccount/PhanTypeMismatchArgumentInternal branch from bf1408c to 51638dd Compare March 11, 2024 12:41
@eldy eldy merged commit bb64871 into Dolibarr:develop Mar 11, 2024
4 of 5 checks passed
@mdeweerd mdeweerd deleted the fix/websiteaccount/PhanTypeMismatchArgumentInternal branch March 11, 2024 15:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants