UseDeclarationSniff checks for newlines between use-statements
authorTim Düsterhus <duesterhus@woltlab.com>
Fri, 4 Jan 2013 15:30:23 +0000 (16:30 +0100)
committerTim Düsterhus <duesterhus@woltlab.com>
Fri, 4 Jan 2013 15:30:23 +0000 (16:30 +0100)
cf. #987

CodeSniff/WCF/Sniffs/Classes/ClassFileNameSniff.php
CodeSniff/WCF/Sniffs/ControlStructures/ControlSignatureSniff.php
CodeSniff/WCF/Sniffs/Namespaces/UseDeclarationSniff.php
CodeSniff/WCF/Sniffs/WhiteSpace/SuperfluousWhitespaceSniff.php
wcfsetup/install/files/lib/acp/form/StyleAddForm.class.php
wcfsetup/install/files/lib/system/cache/builder/OptionCacheBuilder.class.php
wcfsetup/install/files/lib/system/package/PackageInstallationNodeBuilder.class.php

index da3ca9dc9853dd17e7ceea06aecb005eb6a12fa3..49973829196a9068f8bcb5f3b9b2badd0c884846 100644 (file)
@@ -6,7 +6,7 @@
  * See: https://github.com/squizlabs/PHP_CodeSniffer/blob/master/CodeSniffer/Standards/Squiz/Sniffs/Classes/ClassFileNameSniff.php
  * 
  * @author     Tim Duesterhus
- * @license    BSD Licence <https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt>
+ * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
  * @package    com.woltlab.wcf
  * @category   Community Framework
  */
index 283c33e22efaa515eacac52006ad522f2ebb9cee..a10dbad2af33faf4518cc9a01b874bce26d0eb0a 100644 (file)
@@ -10,7 +10,7 @@ if (class_exists('PHP_CodeSniffer_Standards_AbstractPatternSniff', true) === fal
  * See: https://github.com/squizlabs/PHP_CodeSniffer/blob/master/CodeSniffer/Standards/Squiz/Sniffs/ControlStructures/ControlSignatureSniff.php
  * 
  * @author     Tim Duesterhus
- * @license    BSD Licence <https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt>
+ * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
  * @package    com.woltlab.wcf
  * @category   Community Framework
  */
index 38c47fcc4c4568f62c275e156ef183df4660363a..b5adfc30459f8b1219c89fb1f5dccb014c7f5fce 100644 (file)
@@ -62,10 +62,24 @@ class WCF_Sniffs_Namespaces_UseDeclarationSniff implements PHP_CodeSniffer_Sniff
                        }
                }
                
+               $end = $phpcsFile->findNext(T_SEMICOLON, ($stackPtr + 1));
+               $next = $phpcsFile->findNext(T_WHITESPACE, ($end + 1), null, true);
+               if ($tokens[$next]['code'] === T_USE) {
+                       $diff = $tokens[$next]['line'] - $tokens[$stackPtr]['line'] - 1;
+                       if ($diff !== 0) {
+                               $error = 'There must not be any blank lines between use statements; %s found;';
+                               $data = array($diff);
+                               $phpcsFile->addError($error, $stackPtr, 'SpaceBetweenUse', $data);
+                       }
+               }
+               
                // Only interested in the last USE statement from here onwards.
                $nextUse = $phpcsFile->findNext(T_USE, ($stackPtr + 1));
                if ($nextUse !== false) {
-                       return;
+                       $next = $phpcsFile->findNext(T_WHITESPACE, ($nextUse + 1), null, true);
+                       if ($tokens[$next]['code'] !== T_OPEN_PARENTHESIS) {
+                               return;
+                       }
                }
                
                $end  = $phpcsFile->findNext(T_SEMICOLON, ($stackPtr + 1));
@@ -77,7 +91,7 @@ class WCF_Sniffs_Namespaces_UseDeclarationSniff implements PHP_CodeSniffer_Sniff
                        }
                        
                        $error = 'There must be one blank line after the last USE statement; %s found;';
-                       $data  = array($diff);
+                       $data = array($diff);
                        $phpcsFile->addError($error, $stackPtr, 'SpaceAfterLastUse', $data);
                }
        
index 40d5f210545090da6fee08579a1d1a36b2f368d8..ec4cf0bd7e3c7d228558e82f8a76f29058333be7 100644 (file)
@@ -6,7 +6,7 @@
  * See: https://github.com/squizlabs/PHP_CodeSniffer/blob/master/CodeSniffer/Standards/Squiz/Sniffs/WhiteSpace/SuperfluousWhitespaceSniff.php
  * 
  * @author     Tim Duesterhus
- * @license    BSD Licence <https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt>
+ * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
  * @package    com.woltlab.wcf
  * @category   Community Framework
  */
index 1c1f608f7a621f2adb2cb5f6939002a46d8982c9..3e76477890798399c575fa7561d0f533196028cb 100644 (file)
@@ -1,7 +1,6 @@
 <?php
 namespace wcf\acp\form;
 use wcf\data\style\StyleEditor;
-
 use wcf\data\package\Package;
 use wcf\data\style\StyleAction;
 use wcf\data\template\group\TemplateGroupList;
index 2d1251e316110aa7fe7c5b09fff82cab097d785b..8239b3e5c4504d0f3d0b5a9648199a9a27b1cf64 100644 (file)
@@ -1,9 +1,8 @@
 <?php
 namespace wcf\system\cache\builder;
-use wcf\system\Regex;
-
 use wcf\data\option\category\OptionCategory;
 use wcf\system\database\util\PreparedStatementConditionBuilder;
+use wcf\system\Regex;
 use wcf\system\WCF;
 
 /**
index 63da8f322631efca18b5496c8f1e3ca1820f7952..7f440f850f02c9bd80402f8b47b33579831b5f53 100644 (file)
@@ -1,9 +1,8 @@
 <?php
 namespace wcf\system\package;
-use wcf\data\package\Package;
-
 use wcf\data\package\installation\queue\PackageInstallationQueueEditor;
 use wcf\data\package\installation\queue\PackageInstallationQueueList;
+use wcf\data\package\Package;
 use wcf\system\exception\SystemException;
 use wcf\system\Callback;
 use wcf\system\WCF;