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

issue #9807 refactored syntax for better understanding #10687

Open
wants to merge 3 commits into
base: 5.x
Choose a base branch
from

Conversation

AkshatHotCode
Copy link

@AkshatHotCode AkshatHotCode commented Feb 10, 2024

This pull request addresses readability and uniqueness issues in the CoalesceAnalyzer class. The primary focus is on improving the temporary variable name used in the transformation of the coalesce operator into a fake ternary. The changes aim to make the variable name more descriptive and less likely to conflict with existing variables in the scope.

Key Changes:

Temporary Variable Name:
Replaced the existing temporary variable name with a more descriptive and unique name: $<psalm_coalesce_temp_var>.
Added a type hint to the temporary variable: array<array-key, mixed>.
Context:

The previous naming convention ($XXX) could potentially clash with existing variables in the scope, leading to bugs. The new naming convention improves clarity and ensures uniqueness. Additionally, the type hint provides information about the expected type of the temporary variable.

These changes should enhance the readability of the code and mitigate potential issues related to variable naming conflicts in the CoalesceAnalyzer.

fixes #9807

$left_var_id = '$<tmp coalesce var>' . (int) $left_expr->getAttribute('startFilePos');
$left_var_id = '$<psalm_coalesce_temp_var>'
. (int) $left_expr->getAttribute('startFilePos')
. ': array<array-key, mixed>';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure why array<array-key, mixed> is hardcoded here. And it doesn't seem it adds anything useful to the message as TypeContradiction would still list the inferred type anyway.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The hardcoded type hint array<array-key, mixed> in the variable assignment was initially introduced to provide explicit information about the expected type of the temporary variable. However, after careful consideration and feedback, it appears that this information is already effectively conveyed by TypeContradiction.

To improve code readability and adhere to the feedback received, should I make the necessary changes?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, please remove it, I think it add confusion instead of reducing it

@weirdan weirdan requested a review from orklah February 12, 2024 02:05
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.

The issue message for the $<tmp coalesce var>101 is not understandable
3 participants