From bb906ff8c4a1218abb030eab19e8b24fe9cd6c66 Mon Sep 17 00:00:00 2001 From: Greg Sherwood Date: Fri, 20 Nov 2020 16:25:26 +1100 Subject: [PATCH] Fixed bug #2992 : Enabling caching using a ruleset produces invalid cache files when using --sniffs and --exclude CLI args --- package.xml | 1 + src/Ruleset.php | 16 ++++++++-------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/package.xml b/package.xml index d98e3ab320..772eb40e9f 100644 --- a/package.xml +++ b/package.xml @@ -62,6 +62,7 @@ http://pear.php.net/dtd/package-2.0.xsd"> -- This works around a long-standing PHP bug with is_readable() -- Thanks to Michael S for the patch - Fixed bug #2913 : Generic.WhiteSpace.ScopeIndent false positive when opening and closing tag on same line inside conditional + - Fixed bug #2992 : Enabling caching using a ruleset produces invalid cache files when using --sniffs and --exclude CLI args - Fixed bug #3157 : PSR2.ControlStructures.SwitchDeclaration.BreakIndent false positive when case keyword is not indented - Fixed bug #3165 : Squiz.PHP.DisallowComparisonAssignment false positive when comparison inside closure - Fixed bug #3167 : Generic.WhiteSpace.ScopeIndent false positive when using PHP 8.0 constructor property promotion diff --git a/src/Ruleset.php b/src/Ruleset.php index 3220a18f22..085d18b4de 100644 --- a/src/Ruleset.php +++ b/src/Ruleset.php @@ -126,15 +126,9 @@ class Ruleset */ public function __construct(Config $config) { - // Ignore sniff restrictions if caching is on. - $restrictions = []; - $exclusions = []; - if ($config->cache === false) { - $restrictions = $config->sniffs; - $exclusions = $config->exclude; - } - $this->config = $config; + $restrictions = $config->sniffs; + $exclusions = $config->exclude; $sniffs = []; $standardPaths = []; @@ -200,6 +194,12 @@ public function __construct(Config $config) $sniffs = array_merge($sniffs, $this->processRuleset($standard)); }//end foreach + // Ignore sniff restrictions if caching is on. + if ($config->cache === true) { + $restrictions = []; + $exclusions = []; + } + $sniffRestrictions = []; foreach ($restrictions as $sniffCode) { $parts = explode('.', strtolower($sniffCode));