Skip to content

Commit

Permalink
Fixed bug #1334 : Undefined offset when explaining standard with cust…
Browse files Browse the repository at this point in the history
…om sniffs
  • Loading branch information
gsherwood committed Feb 5, 2017
1 parent b2f8291 commit 203046e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 31 deletions.
25 changes: 3 additions & 22 deletions package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,35 +17,16 @@ http://pear.php.net/dtd/package-2.0.xsd">
<date>2017-02-02</date>
<time>14:50:00</time>
<version>
<release>3.0.0RC3</release>
<api>3.0.0RC3</api>
<release>3.0.0RC4</release>
<api>3.0.0RC4</api>
</version>
<stability>
<release>beta</release>
<api>beta</api>
</stability>
<license uri="https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt">BSD 3-Clause License</license>
<notes>
- Added support for ES6 class declarations
-- Previously, these class were tokenized as JS objects but are now tokenzied as normal T_CLASS structures
- Added support for ES6 method declarations, where the "function" keyword is not used
-- Previously, these methods were tokenized as JS objects (fixes bug #1251)
-- The name of the ES6 method is now assigned the T_FUNCTION keyword and treated like a normal function
-- Custom sniffs that support JS and listen for T_FUNCTION tokens can't assume the token represents the word "function"
-- Check the contents of the token first, or use $phpcsFile->getDeclarationName($stackPtr) if you just want its name
-- There is no change for custom sniffs that only check PHP code
- PHPCBF exit codes have been changed so they are now more useful (request #1270)
-- Exit code 0 is now used to indicate that no fixable errors were found, and so nothing was fixed
-- Exit code 1 is now used to indicate that all fixable errors were fixed correctly
-- Exit code 2 is now used to indicate that PHPCBF failed to fix some of the fixable errors it found
-- Exit code 3 is now used for general script execution errors
- Added PEAR.Commenting.FileComment.ParamCommentAlignment to check alignment of multi-line param comments
- Includes all changes from the 2.8.0 release
- Fixed an issue where excluding a file using a @codingStandardsIgnoreFile comment would produce errors
-- For PHPCS, it would show empty files being processed
-- For PHPCBF, it would produce a PHP error
- Fixed bug #1233 : Can't set config data inside ruleset.xml file
- Fixed bug #1241 : CodeSniffer.conf not working with 3.x PHAR file
- Fixed bug #1334 : Undefined offset when explaining standard with custom sniffs
</notes>
<contents>
<dir name="/">
Expand Down
2 changes: 1 addition & 1 deletion src/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class Config
*
* @var string
*/
const VERSION = '3.0.0RC3';
const VERSION = '3.0.0RC4';

/**
* Package stability; either stable, beta or alpha.
Expand Down
19 changes: 11 additions & 8 deletions src/Ruleset.php
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ public function __construct(Config $config)
*/
public function explain()
{
$sniffs = array_keys($this->sniffs);
$sniffs = array_keys($this->sniffCodes);
sort($sniffs);

ob_start();
Expand All @@ -233,9 +233,7 @@ public function explain()
if ($i === $sniffCount) {
$currentStandard = null;
} else {
$parts = explode('\\', $sniff);

$currentStandard = $parts[2];
$currentStandard = substr($sniff, 0, strpos($sniff, '.'));
if ($lastStandard === null) {
$lastStandard = $currentStandard;
}
Expand All @@ -245,22 +243,27 @@ public function explain()
$sniffList = ob_get_contents();
ob_end_clean();

echo PHP_EOL.$lastStandard.' ('.$lastCount.' sniffs)'.PHP_EOL;
echo PHP_EOL.$lastStandard.' ('.$lastCount.' sniff';
if ($lastCount > 1) {
echo 's';
}

echo ')'.PHP_EOL;
echo str_repeat('-', (strlen($lastStandard.$lastCount) + 10));
echo PHP_EOL;
echo $sniffList;

$lastStandard = $parts[2];
$lastStandard = $currentStandard;
$lastCount = 0;

if ($currentStandard === null) {
break;
}

ob_start();
}
}//end if

echo ' '.$parts[2].'.'.$parts[4].'.'.substr($parts[5], 0, -5).PHP_EOL;
echo ' '.$sniff.PHP_EOL;
$lastCount++;
}//end foreach

Expand Down

0 comments on commit 203046e

Please sign in to comment.