Permalink
Browse files

Fixed bug #19411 : magic method error on __construct(). I don't remem…

…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...
1 parent d8f22be commit 766f102ca453e685e7a445f288043213cb7cde11 @gsherwood gsherwood committed May 11, 2012
@@ -62,20 +62,6 @@
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.
*
* @var boolean
@@ -138,11 +124,7 @@ public function __construct(
*/
public final function register()
{
- if ($this->_listenOutside === false) {
- return $this->_scopeTokens;
- } else {
- return array_merge($this->_scopeTokens, $this->_tokens);
- }
+ return $this->_tokens;
}//end register()
@@ -159,35 +141,17 @@ public function __construct(
*/
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();
- if (in_array($tokens[$stackPtr]['code'], $this->_scopeTokens) === true) {
- $this->currScope = $stackPtr;
- $phpcsFile->addTokenListener($this, $this->_tokens);
- } else if ($this->currScope !== null
- && isset($tokens[$this->currScope]['scope_closer']) === 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);
+ $foundScope = false;
+ foreach ($tokens[$stackPtr]['conditions'] as $scope => $code) {
+ if (in_array($code, $this->_scopeTokens) === true) {
+ $this->processTokenWithinScope($phpcsFile, $stackPtr, $scope);
+ $foundScope = true;
}
- } else if ($this->currScope !== null) {
- $this->processTokenWithinScope($phpcsFile, $stackPtr, $this->currScope);
- } else {
+ }
+
+ if ($this->_listenOutside === true && $foundScope === false) {
$this->processTokenOutsideScope($phpcsFile, $stackPtr);
}
@@ -183,4 +183,11 @@ class Closure_Test {
function test() {
$foo = function() { echo 'foo'; };
}
+
+/* @codingStandardsIgnoreStart */
+class MyClass
+{
+ /* @codingStandardsIgnoreEnd */
+ public function __construct() {}
+}
?>
@@ -17,4 +17,11 @@ function XMLParser() {}
function xmlParser() {}
echo preg_replace_callback('~-([a-z])~', function ($match) { return strtoupper($match[1]); }, 'hello-world');
+
+/* @codingStandardsIgnoreStart */
+class MyClass
+{
+ /* @codingStandardsIgnoreEnd */
+ public function __construct() {}
+}
?>
View
@@ -55,6 +55,8 @@ http://pear.php.net/dtd/package-2.0.xsd">
- Fixed bug #19374 : HEREDOC/NOWDOC Indentation problems
- Fixed bug #19381 : traits and indetations in traits are not handled properly
- 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 #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

0 comments on commit 766f102

Please sign in to comment.