From 76927ef412ea9534dc0939698593686f909e5c26 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Mon, 4 Nov 2024 00:50:07 +0100 Subject: [PATCH] Generators/Generator: minor tweak * Predefine the find/replace values as these don't change within the loop. * Only call `str_replace()` once with arrays for find/replace. --- src/Generators/Generator.php | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/Generators/Generator.php b/src/Generators/Generator.php index ab81baed76..873ac3f3fa 100644 --- a/src/Generators/Generator.php +++ b/src/Generators/Generator.php @@ -6,7 +6,9 @@ * in a standard. * * @author Greg Sherwood + * @author Juliette Reinders Folmer * @copyright 2006-2015 Squiz Pty Ltd (ABN 77 084 670 600) + * @copyright 2024 PHPCSStandards and contributors * @license https://github.com/PHPCSStandards/PHP_CodeSniffer/blob/master/licence.txt BSD Licence */ @@ -46,14 +48,18 @@ public function __construct(Ruleset $ruleset) { $this->ruleset = $ruleset; + $find = [ + DIRECTORY_SEPARATOR.'Sniffs'.DIRECTORY_SEPARATOR, + 'Sniff.php', + ]; + $replace = [ + DIRECTORY_SEPARATOR.'Docs'.DIRECTORY_SEPARATOR, + 'Standard.xml', + ]; + foreach ($ruleset->sniffs as $className => $sniffClass) { $file = Autoload::getLoadedFileName($className); - $docFile = str_replace( - DIRECTORY_SEPARATOR.'Sniffs'.DIRECTORY_SEPARATOR, - DIRECTORY_SEPARATOR.'Docs'.DIRECTORY_SEPARATOR, - $file - ); - $docFile = str_replace('Sniff.php', 'Standard.xml', $docFile); + $docFile = str_replace($find, $replace, $file); if (is_file($docFile) === true) { $this->docFiles[] = $docFile;