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

Updated - WP.AlternativeFunctions: Add more functions to filesystem functions list #2108

Merged
merged 15 commits into from
Dec 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 29 additions & 2 deletions WordPress/Sniffs/WP/AlternativeFunctionsSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,37 @@ public function getGroups() {
),
),

'file_system_read' => array(
'unlink' => array(
'type' => 'warning',
'message' => 'File operations should use WP_Filesystem methods instead of direct PHP filesystem calls. Found: %s()',
'message' => '%s() is discouraged. Use wp_delete_file() to delete a file.',
'since' => '4.2.0',
'functions' => array(
'unlink',
),
),

'rename' => array(
'type' => 'warning',
'message' => '%s() is discouraged. Use WP_Filesystem::move() to rename a file.',
'since' => '2.5.0',
'functions' => array(
'rename',
),
),

'file_system_operations' => array(
'type' => 'warning',
'message' => 'File operations should use WP_Filesystem methods instead of direct PHP filesystem calls. Found: %s().',
'since' => '2.5.0',
'functions' => array(
'chgrp',
'chmod',
'chown',
'is_writable',
'is_writeable',
'mkdir',
'rmdir',
'touch',
GaryJones marked this conversation as resolved.
Show resolved Hide resolved
'readfile',
'fclose',
'fopen',
Expand All @@ -139,6 +165,7 @@ public function getGroups() {
'file_put_contents',
'fsockopen',
'pfsockopen',
'fputs',
),
),

Expand Down
12 changes: 12 additions & 0 deletions WordPress/Tests/WP/AlternativeFunctionsUnitTest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,15 @@ function curl_version_ssl() {} // OK.
use function curl_version; // OK.
use function something as curl_version; // OK.
use function curl_init as curl_version; // Bad.

unlink(); // Warning.
rename(); // Warning.
chgrp(); // Warning.
chmod(); // Warning.
chown(); // Warning.
is_writable(); // Warning.
is_writeable(); // Warning.
mkdir(); // Warning.
rmdir(); // Warning.
touch(); // Warning.
fputs(); // Warning.
11 changes: 11 additions & 0 deletions WordPress/Tests/WP/AlternativeFunctionsUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,17 @@ public function getWarningList() {
68 => 1,
73 => 1,
80 => 1,
82 => 1,
83 => 1,
84 => 1,
85 => 1,
86 => 1,
87 => 1,
88 => 1,
89 => 1,
90 => 1,
91 => 1,
92 => 1,
);
}

Expand Down