WordPress / performance

Performance plugin from the WordPress Performance Group, which is a collection of standalone performance modules.
https://wordpress.org/plugins/performance-lab/
GNU General Public License v2.0
347 stars 94 forks source link

Add checks to disallow use of isset( $var ) and empty() #1219

Open westonruter opened 3 months ago

westonruter commented 3 months ago

Feature Description

The use of empty() and isset( $var ) can mask code problems (e.g. typos). And they rarely need to be used, for example:

cf. comment by @felixarntz in https://github.com/WordPress/performance/pull/1091#discussion_r1543908524

We should consider adding sniffs to warn against their use. (Granted, PHPStan should catch the problematic uses of isset() and empty().)

swissspidy commented 3 months ago

https://github.com/phpstan/phpstan-strict-rules Is your friend.

Works like a charm

westonruter commented 3 months ago

But I said we were done with PHPStan PRs 😂

felixarntz commented 2 weeks ago

Per https://github.com/WordPress/performance/pull/1489#discussion_r1725404800, let's change this issue to be only about empty() - or, if we want to include isset(), it should only be prevented on variable checks like isset( $something ), but not on e.g. array key or object property checks like isset( $arr['something'] ).