Skip to content

Commit 01942e1

Browse files
committed
Explain: mark deprecated sniffs as such
This commit makes a small adjustment to the output of the `-e` (explain) command. Deprecated sniffs will now be marked with a trailing `*` asterix and if the standard contains deprecated sniffs, a line will show at the end of the output to explain that the `*` means that a sniff is deprecated. Includes a test documenting and safeguarding this behaviour.
1 parent 76eb00f commit 01942e1

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

src/Ruleset.php

+8
Original file line numberDiff line numberDiff line change
@@ -321,10 +321,18 @@ public function explain()
321321
}
322322
}//end if
323323

324+
if (isset($this->deprecatedSniffs[$sniff]) === true) {
325+
$sniff .= ' *';
326+
}
327+
324328
$sniffsInStandard[] = $sniff;
325329
++$lastCount;
326330
}//end foreach
327331

332+
if (count($this->deprecatedSniffs) > 0) {
333+
echo PHP_EOL.'* Sniffs marked with an asterix are deprecated.'.PHP_EOL;
334+
}
335+
328336
}//end explain()
329337

330338

tests/Core/Ruleset/ExplainTest.php

+42
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,48 @@ public function testExplainCustomRuleset()
166166
}//end testExplainCustomRuleset()
167167

168168

169+
/**
170+
* Test the output of the "explain" command for a standard containing both deprecated
171+
* and non-deprecated sniffs.
172+
*
173+
* Tests that:
174+
* - Deprecated sniffs are marked with an asterix in the list.
175+
* - A footnote is displayed explaining the asterix.
176+
* - And that the "standard uses # deprecated sniffs" listing is **not** displayed.
177+
*
178+
* @return void
179+
*/
180+
public function testExplainWithDeprecatedSniffs()
181+
{
182+
// Set up the ruleset.
183+
$standard = __DIR__.'/ShowSniffDeprecationsTest.xml';
184+
$config = new ConfigDouble(["--standard=$standard", '-e']);
185+
$ruleset = new Ruleset($config);
186+
187+
$expected = PHP_EOL;
188+
$expected .= 'The SniffDeprecationTest standard contains 9 sniffs'.PHP_EOL.PHP_EOL;
189+
190+
$expected .= 'Fixtures (9 sniffs)'.PHP_EOL;
191+
$expected .= '-------------------'.PHP_EOL;
192+
$expected .= ' Fixtures.Deprecated.WithLongReplacement *'.PHP_EOL;
193+
$expected .= ' Fixtures.Deprecated.WithoutReplacement *'.PHP_EOL;
194+
$expected .= ' Fixtures.Deprecated.WithReplacement *'.PHP_EOL;
195+
$expected .= ' Fixtures.Deprecated.WithReplacementContainingLinuxNewlines *'.PHP_EOL;
196+
$expected .= ' Fixtures.Deprecated.WithReplacementContainingNewlines *'.PHP_EOL;
197+
$expected .= ' Fixtures.SetProperty.AllowedAsDeclared'.PHP_EOL;
198+
$expected .= ' Fixtures.SetProperty.AllowedViaMagicMethod'.PHP_EOL;
199+
$expected .= ' Fixtures.SetProperty.AllowedViaStdClass'.PHP_EOL;
200+
$expected .= ' Fixtures.SetProperty.NotAllowedViaAttribute'.PHP_EOL.PHP_EOL;
201+
202+
$expected .= '* Sniffs marked with an asterix are deprecated.'.PHP_EOL;
203+
204+
$this->expectOutputString($expected);
205+
206+
$ruleset->explain();
207+
208+
}//end testExplainWithDeprecatedSniffs()
209+
210+
169211
/**
170212
* Test that each standard passed on the command-line is explained separately.
171213
*

0 commit comments

Comments
 (0)