From 1b9f3861b06008ee6f7e52e88e77084bb586d747 Mon Sep 17 00:00:00 2001 From: Marc Ginesta Date: Wed, 6 Oct 2021 11:20:46 +0200 Subject: [PATCH] AC-1167: Update DiscouragedFunctionSniff with FilesystemDriverInterface functions --- .../Functions/DiscouragedFunctionSniff.php | 9 +++++++++ .../Functions/DiscouragedFunctionUnitTest.inc | 18 ++++++++++++++++++ .../Functions/DiscouragedFunctionUnitTest.php | 11 ++++++++++- 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/Magento2/Sniffs/Functions/DiscouragedFunctionSniff.php b/Magento2/Sniffs/Functions/DiscouragedFunctionSniff.php index e73e981a..4982f8cc 100644 --- a/Magento2/Sniffs/Functions/DiscouragedFunctionSniff.php +++ b/Magento2/Sniffs/Functions/DiscouragedFunctionSniff.php @@ -229,5 +229,14 @@ class DiscouragedFunctionSniff extends ForbiddenFunctionsSniff '^strval$' => '(string) construction', '^htmlspecialchars$' => '\Magento\Framework\Escaper->escapeHtml', '^getimagesize$' => 'getimagesizefromstring', + '^file_exists$' => 'Magento\Framework\Filesystem\DriverInterface::isExists()', + '^file_get_contents$' => 'Magento\Framework\Filesystem\DriverInterface::fileGetContents()', + '^file_put_contents$' => 'Magento\Framework\Filesystem\DriverInterface::filePutContents()', + '^fgetcsv$' => 'Magento\Framework\Filesystem\DriverInterface::fileGetCsv()', + '^fputcsv$' => 'Magento\Framework\Filesystem\DriverInterface::filePutCsv()', + '^ftell$' => 'Magento\Framework\Filesystem\DriverInterface::fileTell()', + '^fseek$' => 'Magento\Framework\Filesystem\DriverInterface::fileSeek()', + '^feof$' => 'Magento\Framework\Filesystem\DriverInterface::endOfFile()', + '^flock$' => 'Magento\Framework\Filesystem\DriverInterface::fileLock()', ]; } diff --git a/Magento2/Tests/Functions/DiscouragedFunctionUnitTest.inc b/Magento2/Tests/Functions/DiscouragedFunctionUnitTest.inc index 5abf6dd5..0302ff56 100644 --- a/Magento2/Tests/Functions/DiscouragedFunctionUnitTest.inc +++ b/Magento2/Tests/Functions/DiscouragedFunctionUnitTest.inc @@ -464,3 +464,21 @@ $str = chop($text, 'ttt'); md5($text); htmlspecialchars('text'); + +file_exists('./'); + +file_get_contents('file.txt'); + +file_put_contents($file, 'test'); + +fgetcsv($fp,'r'); + +fputcsv($fp, $fields); + +ftell($file); + +fseek($file, 0); + +feof($fp); + +flock($fp, LOCK_EX); diff --git a/Magento2/Tests/Functions/DiscouragedFunctionUnitTest.php b/Magento2/Tests/Functions/DiscouragedFunctionUnitTest.php index 983a87b6..2a30100e 100644 --- a/Magento2/Tests/Functions/DiscouragedFunctionUnitTest.php +++ b/Magento2/Tests/Functions/DiscouragedFunctionUnitTest.php @@ -246,7 +246,16 @@ public function getWarningList() 458 => 1, 460 => 1, 462 => 1, - 466 => 1 + 466 => 1, + 468 => 1, + 470 => 1, + 472 => 1, + 474 => 1, + 476 => 1, + 478 => 1, + 480 => 1, + 482 => 1, + 484 => 1 ]; } }