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

AbstractArrayAssignmentRestrictions: remove support for 'callback' #2291

Conversation

jrfnl
Copy link
Member

@jrfnl jrfnl commented Jul 4, 2023

👉🏻 [OPTIONAL/PROPOSAL]

The getGroups() method allows to pass a custom callback for any particular group, however, in practice that array key is never used as the callback() method (the default) is declared as abstract and therefore must be defined in a child class.

I propose to remove support for the callback array key from the abstract sniff.

Sniffs which extend this abstract can still use different logic for different groups by applying a switch to the $group parameter received in the callback(), along the lines of:

public function callback( $key, $val, $line, $group ) {
    switch( $group ) {
        case 'groupA':
            return $this->callback_for_group_A($key, val, $line);
        case 'groupB':
            return $this->callback_for_group_B($key, val, $line);
    }
}

I have verified that none of the sniffs published in public repos and which extend this abstract sniff currently use the 'callback' key.

Removing the support for the key is a breaking change, but one with low impact based on current usage of the abstract.

[OPTIONAL]

The `getGroups()` method allows to pass a custom callback for any particular group, however, in practice that array key is never used as the `callback()` method (the default) is declared as `abstract` and therefore **must** be defined in a child class.

I propose to remove support for the `callback` array key from the abstract sniff.

Sniffs which extend this abstract can still use different logic for different groups by applying a switch to the `$group` parameter received in the `callback()`, along the lines of:
```php
public function callback( $key, $val, $line, $group ) {
    switch( $group ) {
        case 'groupA':
            return $this->callback_for_group_A($key, val, $line);
        case 'groupB':
            return $this->callback_for_group_B($key, val, $line);
    }
}
```

I have verified that [none of the sniffs published in public repos and which extend this abstract sniff](https://sourcegraph.com/search?q=context:global+use+WordPressCS%5CWordPress%5CAbstractArrayAssignmentRestrictionsSniff&patternType=standard&case=yes&sm=0&groupBy=group) currently use the `'callback'` key.

Removing the support for the key is a breaking change, but one with low impact based on current usage of the abstract.
Copy link
Member

@GaryJones GaryJones left a comment

Choose a reason for hiding this comment

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

@GaryJones GaryJones merged commit c283772 into develop Jul 4, 2023
35 checks passed
@GaryJones GaryJones deleted the feature/abstractarrayassignmentrestrictions-remove-callback-option branch July 4, 2023 13:29
@jrfnl
Copy link
Member Author

jrfnl commented Jul 4, 2023

Eh.. okay...guess you all agreed with this proposal, even though it is a breaking change. 😁

@dingo-d
Copy link
Member

dingo-d commented Jul 4, 2023

The impact is low, so it's not going to cause any issues. Plus v3.0.0 is a major one, so BC breaks are allowed (and expected).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants