PHPCompatibility / PHPModernizer

External PHPCS standard with auto-fixers to modernize legacy codebases
GNU Lesser General Public License v3.0
10 stars 0 forks source link

New sniff: change dirname( __FILE__ ) to __DIR__ #2

Open jrfnl opened 6 years ago

jrfnl commented 6 years ago
Sniff basics -
Fixable for PHP: 5.3+
Sniff type: Modernize
Fixer type: Safe

Short description

PHP 5.3 introduced the magic constant __DIR__ which is equivalent to dirname( __FILE__ ) and more efficient to use - function call vs native PHP (magic) constant -.

Related PHPCompatibility sniff(s):

PHP manual references:

Example code:

Detect the following code pattern(s):

dirname( __FILE__ );

And fix these to:

__DIR__

Notes for implementation of the sniff:

Prior art: