Skip to content

WP/AlternativeFunctions: fails to detect namespaced and class-based function/constant calls #2603

@rodrigoprimo

Description

@rodrigoprimo

The sniff WordPress.WP.AlternativeFunctions checks for function calls and constants in the first parameter of file_get_contents() without differentiating global and non-global function calls and constants. It also fails to differentiate between functions/constants, and class methods/class constants. This leads to false negatives in some cases.

All the examples below don't trigger the sniff, but they should:

file_get_contents(MyNamespace\WP_Upload_Dir()['path'] . 'subdir/file.inc');
file_get_contents(\MyNamespace\WP_Upload_Dir()['path'] . 'subdir/file.inc');
file_get_contents(namespace\WP_Upload_Dir()['path'] . 'subdir/file.inc');
file_get_contents(MyNamespace\ABSPATH . 'wp-admin/css/some-file.css');
file_get_contents(\MyNamespace\ABSPATH . 'wp-admin/css/some-file.css');
file_get_contents(namespace\ABSPATH . 'wp-admin/css/some-file.css');

file_get_contents(MyClass::wp_upload_dir() . 'subdir/file.inc');
file_get_contents($this->wp_upload_dir() . 'subdir/file.inc');
file_get_contents(MyClass::ABSPATH . 'subdir/file.inc');
file_get_contents($this->ABSPATH . 'subdir/file.inc');

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions