Skip to content

Commit bf2b64d

Browse files
authored
Merge pull request #841 from PHPCSStandards/feature/runner-dont-prefix-ruleset-errors
Runner: don't prefix Ruleset error notices
2 parents 6472698 + 14de190 commit bf2b64d

11 files changed

+25
-25
lines changed

src/Ruleset.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ public function __construct(Config $config)
239239
}
240240

241241
if ($numSniffs === 0) {
242-
throw new RuntimeException('No sniffs were registered');
242+
throw new RuntimeException('ERROR: No sniffs were registered');
243243
}
244244

245245
}//end __construct()
@@ -366,7 +366,7 @@ public function showSniffDeprecations()
366366

367367
$messages = [];
368368
$messageTemplate = 'This sniff has been deprecated since %s and will be removed in %s. %s';
369-
$errorTemplate = 'The %s::%s() method must return a %sstring, received %s';
369+
$errorTemplate = 'ERROR: The %s::%s() method must return a %sstring, received %s';
370370

371371
foreach ($this->deprecatedSniffs as $sniffCode => $className) {
372372
if (isset($this->sniffs[$className]) === false) {
@@ -486,7 +486,7 @@ public function processRuleset($rulesetPath, $depth=0)
486486
libxml_use_internal_errors(true);
487487
$ruleset = simplexml_load_string(file_get_contents($rulesetPath));
488488
if ($ruleset === false) {
489-
$errorMsg = "Ruleset $rulesetPath is not valid".PHP_EOL;
489+
$errorMsg = "ERROR: Ruleset $rulesetPath is not valid".PHP_EOL;
490490
$errors = libxml_get_errors();
491491
foreach ($errors as $error) {
492492
$errorMsg .= '- On line '.$error->line.', column '.$error->column.': '.$error->message;
@@ -530,7 +530,7 @@ public function processRuleset($rulesetPath, $depth=0)
530530
if ($relativePath !== false && is_file($relativePath) === true) {
531531
$autoloadPath = $relativePath;
532532
} else if (is_file($autoloadPath) === false) {
533-
throw new RuntimeException('The specified autoload file "'.$autoload.'" does not exist');
533+
throw new RuntimeException('ERROR: The specified autoload file "'.$autoload.'" does not exist');
534534
}
535535

536536
include_once $autoloadPath;
@@ -993,7 +993,7 @@ private function expandRulesetReference($ref, $rulesetDir, $depth=0)
993993
}
994994
} else {
995995
if (is_file($ref) === false) {
996-
$error = "Referenced sniff \"$ref\" does not exist";
996+
$error = "ERROR: Referenced sniff \"$ref\" does not exist";
997997
throw new RuntimeException($error);
998998
}
999999

@@ -1083,7 +1083,7 @@ private function processRule($rule, $newSniffs, $depth=0)
10831083

10841084
$type = strtolower((string) $rule->type);
10851085
if ($type !== 'error' && $type !== 'warning') {
1086-
throw new RuntimeException("Message type \"$type\" is invalid; must be \"error\" or \"warning\"");
1086+
throw new RuntimeException("ERROR: Message type \"$type\" is invalid; must be \"error\" or \"warning\"");
10871087
}
10881088

10891089
$this->ruleset[$code]['type'] = $type;
@@ -1412,7 +1412,7 @@ public function populateTokenListeners()
14121412

14131413
$tokens = $this->sniffs[$sniffClass]->register();
14141414
if (is_array($tokens) === false) {
1415-
$msg = "Sniff $sniffClass register() method must return an array";
1415+
$msg = "ERROR: Sniff $sniffClass register() method must return an array";
14161416
throw new RuntimeException($msg);
14171417
}
14181418

@@ -1523,7 +1523,7 @@ public function setSniffProperty($sniffClass, $name, $settings)
15231523

15241524
if ($isSettable === false) {
15251525
if ($settings['scope'] === 'sniff') {
1526-
$notice = "Ruleset invalid. Property \"$propertyName\" does not exist on sniff ";
1526+
$notice = "ERROR: Ruleset invalid. Property \"$propertyName\" does not exist on sniff ";
15271527
$notice .= array_search($sniffClass, $this->sniffCodes, true);
15281528
throw new RuntimeException($notice);
15291529
}

src/Runner.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ public function init()
351351
$this->ruleset->showSniffDeprecations();
352352
}
353353
} catch (RuntimeException $e) {
354-
$error = 'ERROR: '.$e->getMessage().PHP_EOL.PHP_EOL;
354+
$error = rtrim($e->getMessage(), "\r\n").PHP_EOL.PHP_EOL;
355355
$error .= $this->config->printShortUsage(true);
356356
throw new DeepExitException($error, 3);
357357
}

tests/Core/Ruleset/ConstructorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ public function testNoSniffsRegisteredException()
282282
$standard = __DIR__.'/ConstructorNoSniffsTest.xml';
283283
$config = new ConfigDouble(["--standard=$standard"]);
284284

285-
$message = 'No sniffs were registered';
285+
$message = 'ERROR: No sniffs were registered';
286286
$this->expectRuntimeExceptionMessage($message);
287287

288288
new Ruleset($config);

tests/Core/Ruleset/ExpandRulesetReferenceHomePathTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ public function testHomePathRefGetsExpandedAndThrowsExceptionWhenPathIsInvalid()
109109
$standard = __DIR__.'/ExpandRulesetReferenceHomePathFailTest.xml';
110110
$config = new ConfigDouble(["--standard=$standard"]);
111111

112-
$exceptionMessage = 'Referenced sniff "~/src/MyStandard/Sniffs/DoesntExist/" does not exist';
112+
$exceptionMessage = 'ERROR: Referenced sniff "~/src/MyStandard/Sniffs/DoesntExist/" does not exist';
113113
$this->expectRuntimeExceptionMessage($exceptionMessage);
114114

115115
new Ruleset($config);

tests/Core/Ruleset/ExpandRulesetReferenceTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public function testUnresolvableReferenceThrowsException($standard, $replacement
6161
$standard = __DIR__.'/'.$standard;
6262
$config = new ConfigDouble(["--standard=$standard"]);
6363

64-
$exceptionMessage = 'Referenced sniff "%s" does not exist';
64+
$exceptionMessage = 'ERROR: Referenced sniff "%s" does not exist';
6565
$this->expectRuntimeExceptionMessage(sprintf($exceptionMessage, $replacement));
6666

6767
new Ruleset($config);

tests/Core/Ruleset/PopulateTokenListenersTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public function testSniffWhereRegisterDoesNotReturnAnArrayThrowsException()
6262
$config = new ConfigDouble(["--standard=$standard"]);
6363

6464
$sniffClass = 'Fixtures\\TestStandard\\Sniffs\\InvalidSniffs\\RegisterNoArraySniff';
65-
$message = "Sniff $sniffClass register() method must return an array";
65+
$message = "ERROR: Sniff $sniffClass register() method must return an array";
6666
$this->expectRuntimeExceptionMessage($message);
6767

6868
new Ruleset($config);

tests/Core/Ruleset/ProcessRuleInvalidTypeTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public function testInvalidTypeHandling()
3232
$standard = __DIR__.'/ProcessRuleInvalidTypeTest.xml';
3333
$config = new ConfigDouble(["--standard=$standard"]);
3434

35-
$message = 'Message type "notice" is invalid; must be "error" or "warning"';
35+
$message = 'ERROR: Message type "notice" is invalid; must be "error" or "warning"';
3636
$this->expectRuntimeExceptionMessage($message);
3737

3838
new Ruleset($config);

tests/Core/Ruleset/ProcessRulesetAutoloadTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ public function testShouldProcessAutoloadCbfonly()
150150
*/
151151
public function testFileNotFoundException()
152152
{
153-
$exceptionMsg = 'The specified autoload file "./tests/Core/Ruleset/Fixtures/ThisFileDoesNotExist.php" does not exist';
153+
$exceptionMsg = 'ERROR: The specified autoload file "./tests/Core/Ruleset/Fixtures/ThisFileDoesNotExist.php" does not exist';
154154
$this->expectRuntimeExceptionMessage($exceptionMsg);
155155

156156
// Set up the ruleset.

tests/Core/Ruleset/ProcessRulesetBrokenRulesetTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public function testBrokenRulesetEmptyFile()
3939
$standard = __DIR__.'/ProcessRulesetBrokenRulesetEmptyFileTest.xml';
4040
$config = new ConfigDouble(["--standard=$standard"]);
4141

42-
$regex = '`^Ruleset \S+ProcessRulesetBrokenRulesetEmptyFileTest\.xml is not valid\R';
42+
$regex = '`^ERROR: Ruleset \S+ProcessRulesetBrokenRulesetEmptyFileTest\.xml is not valid\R';
4343
$regex .= '(- On line 1, column 1: Document is empty\R)?$`';
4444

4545
$this->expectRuntimeExceptionRegex($regex);
@@ -59,7 +59,7 @@ public function testBrokenRulesetSingleError()
5959
$standard = __DIR__.'/ProcessRulesetBrokenRulesetSingleErrorTest.xml';
6060
$config = new ConfigDouble(["--standard=$standard"]);
6161

62-
$regex = '`^Ruleset \S+ProcessRulesetBrokenRulesetSingleErrorTest\.xml is not valid\R';
62+
$regex = '`^ERROR: Ruleset \S+ProcessRulesetBrokenRulesetSingleErrorTest\.xml is not valid\R';
6363
$regex .= '- On line 3, column 1: Premature end of data in tag ruleset line 2\R$`';
6464

6565
$this->expectRuntimeExceptionRegex($regex);
@@ -79,7 +79,7 @@ public function testBrokenRulesetMultiError()
7979
$standard = __DIR__.'/ProcessRulesetBrokenRulesetMultiErrorTest.xml';
8080
$config = new ConfigDouble(["--standard=$standard"]);
8181

82-
$regex = '`^Ruleset \S+ProcessRulesetBrokenRulesetMultiErrorTest\.xml is not valid\R';
82+
$regex = '`^ERROR: Ruleset \S+ProcessRulesetBrokenRulesetMultiErrorTest\.xml is not valid\R';
8383
$regex .= '- On line 8, column 12: Opening and ending tag mismatch: property line 7 and rule\R';
8484
$regex .= '- On line 10, column 11: Opening and ending tag mismatch: properties line 5 and ruleset\R';
8585
$regex .= '(- On line 11, column 1: Premature end of data in tag rule line 4\R)?$`';

tests/Core/Ruleset/SetSniffPropertyTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ public function testSetPropertyAppliesPropertyToMultipleSniffsInCategory()
135135
*/
136136
public function testSetPropertyThrowsErrorOnInvalidProperty()
137137
{
138-
$exceptionMsg = 'Ruleset invalid. Property "indentation" does not exist on sniff Generic.Arrays.ArrayIndent';
138+
$exceptionMsg = 'ERROR: Ruleset invalid. Property "indentation" does not exist on sniff Generic.Arrays.ArrayIndent';
139139
$this->expectRuntimeExceptionMessage($exceptionMsg);
140140

141141
// Set up the ruleset.
@@ -155,7 +155,7 @@ public function testSetPropertyThrowsErrorOnInvalidProperty()
155155
*/
156156
public function testSetPropertyThrowsErrorWhenPropertyOnlyAllowedViaAttribute()
157157
{
158-
$exceptionMsg = 'Ruleset invalid. Property "arbitrarystring" does not exist on sniff TestStandard.SetProperty.NotAllowedViaAttribute';
158+
$exceptionMsg = 'ERROR: Ruleset invalid. Property "arbitrarystring" does not exist on sniff TestStandard.SetProperty.NotAllowedViaAttribute';
159159
$this->expectRuntimeExceptionMessage($exceptionMsg);
160160

161161
// Set up the ruleset.

tests/Core/Ruleset/ShowSniffDeprecationsTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -514,23 +514,23 @@ public static function dataExceptionIsThrownOnIncorrectlyImplementedInterface()
514514
return [
515515
'getDeprecationVersion() does not return a string' => [
516516
'standard' => 'ShowSniffDeprecationsInvalidDeprecationVersionTest.xml',
517-
'exceptionMessage' => 'The Fixtures\TestStandard\Sniffs\DeprecatedInvalid\InvalidDeprecationVersionSniff::getDeprecationVersion() method must return a non-empty string, received double',
517+
'exceptionMessage' => 'ERROR: The Fixtures\TestStandard\Sniffs\DeprecatedInvalid\InvalidDeprecationVersionSniff::getDeprecationVersion() method must return a non-empty string, received double',
518518
],
519519
'getRemovalVersion() does not return a string' => [
520520
'standard' => 'ShowSniffDeprecationsInvalidRemovalVersionTest.xml',
521-
'exceptionMessage' => 'The Fixtures\TestStandard\Sniffs\DeprecatedInvalid\InvalidRemovalVersionSniff::getRemovalVersion() method must return a non-empty string, received array',
521+
'exceptionMessage' => 'ERROR: The Fixtures\TestStandard\Sniffs\DeprecatedInvalid\InvalidRemovalVersionSniff::getRemovalVersion() method must return a non-empty string, received array',
522522
],
523523
'getDeprecationMessage() does not return a string' => [
524524
'standard' => 'ShowSniffDeprecationsInvalidDeprecationMessageTest.xml',
525-
'exceptionMessage' => 'The Fixtures\TestStandard\Sniffs\DeprecatedInvalid\InvalidDeprecationMessageSniff::getDeprecationMessage() method must return a string, received object',
525+
'exceptionMessage' => 'ERROR: The Fixtures\TestStandard\Sniffs\DeprecatedInvalid\InvalidDeprecationMessageSniff::getDeprecationMessage() method must return a string, received object',
526526
],
527527
'getDeprecationVersion() returns an empty string' => [
528528
'standard' => 'ShowSniffDeprecationsEmptyDeprecationVersionTest.xml',
529-
'exceptionMessage' => 'The Fixtures\TestStandard\Sniffs\DeprecatedInvalid\EmptyDeprecationVersionSniff::getDeprecationVersion() method must return a non-empty string, received ""',
529+
'exceptionMessage' => 'ERROR: The Fixtures\TestStandard\Sniffs\DeprecatedInvalid\EmptyDeprecationVersionSniff::getDeprecationVersion() method must return a non-empty string, received ""',
530530
],
531531
'getRemovalVersion() returns an empty string' => [
532532
'standard' => 'ShowSniffDeprecationsEmptyRemovalVersionTest.xml',
533-
'exceptionMessage' => 'The Fixtures\TestStandard\Sniffs\DeprecatedInvalid\EmptyRemovalVersionSniff::getRemovalVersion() method must return a non-empty string, received ""',
533+
'exceptionMessage' => 'ERROR: The Fixtures\TestStandard\Sniffs\DeprecatedInvalid\EmptyRemovalVersionSniff::getRemovalVersion() method must return a non-empty string, received ""',
534534
],
535535
];
536536

0 commit comments

Comments
 (0)