Skip to content

Commit

Permalink
Fixed bug squizlabs#791 : codingStandardsChangeSetting settings not w…
Browse files Browse the repository at this point in the history
…orking with namespaces
  • Loading branch information
gsherwood committed Mar 23, 2016
1 parent 8129f9b commit 0abb1df
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
11 changes: 11 additions & 0 deletions CodeSniffer.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,16 @@ class PHP_CodeSniffer
*/
protected $sniffs = array();

/**
* A mapping of sniff codes to fully qualified class names.
*
* The key is the sniff code and the value
* is the fully qualified name of the sniff class.
*
* @var array<string, string>
*/
public $sniffCodes = array();

/**
* The listeners array, indexed by token type.
*
Expand Down Expand Up @@ -1408,6 +1418,7 @@ public function populateTokenListeners()
$code = substr($code, 0, -5);

$this->listeners[$listenerClass] = new $listenerClass();
$this->sniffCodes[$code] = $listenerClass;

// Set custom properties.
if (isset($this->ruleset[$code]['properties']) === true) {
Expand Down
11 changes: 5 additions & 6 deletions CodeSniffer/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -501,12 +501,11 @@ public function start($contents=null)
$start = strpos($token['content'], '@codingStandardsChangeSetting');
$comment = substr($token['content'], ($start + 30));
$parts = explode(' ', $comment);
if (count($parts) >= 3) {
$sniffParts = explode('.', $parts[0]);
if (count($sniffParts) >= 3) {
$listenerClass = $sniffParts[0].'_Sniffs_'.$sniffParts[1].'_'.$sniffParts[2].'Sniff';
$this->phpcs->setSniffProperty($listenerClass, $parts[1], $parts[2]);
}
if (count($parts) >= 3
&& isset($this->phpcs->sniffCodes[$parts[0]]) === true
) {
$listenerClass = $this->phpcs->sniffCodes[$parts[0]];
$this->phpcs->setSniffProperty($listenerClass, $parts[1], $parts[2]);
}
}//end if
}//end if
Expand Down
1 change: 1 addition & 0 deletions package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
- Squiz ComparisonOperatorUsageSniff now allows conditions like while(true)
- PEAR FunctionCallSignatureSniff (and the Squiz and PSR2 sniffs that use it) now correctly check the first argument
-- Further fix for bug #698
- Fixed bug #791 : codingStandardsChangeSetting settings not working with namespaces
- Fixed bug #872 : Incorrect detection of blank lines between CSS class names
- Fixed bug #879 : Generic InlineControlStructureSniff can create parse error when case/if/elseif/else have mixed brace and braceless definitions
- Fixed bug #883 : PSR2 is not checking for blank lines at the start and end of control structures
Expand Down

0 comments on commit 0abb1df

Please sign in to comment.