Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed bug #19655 : Closures reporting as multi-line when they are not

  • Loading branch information...
commit 53696950ac850628d90c217a05ba2565dd380b0f 1 parent e49952e
Greg Sherwood authored October 26, 2012
10  CodeSniffer/Standards/PEAR/Sniffs/Functions/FunctionDeclarationSniff.php
@@ -105,7 +105,7 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
105 105
         }//end if
106 106
 
107 107
         // Check if this is a single line or multi-line declaration.
108  
-        $singleLine = false;
  108
+        $singleLine = true;
109 109
         if ($tokens[$openBracket]['line'] === $tokens[$closeBracket]['line']) {
110 110
             // Closures may use the USE keyword and so be multi-line in this way.
111 111
             if ($tokens[$stackPtr]['code'] === T_CLOSURE) {
@@ -114,13 +114,13 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
114 114
                     // are also on the same line, this is a single line declaration.
115 115
                     $open  = $phpcsFile->findNext(T_OPEN_PARENTHESIS, ($use + 1));
116 116
                     $close = $tokens[$open]['parenthesis_closer'];
117  
-                    if ($tokens[$open]['line'] === $tokens[$close]['line']) {
118  
-                        $singleLine = true;
  117
+                    if ($tokens[$open]['line'] !== $tokens[$close]['line']) {
  118
+                        $singleLine = false;
119 119
                     }
120 120
                 }
121  
-            } else {
122  
-                $singleLine = true;
123 121
             }
  122
+        } else {
  123
+            $singleLine = false;
124 124
         }
125 125
 
126 126
         if ($singleLine === true) {
7  CodeSniffer/Standards/Squiz/Tests/Functions/MultiLineFunctionDeclarationUnitTest.inc
@@ -90,4 +90,11 @@ $noArgs_longVars = function () use (
90 90
 ) {
91 91
     // body
92 92
 };
  93
+
  94
+usort(
  95
+    $data,
  96
+    function ($a, $b) {
  97
+        // body
  98
+    }
  99
+);
93 100
 ?>
1  package.xml
@@ -58,6 +58,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
58 58
   - Fixed bug #19616 : Nested switches cause false error in PSR2
59 59
   - Fixed bug #19629 : PSR2 error for inline comments on multi-line argument lists
60 60
   - Fixed bug #19644 : Alternative syntax, e.g. if/endif triggers Inline Control Structure error
  61
+  - Fixed bug #19655 : Closures reporting as multi-line when they are not
61 62
  </notes>
62 63
  <contents>
63 64
   <dir name="/">

0 notes on commit 5369695

Please sign in to comment.
Something went wrong with that request. Please try again.