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

Closes #7123: Rules about get_subscribed_events #7124

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

Miraeld
Copy link
Contributor

@Miraeld Miraeld commented Nov 21, 2024

Description

Fixes #7123
Explain how this code impacts users.

Type of change

  • New feature (non-breaking change which adds functionality).
  • Bug fix (non-breaking change which fixes an issue).
  • Enhancement (non-breaking change which improves an existing functionality).
  • Breaking change (fix or feature that would cause existing functionality to not work as before).
  • Sub-task of #(issue number)
  • Release

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

  • I validated all the Acceptance Criteria. If possible, provide screenshots or videos.
  • I triggered all changed lines of code at least once without new errors/warnings/notices.
  • I implemented built-in tests to cover the new/changed code.

Code style

  • I wrote a self-explanatory code about what it does.
  • I protected entry points against unexpected inputs.
  • I did not introduce unnecessary complexity.
  • Output messages (errors, notices, logs) are explicit enough for users to understand the issue and are actionnable.

Additional Checks

  • In the case of complex code, I wrote comments to explain it.
  • When possible, I prepared ways to observe the implemented system (logs, data, etc.).
  • I added error handling logic when using functions that could throw errors (HTTP/API request, filesystem, etc.)

@Miraeld Miraeld self-assigned this Nov 21, 2024
@Miraeld Miraeld added the type: enhancement Improvements that slightly enhance existing functionality and are fast to implement label Nov 21, 2024
Copy link

codacy-production bot commented Nov 21, 2024

Coverage summary from Codacy

See diff coverage on Codacy

Coverage variation Diff coverage
Report missing for 4542d7b1 (target: 50.00%)
Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (4542d7b) Report Missing Report Missing Report Missing
Head commit (6da4cc4) 38228 16731 43.77%

Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: <coverage of head commit> - <coverage of common ancestor commit>

Diff coverage details
Coverable lines Covered lines Diff coverage
Pull request (#7124) 0 0 ∅ (not applicable)

Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: <covered lines added or modified>/<coverable lines added or modified> * 100%

See your quality gate settings    Change summary preferences

Codacy stopped sending the deprecated coverage status on June 5th, 2024. Learn more

Footnotes

  1. Codacy didn't receive coverage data for the commit, or there was an error processing the received data. Check your integration for errors and validate that your coverage setup is correct.


// Get the function/method name from the scope
$functionName = $scope->getFunctionName();
if ('get_subscribed_events' === $functionName) {
Copy link
Contributor

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_) {
Copy link
Contributor

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) {
Copy link
Contributor

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

Comment on lines +57 to +59
if ($methodValue instanceof Node\Scalar\String_) {
// Simple structure: array('hook_name' => 'method_name')
$errors = $this->checkIfMethodExistsInClass($methodValue->value, $scope, $methodValue);
Copy link
Contributor

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) {
Copy link
Contributor

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_) {
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement Improvements that slightly enhance existing functionality and are fast to implement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

PHPStan - Add Rule to ensure get_subscribed_events use one of the three possible syntax
2 participants