squizlabs / PHP_CodeSniffer

PHP_CodeSniffer tokenizes PHP files and detects violations of a defined set of coding standards.
BSD 3-Clause "New" or "Revised" License
10.67k stars 1.48k forks source link

Generic/LowerCaseType: fix potential PHP notice #3833

Closed jrfnl closed 11 months ago

jrfnl commented 1 year ago

Description

The Generic.PHP.LowerCaseType sniff calls the File::getMemberProperties() method to get information about potential properties.

That method throws an exception when the T_VARIABLE token passed is not a property, but will create an Internal.ParseError.InterfaceHasMemberVar warning and return an empty array when the T_VARIABLE passed is an illegal property, i.e. a property in a context in which it is not allowed (interface/enum).

As things were, the sniff did not take a potential return value of an empty array into account, which could result in an Undefined array key "type" PHP notice.

Fixed now.

Includes unit test.

Suggested changelog entry

Generic.PHP.LowerCaseType: fixed potential undefined array index notice

Related issues/external references

N/A

Types of changes

jrfnl commented 1 year ago

This PR will conflict with PR #3662 and either one of them will need rebasing if the other gets merged first.

jrfnl commented 11 months ago

Closing as replaced by https://github.com/PHPCSStandards/PHP_CodeSniffer/pull/62

jrfnl commented 10 months ago

FYI: this fix is included in today's PHP_CodeSniffer 3.8.0 release.

As per #3932, development on PHP_CodeSniffer will continue in the PHPCSStandards/PHP_CodeSniffer repository. If you want to stay informed, you may want to start "watching" that repo (or watching releases from that repo).