Skip to content

Commit

Permalink
Fixed bug #19411 : magic method error on __construct(). I don't remem…
Browse files Browse the repository at this point in the history
…ber why AbstractScopeSniff was coded in such a complex way, but it seems to make sense to rewrite it and all tests are passing.
  • Loading branch information
gsherwood committed May 11, 2012
1 parent d8f22be commit 766f102
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 45 deletions.
54 changes: 9 additions & 45 deletions CodeSniffer/Standards/AbstractScopeSniff.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -61,20 +61,6 @@ abstract class PHP_CodeSniffer_Standards_AbstractScopeSniff implements PHP_CodeS
*/ */
private $_scopeTokens = array(); private $_scopeTokens = array();


/**
* The position in the tokens array that opened the current scope.
*
* @var array()
*/
protected $currScope = null;

/**
* The current file being checked.
*
* @var string
*/
protected $currFile = '';

/** /**
* True if this test should fire on tokens outside of the scope. * True if this test should fire on tokens outside of the scope.
* *
Expand Down Expand Up @@ -138,11 +124,7 @@ public function __construct(
*/ */
public final function register() public final function register()
{ {
if ($this->_listenOutside === false) { return $this->_tokens;
return $this->_scopeTokens;
} else {
return array_merge($this->_scopeTokens, $this->_tokens);
}


}//end register() }//end register()


Expand All @@ -159,35 +141,17 @@ public final function register()
*/ */
public final function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) public final function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
{ {
$file = $phpcsFile->getFilename();
if ($this->currFile !== $file) {
// We have changed files, so clean up.
$this->currScope = null;
$this->currFile = $file;
}

$tokens = $phpcsFile->getTokens(); $tokens = $phpcsFile->getTokens();


if (in_array($tokens[$stackPtr]['code'], $this->_scopeTokens) === true) { $foundScope = false;
$this->currScope = $stackPtr; foreach ($tokens[$stackPtr]['conditions'] as $scope => $code) {
$phpcsFile->addTokenListener($this, $this->_tokens); if (in_array($code, $this->_scopeTokens) === true) {
} else if ($this->currScope !== null $this->processTokenWithinScope($phpcsFile, $stackPtr, $scope);
&& isset($tokens[$this->currScope]['scope_closer']) === true $foundScope = true;
&& $stackPtr > $tokens[$this->currScope]['scope_closer']
) {
$this->currScope = null;
if ($this->_listenOutside === true) {
// This is a token outside the current scope, so notify the
// extender as they wish to know about this.
$this->processTokenOutsideScope($phpcsFile, $stackPtr);
} else {
// Don't remove the listener if the extender wants to know about
// tokens that live outside the current scope.
$phpcsFile->removeTokenListener($this, $this->_tokens);
} }
} else if ($this->currScope !== null) { }
$this->processTokenWithinScope($phpcsFile, $stackPtr, $this->currScope);
} else { if ($this->_listenOutside === true && $foundScope === false) {
$this->processTokenOutsideScope($phpcsFile, $stackPtr); $this->processTokenOutsideScope($phpcsFile, $stackPtr);
} }


Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -183,4 +183,11 @@ class Closure_Test {
function test() { function test() {
$foo = function() { echo 'foo'; }; $foo = function() { echo 'foo'; };
} }

/* @codingStandardsIgnoreStart */
class MyClass
{
/* @codingStandardsIgnoreEnd */
public function __construct() {}
}
?> ?>
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -17,4 +17,11 @@ function XMLParser() {}
function xmlParser() {} function xmlParser() {}


echo preg_replace_callback('~-([a-z])~', function ($match) { return strtoupper($match[1]); }, 'hello-world'); echo preg_replace_callback('~-([a-z])~', function ($match) { return strtoupper($match[1]); }, 'hello-world');

/* @codingStandardsIgnoreStart */
class MyClass
{
/* @codingStandardsIgnoreEnd */
public function __construct() {}
}
?> ?>
2 changes: 2 additions & 0 deletions package.xml
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ http://pear.php.net/dtd/package-2.0.xsd">
- Fixed bug #19374 : HEREDOC/NOWDOC Indentation problems - Fixed bug #19374 : HEREDOC/NOWDOC Indentation problems
- Fixed bug #19381 : traits and indetations in traits are not handled properly - Fixed bug #19381 : traits and indetations in traits are not handled properly
- Fixed bug #19394 : Notice in NonExecutableCodeSniff - Fixed bug #19394 : Notice in NonExecutableCodeSniff
- Fixed bug #19411 : magic method error on __construct()
-- The fix required a rewrite of AbstractScopeSniff, so please test any sniffs that extend this class
- Fixed bug #19412 : Incorrect error about assigning objects to variables when inside inline IF - Fixed bug #19412 : Incorrect error about assigning objects to variables when inside inline IF
- Fixed bug #19413 : php_cs thinks I haven't used a parameter when I have - Fixed bug #19413 : php_cs thinks I haven't used a parameter when I have
- Fixed bug #19414 : php_cs seems to not track variables correctly in heredocs - Fixed bug #19414 : php_cs seems to not track variables correctly in heredocs
Expand Down

0 comments on commit 766f102

Please sign in to comment.