-
Notifications
You must be signed in to change notification settings - Fork 219
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
Closes #7123: Rules about get_subscribed_events #7124
base: develop
Are you sure you want to change the base?
Closes #7123: Rules about get_subscribed_events #7124
Conversation
Coverage summary from CodacySee diff coverage on Codacy
Coverage variation details
Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: Diff coverage details
Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: See your quality gate settings Change summary preferencesCodacy stopped sending the deprecated coverage status on June 5th, 2024. Learn more Footnotes
|
|
||
// Get the function/method name from the scope | ||
$functionName = $scope->getFunctionName(); | ||
if ('get_subscribed_events' === $functionName) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Miraeld two things:
- It would be better to bail out here to keep the logic simple.
- We also need to check that we extend from the interface
Subscriber_Interface
to prevent side effects
$functionName = $scope->getFunctionName(); | ||
if ('get_subscribed_events' === $functionName) { | ||
// Check if the return expression is an array | ||
if ($node->expr instanceof Node\Expr\Array_) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to bail out here too
// Check if the return expression is an array | ||
if ($node->expr instanceof Node\Expr\Array_) { | ||
foreach ($node->expr->items as $item) { | ||
if ($item instanceof Node\Expr\ArrayItem) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here with a continue
if ($methodValue instanceof Node\Scalar\String_) { | ||
// Simple structure: array('hook_name' => 'method_name') | ||
$errors = $this->checkIfMethodExistsInClass($methodValue->value, $scope, $methodValue); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can bail out here
} elseif ($methodValue instanceof Node\Expr\Array_) { | ||
// More complex structures: array or nested array | ||
foreach ($methodValue->items as $subItem) { | ||
if ($subItem instanceof Node\Expr\ArrayItem) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here, we can bail out
// More complex structures: array or nested array | ||
foreach ($methodValue->items as $subItem) { | ||
if ($subItem instanceof Node\Expr\ArrayItem) { | ||
if ($subItem->value instanceof Node\Scalar\String_) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and same here with continue
Description
Fixes #7123
Explain how this code impacts users.
Type of change
Detailed scenario
Explain how to reproduce the issue (for bugs) or how to trigger the new code. You can refer to the GitHub issue or grooming if it is still applicable.
Technical description
Documentation
Explain how this code works. Diagrams & drawings are welcome.
New dependencies
List any new dependencies that are required for this change.
Risks
List possible performance & security issues or risks, and explain how they have been mitigated.
Mandatory Checklist
Code validation
Code style
Additional Checks