Completed
Branch develop (6d735e)
by Timothy
07:48
created
build/CodeIgniter/Sniffs/Commenting/InlineCommentSniff.php 2 patches
Doc Comments   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -41,7 +41,7 @@  discard block
 block discarded – undo
41 41
     /**
42 42
      * Returns an array of tokens this test wants to listen for.
43 43
      *
44
-     * @return array
44
+     * @return integer[]
45 45
      */
46 46
     public function register()
47 47
     {
@@ -118,7 +118,7 @@  discard block
 block discarded – undo
118 118
      * @param File $phpcsFile The current file being scanned.
119 119
      * @param int                  $stackPtr  Pointer to the first comment line.
120 120
      *
121
-     * @return type array Pointers to tokens making up the comment block.
121
+     * @return integer[] array Pointers to tokens making up the comment block.
122 122
      */
123 123
     private function _getCommentBlock(File $phpcsFile, $stackPtr)
124 124
     {
@@ -145,7 +145,7 @@  discard block
 block discarded – undo
145 145
      * Add errors to $phpcsFile, if $commentLines isn't enclosed with blank lines.
146 146
      *
147 147
      * @param File $phpcsFile    The current file being scanned.
148
-     * @param array                $commentLines Lines of the comment block being checked.
148
+     * @param integer[]                $commentLines Lines of the comment block being checked.
149 149
      *
150 150
      * @return bool TRUE if $commentLines is enclosed with at least a blank line
151 151
      * before and after, FALSE otherwise.
Please login to merge, or discard this patch.
Braces   +26 added lines, -14 removed lines patch added patch discarded remove patch
@@ -30,8 +30,7 @@  discard block
 block discarded – undo
30 30
 use PHP_CodeSniffer\Sniffs\Sniff;
31 31
 use PHP_CodeSniffer\Files\File;
32 32
 
33
-class InlineCommentSniff implements Sniff
34
-{
33
+class InlineCommentSniff implements Sniff {
35 34
     /**
36 35
      * @var int Limit defining long comments.
37 36
      * Long comments count $longCommentLimit or more lines.
@@ -65,14 +64,17 @@  discard block
 block discarded – undo
65 64
 
66 65
         // keep testing only if it's about the first comment of the block
67 66
         $previousCommentPtr = $phpcsFile->findPrevious($tokens[$stackPtr]['code'], $stackPtr - 1);
68
-        if ($tokens[$previousCommentPtr]['line'] !== $tokens[$stackPtr]['line'] - 1) {
69
-            if (TRUE !== $this->_checkCommentStyle($phpcsFile, $stackPtr)) {
67
+        if ($tokens[$previousCommentPtr]['line'] !== $tokens[$stackPtr]['line'] - 1)
68
+        {
69
+            if (TRUE !== $this->_checkCommentStyle($phpcsFile, $stackPtr))
70
+            {
70 71
                 return;
71 72
             }
72 73
 
73 74
             $commentLines = $this->_getCommentBlock($phpcsFile, $stackPtr);
74 75
 
75
-            if (count($commentLines) >= $this->longCommentLimit) {
76
+            if (count($commentLines) >= $this->longCommentLimit)
77
+            {
76 78
                 $this->_checkBlankLinesAroundLongComment($phpcsFile, $commentLines);
77 79
             }
78 80
         }
@@ -93,17 +95,21 @@  discard block
 block discarded – undo
93 95
     private function _checkCommentStyle(File $phpcsFile, $stackPtr)
94 96
     {
95 97
         $tokens = $phpcsFile->getTokens();
96
-        if ($tokens[$stackPtr]['content']{0} === '#') {
98
+        if ($tokens[$stackPtr]['content']{0} === '#')
99
+        {
97 100
             $error  = 'Perl-style comments are not allowed; use "// Comment" or DocBlock comments instead';
98 101
             $phpcsFile->addError($error, $stackPtr, 'WrongStyle');
99 102
             return FALSE;
100
-        } else if (substr($tokens[$stackPtr]['content'], 0, 2) === '/*'
103
+        }
104
+        else if (substr($tokens[$stackPtr]['content'], 0, 2) === '/*'
101 105
             || $tokens[$stackPtr]['content']{0} === '*'
102 106
         ) {
103 107
             $error  = 'Multi lines comments are not allowed; use "// Comment" DocBlock comments instead';
104 108
             $phpcsFile->addError($error, $stackPtr, 'WrongStyle');
105 109
             return FALSE;
106
-        } else if (substr($tokens[$stackPtr]['content'], 0, 2) !== '//') {
110
+        }
111
+        else if (substr($tokens[$stackPtr]['content'], 0, 2) !== '//')
112
+        {
107 113
             $error  = 'Use single line or DocBlock comments within code';
108 114
             $phpcsFile->addError($error, $stackPtr, 'WrongStyle');
109 115
             return FALSE;
@@ -127,8 +133,10 @@  discard block
 block discarded – undo
127 133
         $nextComment  = $stackPtr;
128 134
         $lastLine     = $tokens[$stackPtr]['line'];
129 135
 
130
-        while (($nextComment = $phpcsFile->findNext($tokens[$stackPtr]['code'], ($nextComment + 1), null, false)) !== false) {
131
-            if (($tokens[$nextComment]['line'] - 1) !== $lastLine) {
136
+        while (($nextComment = $phpcsFile->findNext($tokens[$stackPtr]['code'], ($nextComment + 1), null, false)) !== false)
137
+        {
138
+            if (($tokens[$nextComment]['line'] - 1) !== $lastLine)
139
+            {
132 140
                 // Not part of the block.
133 141
                 break;
134 142
             }
@@ -158,10 +166,12 @@  discard block
 block discarded – undo
158 166
         // check blank line before the long comment
159 167
         $firstCommentPtr = reset($commentLines);
160 168
         $firstPreviousSpacePtr = $firstCommentPtr - 1;
161
-        while (T_WHITESPACE === $tokens[$firstPreviousSpacePtr]['code'] && $firstPreviousSpacePtr > 0) {
169
+        while (T_WHITESPACE === $tokens[$firstPreviousSpacePtr]['code'] && $firstPreviousSpacePtr > 0)
170
+        {
162 171
             $firstPreviousSpacePtr--;
163 172
         }
164
-        if ($tokens[$firstPreviousSpacePtr]['line'] >= $tokens[$firstCommentPtr]['line'] - 1) {
173
+        if ($tokens[$firstPreviousSpacePtr]['line'] >= $tokens[$firstCommentPtr]['line'] - 1)
174
+        {
165 175
             $error  = "Please add a blank line before comments counting more than {$this->longCommentLimit} lines.";
166 176
             $phpcsFile->addError($error, $firstCommentPtr, 'LongCommentWithoutSpacing');
167 177
             $hasBlankLinesAround = FALSE;
@@ -170,10 +180,12 @@  discard block
 block discarded – undo
170 180
         // check blank line after the long comment
171 181
         $lastCommentPtr = end($commentLines);
172 182
         $lastNextSpacePtr = $lastCommentPtr + 1;
173
-        while (T_WHITESPACE === $tokens[$lastNextSpacePtr]['code'] && $lastNextSpacePtr < count($tokens)) {
183
+        while (T_WHITESPACE === $tokens[$lastNextSpacePtr]['code'] && $lastNextSpacePtr < count($tokens))
184
+        {
174 185
             $lastNextSpacePtr++;
175 186
         }
176
-        if ($tokens[$lastNextSpacePtr]['line'] <= $tokens[$lastCommentPtr]['line'] + 1) {
187
+        if ($tokens[$lastNextSpacePtr]['line'] <= $tokens[$lastCommentPtr]['line'] + 1)
188
+        {
177 189
             $error  = "Please add a blank line after comments counting more than {$this->longCommentLimit} lines.";
178 190
             $phpcsFile->addError($error, $lastCommentPtr, 'LongCommentWithoutSpacing');
179 191
             $hasBlankLinesAround = FALSE;
Please login to merge, or discard this patch.
build/CodeIgniter/Sniffs/Files/ByteOrderMarkSniff.php 2 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -35,7 +35,7 @@
 block discarded – undo
35 35
     /**
36 36
      * Returns an array of tokens this test wants to listen for.
37 37
      *
38
-     * @return array
38
+     * @return integer[]
39 39
      */
40 40
     public function register()
41 41
     {
Please login to merge, or discard this patch.
Braces   +9 added lines, -6 removed lines patch added patch discarded remove patch
@@ -30,8 +30,7 @@  discard block
 block discarded – undo
30 30
 use PHP_CodeSniffer\Sniffs\Sniff;
31 31
 use PHP_CodeSniffer\Files\File;
32 32
 
33
-class ByteOrderMarkSniff implements Sniff
34
-{
33
+class ByteOrderMarkSniff implements Sniff {
35 34
     /**
36 35
      * Returns an array of tokens this test wants to listen for.
37 36
      *
@@ -77,18 +76,22 @@  discard block
 block discarded – undo
77 76
     public function process(File $phpcsFile, $stackPtr )
78 77
     {
79 78
         // We are only interested if this is the first open tag.
80
-        if ($stackPtr !== 0) {
81
-            if ($phpcsFile->findPrevious(T_OPEN_TAG, ($stackPtr - 1)) !== false) {
79
+        if ($stackPtr !== 0)
80
+        {
81
+            if ($phpcsFile->findPrevious(T_OPEN_TAG, ($stackPtr - 1)) !== false)
82
+            {
82 83
                 return;
83 84
             }
84 85
         }
85 86
 
86 87
         $tokens = $phpcsFile->getTokens();
87 88
         $fileStartString = $tokens[0]['content'];
88
-        foreach ($this->getBomDefinitions() as $bomName => $expectedBomHex) {
89
+        foreach ($this->getBomDefinitions() as $bomName => $expectedBomHex)
90
+        {
89 91
             $bomByteLength = strlen($expectedBomHex) / 2;
90 92
             $fileStartHex = bin2hex(substr($fileStartString, 0, $bomByteLength));
91
-            if ($fileStartHex === $expectedBomHex) {
93
+            if ($fileStartHex === $expectedBomHex)
94
+            {
92 95
                 $error = "File contains a $bomName byte order mark (BOM).";
93 96
                 $phpcsFile->addError($error, $stackPtr);
94 97
                 break;
Please login to merge, or discard this patch.
build/CodeIgniter/Sniffs/Files/Utf8EncodingSniff.php 2 patches
Doc Comments   +2 added lines, -1 removed lines patch added patch discarded remove patch
@@ -36,7 +36,7 @@  discard block
 block discarded – undo
36 36
     /**
37 37
      * Returns an array of tokens this test wants to listen for.
38 38
      *
39
-     * @return array
39
+     * @return integer[]
40 40
      */
41 41
     public function register()
42 42
     {
@@ -174,6 +174,7 @@  discard block
 block discarded – undo
174 174
      *
175 175
      * @param string $str String to split.
176 176
 	 * @param int $len number of characters per chunk
177
+	 * @param string $glue
177 178
      *
178 179
      * @return array string array after splitting
179 180
      *
Please login to merge, or discard this patch.
Braces   +48 added lines, -23 removed lines patch added patch discarded remove patch
@@ -30,8 +30,7 @@  discard block
 block discarded – undo
30 30
 use PHP_CodeSniffer\Sniffs\Sniff;
31 31
 use PHP_CodeSniffer\Files\File;
32 32
 
33
-class Utf8EncodingSniff implements Sniff
34
-{
33
+class Utf8EncodingSniff implements Sniff {
35 34
 
36 35
     /**
37 36
      * Returns an array of tokens this test wants to listen for.
@@ -59,8 +58,10 @@  discard block
 block discarded – undo
59 58
     public function process(File $phpcsFile, $stackPtr)
60 59
     {
61 60
         // We are only interested if this is the first open tag.
62
-        if ($stackPtr !== 0) {
63
-            if ($phpcsFile->findPrevious(T_OPEN_TAG, ($stackPtr - 1)) !== false) {
61
+        if ($stackPtr !== 0)
62
+        {
63
+            if ($phpcsFile->findPrevious(T_OPEN_TAG, ($stackPtr - 1)) !== false)
64
+            {
64 65
                 return;
65 66
             }
66 67
         }
@@ -68,15 +69,18 @@  discard block
 block discarded – undo
68 69
         $file_path = $phpcsFile->getFilename();
69 70
         $file_name = basename($file_path);
70 71
         $file_content = file_get_contents($file_path);
71
-        if (false === mb_check_encoding($file_content, 'UTF-8')) {
72
+        if (false === mb_check_encoding($file_content, 'UTF-8'))
73
+        {
72 74
             $error = 'File "' . $file_name . '" should be saved with Unicode (UTF-8) encoding.';
73 75
             $phpcsFile->addError($error, 0);
74 76
         }
75
-        if ( ! self::_checkUtf8W3c($file_content)) {
77
+        if ( ! self::_checkUtf8W3c($file_content))
78
+        {
76 79
             $error = 'File "' . $file_name . '" should be saved with Unicode (UTF-8) encoding, but it did not successfully pass the W3C test.';
77 80
             $phpcsFile->addError($error, 0);
78 81
         }
79
-        if ( ! self::_checkUtf8Rfc3629($file_content)) {
82
+        if ( ! self::_checkUtf8Rfc3629($file_content))
83
+        {
80 84
             $error = 'File "' . $file_name . '" should be saved with Unicode (UTF-8) encoding, but it did not meet RFC3629 requirements.';
81 85
             $phpcsFile->addError($error, 0);
82 86
         }
@@ -98,7 +102,7 @@  discard block
 block discarded – undo
98 102
     {
99 103
         $content_chunks=self::mb_chunk_split($content, 4096, '');
100 104
     	foreach($content_chunks as $content_chunk)
101
-		{
105
+    	{
102 106
 			$preg_result= preg_match(
103 107
             '%^(?:
104 108
                   [\x09\x0A\x0D\x20-\x7E]            # ASCII
@@ -135,29 +139,47 @@  discard block
 block discarded – undo
135 139
     private static function _checkUtf8Rfc3629($content)
136 140
     {
137 141
         $len = strlen($content);
138
-        for ($i = 0; $i < $len; $i++) {
142
+        for ($i = 0; $i < $len; $i++)
143
+        {
139 144
             $c = ord($content[$i]);
140
-            if ($c > 128) {
141
-                if (($c >= 254)) {
145
+            if ($c > 128)
146
+            {
147
+                if (($c >= 254))
148
+                {
142 149
                     return false;
143
-                } elseif ($c >= 252) {
150
+                }
151
+                elseif ($c >= 252)
152
+                {
144 153
                     $bits=6;
145
-                } elseif ($c >= 248) {
154
+                }
155
+                elseif ($c >= 248)
156
+                {
146 157
                     $bits=5;
147
-                } elseif ($c >= 240) {
158
+                }
159
+                elseif ($c >= 240)
160
+                {
148 161
                     $bytes = 4;
149
-                } elseif ($c >= 224) {
162
+                }
163
+                elseif ($c >= 224)
164
+                {
150 165
                     $bytes = 3;
151
-                } elseif ($c >= 192) {
166
+                }
167
+                elseif ($c >= 192)
168
+                {
152 169
                     $bytes = 2;
153
-                } else {
170
+                }
171
+                else
172
+                {
154 173
                     return false;
155
-                } if (($i + $bytes) > $len) {
174
+                } if (($i + $bytes) > $len)
175
+                {
156 176
                     return false;
157
-                } while ($bytes > 1) {
177
+                } while ($bytes > 1)
178
+                {
158 179
                     $i++;
159 180
                     $b = ord($content[$i]);
160
-                    if ($b < 128 || $b > 191) {
181
+                    if ($b < 128 || $b > 191)
182
+                    {
161 183
                         return false;
162 184
                     }
163 185
                     $bytes--;
@@ -185,10 +207,12 @@  discard block
 block discarded – undo
185 207
 		$array = self::mbStringToArray ($str);
186 208
 		$n = -1;
187 209
 		$new = Array();
188
-		foreach ($array as $char) {
210
+		foreach ($array as $char)
211
+		{
189 212
 			$n++;
190 213
 			if ($n < $len) $new []= $char;
191
-			elseif ($n == $len) {
214
+			elseif ($n == $len)
215
+			{
192 216
 				$new []= $glue . $char;
193 217
 				$n = 0;
194 218
 			}
@@ -209,7 +233,8 @@  discard block
 block discarded – undo
209 233
 		if (empty($str)) return false;
210 234
 		$len = mb_strlen($str);
211 235
 		$array = array();
212
-		for ($i = 0; $i < $len; $i++) {
236
+		for ($i = 0; $i < $len; $i++)
237
+		{
213 238
 			$array[] = mb_substr($str, $i, 1);
214 239
 		}
215 240
 		return $array;
Please login to merge, or discard this patch.
build/CodeIgniter/Sniffs/Operators/LogicalOperatorAndSniff.php 2 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -35,7 +35,7 @@
 block discarded – undo
35 35
 	/**
36 36
      * Returns an array of tokens this test wants to listen for: symbolic and literal operators and.
37 37
      *
38
-     * @return array
38
+     * @return integer[]
39 39
      */
40 40
     public function register()
41 41
     {
Please login to merge, or discard this patch.
Braces   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -30,8 +30,7 @@  discard block
 block discarded – undo
30 30
 use PHP_CodeSniffer\Sniffs\Sniff;
31 31
 use PHP_CodeSniffer\Files\File;
32 32
 
33
-class LogicalOperatorAndSniff implements Sniff
34
-{
33
+class LogicalOperatorAndSniff implements Sniff {
35 34
 	/**
36 35
      * Returns an array of tokens this test wants to listen for: symbolic and literal operators and.
37 36
      *
@@ -63,7 +62,8 @@  discard block
 block discarded – undo
63 62
         $operator_string = $operator_token['content'];
64 63
         $operator_code = $operator_token['code'];
65 64
 
66
-        if ($operator_string !== strtoupper($operator_string)) {
65
+        if ($operator_string !== strtoupper($operator_string))
66
+        {
67 67
             $error_message = 'Logical operator should be in upper case;'
68 68
                 . ' use "' . strtoupper($operator_string)
69 69
                 . '" instead of "' . $operator_string . '"';
Please login to merge, or discard this patch.
build/CodeIgniter/Sniffs/Operators/StrictComparisonOperatorSniff.php 2 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -41,7 +41,7 @@
 block discarded – undo
41 41
     /**
42 42
      * Returns an array of tokens this test wants to listen for.
43 43
      *
44
-     * @return array
44
+     * @return integer[]
45 45
      */
46 46
     public function register()
47 47
     {
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -31,8 +31,7 @@
 block discarded – undo
31 31
 use PHP_CodeSniffer\Sniffs\Sniff;
32 32
 use PHP_CodeSniffer\Files\File;
33 33
 
34
-class StrictComparisonOperatorSniff implements Sniff
35
-{
34
+class StrictComparisonOperatorSniff implements Sniff {
36 35
     private static $_replacements = array(
37 36
         T_IS_EQUAL     => '===',
38 37
         T_IS_NOT_EQUAL => '!==',
Please login to merge, or discard this patch.
build/CodeIgniter/Sniffs/Operators/UppercaseLogicalOperatorOrSniff.php 2 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -35,7 +35,7 @@
 block discarded – undo
35 35
     /**
36 36
      * Returns an array of tokens this test wants to listen for: literal and symbolic operators or.
37 37
      *
38
-     * @return array
38
+     * @return integer[]
39 39
      */
40 40
     public function register()
41 41
     {
Please login to merge, or discard this patch.
Braces   +5 added lines, -4 removed lines patch added patch discarded remove patch
@@ -30,8 +30,7 @@  discard block
 block discarded – undo
30 30
 use PHP_CodeSniffer\Sniffs\Sniff;
31 31
 use PHP_CodeSniffer\Files\File;
32 32
 
33
-class UppercaseLogicalOperatorOrSniff implements Sniff
34
-{
33
+class UppercaseLogicalOperatorOrSniff implements Sniff {
35 34
     /**
36 35
      * Returns an array of tokens this test wants to listen for: literal and symbolic operators or.
37 36
      *
@@ -64,13 +63,15 @@  discard block
 block discarded – undo
64 63
         $operator_string = $operator_token['content'];
65 64
         $operator_code = $operator_token['code'];
66 65
 
67
-        if ($operator_code == T_BOOLEAN_OR) {
66
+        if ($operator_code == T_BOOLEAN_OR)
67
+        {
68 68
             $error_message = 'Logical operator "' . $operator_string
69 69
                 . '" is prohibited; use "OR" instead';
70 70
             $phpcsFile->addError($error_message, $stackPtr, 'UseOf||InsteadOfOR');
71 71
         }
72 72
         // it is literal, if it is not symbolic
73
-        else if ($operator_string !== strtoupper($operator_string)) {
73
+        else if ($operator_string !== strtoupper($operator_string))
74
+        {
74 75
             $error_message = 'Logical operator should be in upper case;'
75 76
                 . ' use "' . strtoupper($operator_string)
76 77
                 . '" instead of "' . $operator_string . '"';
Please login to merge, or discard this patch.
build/CodeIgniter/Sniffs/Strings/DoubleQuoteUsageSniff.php 2 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -87,7 +87,7 @@  discard block
 block discarded – undo
87 87
 	 * @param string               $dblQtString The double-quoted string content,
88 88
 	 *                                          i.e. without quotes.
89 89
 	 *
90
-	 * @return void
90
+	 * @return boolean
91 91
 	 */
92 92
 	protected function processDoubleQuotedString (File $phpcsFile, $stackPtr, $dblQtString)
93 93
 	{
@@ -134,7 +134,7 @@  discard block
 block discarded – undo
134 134
 	 * @param string               $sglQtString The single-quoted string content,
135 135
 	 *                                          i.e. without quotes.
136 136
 	 *
137
-	 * @return void
137
+	 * @return boolean
138 138
 	 */
139 139
 	protected function processSingleQuotedString (File $phpcsFile, $stackPtr, $sglQtString)
140 140
 	{
Please login to merge, or discard this patch.
Braces   +95 added lines, -46 removed lines patch added patch discarded remove patch
@@ -35,8 +35,7 @@  discard block
 block discarded – undo
35 35
  * @license   http://thomas.ernest.fr/developement/php_cs/licence GNU General Public License
36 36
  * @link      http://pear.php.net/package/PHP_CodeSniffer
37 37
  */
38
-class VariableUsageSniff implements Sniff
39
-{
38
+class VariableUsageSniff implements Sniff {
40 39
 	/**
41 40
 	 * Returns an array of tokens this test wants to listen for.
42 41
 	 *
@@ -70,9 +69,12 @@  discard block
 block discarded – undo
70 69
 		// makes sure that it is about a double quote string,
71 70
 		// since variables are not parsed out of double quoted string
72 71
 		$openDblQtStr = substr($string, 0, 1);
73
-		if (0 === strcmp($openDblQtStr, '"')) {
72
+		if (0 === strcmp($openDblQtStr, '"'))
73
+		{
74 74
 			$this->processDoubleQuotedString($phpcsFile, $stackPtr, $string);
75
-		} else if (0 === strcmp($openDblQtStr, "'")) {
75
+		}
76
+		else if (0 === strcmp($openDblQtStr, "'"))
77
+		{
76 78
 			$this->processSingleQuotedString($phpcsFile, $stackPtr, $string);
77 79
 		}
78 80
 	}//end process()
@@ -95,25 +97,34 @@  discard block
 block discarded – undo
95 97
 		$strTokens = token_get_all('<?php '.$dblQtString);
96 98
 		$strPtr = 1; // skip php opening tag added by ourselves
97 99
 		$requireDblQuotes = FALSE;
98
-		while ($strPtr < count($strTokens)) {
100
+		while ($strPtr < count($strTokens))
101
+		{
99 102
 			$strToken = $strTokens[$strPtr];
100
-			if (is_array($strToken)) {
101
-				if (in_array($strToken[0], array(T_DOLLAR_OPEN_CURLY_BRACES, T_CURLY_OPEN))) {
103
+			if (is_array($strToken))
104
+			{
105
+				if (in_array($strToken[0], array(T_DOLLAR_OPEN_CURLY_BRACES, T_CURLY_OPEN)))
106
+				{
102 107
 					$strPtr++;
103
-					try {
108
+					try
109
+					{
104 110
 						$this->_parseVariable($strTokens, $strPtr);
105
-					} catch (Exception $err) {
111
+					}
112
+					catch (Exception $err)
113
+					{
106 114
 						$error = 'There is no variable, object nor array between curly braces. Please use the escape char for $ or {.';
107 115
 						$phpcsFile->addError($error, $stackPtr);
108 116
 					}
109 117
 					$variableFound = TRUE;
110
-					if ('}' !== $strTokens[$strPtr]) {
118
+					if ('}' !== $strTokens[$strPtr])
119
+					{
111 120
 						$error = 'There is no matching closing curly brace.';
112 121
 						$phpcsFile->addError($error, $stackPtr);
113 122
 					}
114 123
 					// don't move forward, since it will be done in the main loop
115 124
 					// $strPtr++;
116
-				} else if (T_VARIABLE === $strToken[0]) {
125
+				}
126
+				else if (T_VARIABLE === $strToken[0])
127
+				{
117 128
 					$variableFound = TRUE;
118 129
 					$error = "Variable {$strToken[1]} in double-quoted strings should be enclosed with curly braces. Please consider {{$strToken[1]}}";
119 130
 					$phpcsFile->addError($error, $stackPtr);
@@ -141,10 +152,13 @@  discard block
 block discarded – undo
141 152
 		$variableFound = FALSE;
142 153
 		$strTokens = token_get_all('<?php '.$sglQtString);
143 154
 		$strPtr = 1; // skip php opening tag added by ourselves
144
-		while ($strPtr < count($strTokens)) {
155
+		while ($strPtr < count($strTokens))
156
+		{
145 157
 			$strToken = $strTokens[$strPtr];
146
-			if (is_array($strToken)) {
147
-				if (T_VARIABLE === $strToken[0]) {
158
+			if (is_array($strToken))
159
+			{
160
+				if (T_VARIABLE === $strToken[0])
161
+				{
148 162
 					$error = "Variables like {$strToken[1]} should be in double-quoted strings only.";
149 163
 					$phpcsFile->addError($error, $stackPtr);
150 164
 				}
@@ -173,25 +187,34 @@  discard block
 block discarded – undo
173 187
 	 */
174 188
 	private function _parseVariable ($strTokens, &$strPtr)
175 189
 	{
176
-		if ( ! in_array($strTokens[$strPtr][0], array(T_VARIABLE, T_STRING_VARNAME))) {
190
+		if ( ! in_array($strTokens[$strPtr][0], array(T_VARIABLE, T_STRING_VARNAME)))
191
+		{
177 192
 			throw new Exception ('Expected variable name.');
178 193
 		}
179 194
 		$var = $strTokens[$strPtr][1];
180 195
 		$strPtr++;
181 196
 		$startStrPtr = $strPtr;
182
-		try {
197
+		try
198
+		{
183 199
 			$attr = $this->_parseObjectAttribute($strTokens, $strPtr);
184 200
 			return array ('obj' => $var, 'attr' => $attr);
185
-		} catch (Exception $err) {
186
-			if ($strPtr !== $startStrPtr) {
201
+		}
202
+		catch (Exception $err)
203
+		{
204
+			if ($strPtr !== $startStrPtr)
205
+			{
187 206
 				throw $err;
188 207
 			}
189 208
 		}
190
-		try {
209
+		try
210
+		{
191 211
 			$idx = $this->_parseArrayIndexes($strTokens, $strPtr);
192 212
 			return array ('arr' => $var, 'idx' => $idx);
193
-		} catch (Exception $err) {
194
-			if ($strPtr !== $startStrPtr) {
213
+		}
214
+		catch (Exception $err)
215
+		{
216
+			if ($strPtr !== $startStrPtr)
217
+			{
195 218
 				throw $err;
196 219
 			}
197 220
 		}
@@ -217,29 +240,39 @@  discard block
 block discarded – undo
217 240
 	 */
218 241
 	private function _parseObjectAttribute ($strTokens, &$strPtr)
219 242
 	{
220
-		if (T_OBJECT_OPERATOR !== $strTokens[$strPtr][0]) {
243
+		if (T_OBJECT_OPERATOR !== $strTokens[$strPtr][0])
244
+		{
221 245
 			throw new Exception ('Expected ->.');
222 246
 		}
223 247
 		$strPtr++;
224
-		if (T_STRING !== $strTokens[$strPtr][0]) {
248
+		if (T_STRING !== $strTokens[$strPtr][0])
249
+		{
225 250
 			throw new Exception ('Expected an object attribute.');
226 251
 		}
227 252
 		$attr = $strTokens[$strPtr][1];
228 253
 		$strPtr++;
229 254
 		$startStrPtr = $strPtr;
230
-		try {
255
+		try
256
+		{
231 257
 			$sub_attr = $this->_parseObjectAttribute($strTokens, $strPtr);
232 258
 			return array ('obj' => $attr, 'attr' => $sub_attr);
233
-		} catch (Exception $err) {
234
-			if ($strPtr !== $startStrPtr) {
259
+		}
260
+		catch (Exception $err)
261
+		{
262
+			if ($strPtr !== $startStrPtr)
263
+			{
235 264
 				throw $err;
236 265
 			}
237 266
 		}
238
-		try {
267
+		try
268
+		{
239 269
 			$idx = $this->_parseArrayIndexes($strTokens, $strPtr);
240 270
 			return array ('arr' => $attr, 'idx' => $idx);
241
-		} catch (Exception $err) {
242
-			if ($strPtr !== $startStrPtr) {
271
+		}
272
+		catch (Exception $err)
273
+		{
274
+			if ($strPtr !== $startStrPtr)
275
+			{
243 276
 				throw $err;
244 277
 			}
245 278
 		}
@@ -263,13 +296,18 @@  discard block
 block discarded – undo
263 296
 	private function _parseArrayIndexes ($strTokens, &$strPtr)
264 297
 	{
265 298
 		$indexes = array($this->_parseArrayIndex($strTokens, $strPtr));
266
-		try {
267
-			while (1) {
299
+		try
300
+		{
301
+			while (1)
302
+			{
268 303
 				$startStrPtr = $strPtr;
269 304
 				$indexes [] = $this->_parseArrayIndex($strTokens, $strPtr);
270 305
 			}
271
-		} catch (Exception $err) {
272
-			if (0 !== ($strPtr - $startStrPtr)) {
306
+		}
307
+		catch (Exception $err)
308
+		{
309
+			if (0 !== ($strPtr - $startStrPtr))
310
+			{
273 311
 				throw $err;
274 312
 			}
275 313
 			return $indexes;
@@ -292,16 +330,19 @@  discard block
 block discarded – undo
292 330
 	 */
293 331
 	private function _parseArrayIndex ($strTokens, &$strPtr)
294 332
 	{
295
-		if ('[' !== $strTokens[$strPtr]) {
333
+		if ('[' !== $strTokens[$strPtr])
334
+		{
296 335
 			throw new Exception ('Expected [.');
297 336
 		}
298 337
 		$strPtr++;
299
-		if (! in_array($strTokens[$strPtr][0], array(T_CONSTANT_ENCAPSED_STRING, T_LNUMBER))) {
338
+		if (! in_array($strTokens[$strPtr][0], array(T_CONSTANT_ENCAPSED_STRING, T_LNUMBER)))
339
+		{
300 340
 			throw new Exception ('Expected an array index.');
301 341
 		}
302 342
 		$index = $strTokens[$strPtr][1];
303 343
 		$strPtr++;
304
-		if (']' !== $strTokens[$strPtr]) {
344
+		if (']' !== $strTokens[$strPtr])
345
+		{
305 346
 			throw new Exception ('Expected ].');
306 347
 		}
307 348
 		$strPtr++;
@@ -325,8 +366,7 @@  discard block
 block discarded – undo
325 366
  * @license   http://thomas.ernest.fr/developement/php_cs/licence GNU General Public License
326 367
  * @link      http://pear.php.net/package/PHP_CodeSniffer
327 368
  */
328
-class DoubleQuoteUsageSniff extends VariableUsageSniff
329
-{
369
+class DoubleQuoteUsageSniff extends VariableUsageSniff {
330 370
     /**
331 371
      * Returns an array of tokens this test wants to listen for.
332 372
      *
@@ -361,9 +401,12 @@  discard block
 block discarded – undo
361 401
         // clean the enclosing quotes
362 402
         $qtString = substr($qtString, 1, strlen($qtString) - 1 - 1);
363 403
 
364
-        if (0 === strcmp($open_qt_str, '"')) {
404
+        if (0 === strcmp($open_qt_str, '"'))
405
+        {
365 406
             $this->processDoubleQuotedString($phpcsFile, $stackPtr, $qtString);
366
-        } else if (0 === strcmp($open_qt_str, "'")) {
407
+        }
408
+        else if (0 === strcmp($open_qt_str, "'"))
409
+        {
367 410
             $this->processSingleQuotedString($phpcsFile, $stackPtr, $qtString);
368 411
         }
369 412
     }//end process()
@@ -393,7 +436,8 @@  discard block
 block discarded – undo
393 436
         ) {
394 437
             $error = 'Single-quoted strings should be used unless it contains variables, special chars like \n or single quotes.';
395 438
             $phpcsFile->addError($error, $stackPtr);
396
-        } else if (false !== $smpl_qt_at && false !== $dbl_qt_at
439
+        }
440
+        else if (false !== $smpl_qt_at && false !== $dbl_qt_at
397 441
             && false === $has_variable && false === $has_specific_sequence
398 442
         ) {
399 443
             $warning = 'It is encouraged to use a single-quoted string, since it doesn\'t contain any variable nor special char though it mixes single and double quotes.';
@@ -423,7 +467,8 @@  discard block
 block discarded – undo
423 467
         $has_variable = parent::processSingleQuotedString($phpcsFile, $stackPtr, "'".$qtString."'");
424 468
         $dbl_qt_at = strpos($qtString, '"');
425 469
         $smpl_qt_at = strpos($qtString, "'");
426
-        if (false === $has_variable && false !== $smpl_qt_at && false === $dbl_qt_at) {
470
+        if (false === $has_variable && false !== $smpl_qt_at && false === $dbl_qt_at)
471
+        {
427 472
             $warning = 'You may also use double-quoted strings if the string contains single quotes, so you do not have to use escape characters.';
428 473
             $phpcsFile->addWarning($warning, $stackPtr);
429 474
         }
@@ -445,14 +490,18 @@  discard block
 block discarded – undo
445 490
     {
446 491
         $hasSpecificSequence = FALSE;
447 492
         $specialMeaningStrs = array('\n', '\r', '\t', '\v', '\f');
448
-        foreach ($specialMeaningStrs as $splStr) {
449
-            if (FALSE !== strpos($string, $splStr)) {
493
+        foreach ($specialMeaningStrs as $splStr)
494
+        {
495
+            if (FALSE !== strpos($string, $splStr))
496
+            {
450 497
                 $hasSpecificSequence = TRUE;
451 498
             }
452 499
         }
453 500
         $specialMeaningPtrns = array('\[0-7]{1,3}', '\x[0-9A-Fa-f]{1,2}');
454
-        foreach ($specialMeaningPtrns as $splPtrn) {
455
-            if (1 === preg_match("/{$splPtrn}/", $string)) {
501
+        foreach ($specialMeaningPtrns as $splPtrn)
502
+        {
503
+            if (1 === preg_match("/{$splPtrn}/", $string))
504
+            {
456 505
                 $hasSpecificSequence = TRUE;
457 506
             }
458 507
         }
Please login to merge, or discard this patch.
build/CodeIgniter/Sniffs/WhiteSpace/DisallowSpaceIndentSniff.php 2 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -48,7 +48,7 @@
 block discarded – undo
48 48
     /**
49 49
      * Returns an array of tokens this test wants to listen for.
50 50
      *
51
-     * @return array
51
+     * @return integer[]
52 52
      */
53 53
     public function register()
54 54
     {
Please login to merge, or discard this patch.
Braces   +5 added lines, -4 removed lines patch added patch discarded remove patch
@@ -30,8 +30,7 @@  discard block
 block discarded – undo
30 30
 use PHP_CodeSniffer\Sniffs\Sniff;
31 31
 use PHP_CodeSniffer\Files\File;
32 32
 
33
-class DisallowSpaceIndentSniff implements Sniff
34
-{
33
+class DisallowSpaceIndentSniff implements Sniff {
35 34
 
36 35
     /**
37 36
      * A list of tokenizers this sniff supports.
@@ -71,11 +70,13 @@  discard block
 block discarded – undo
71 70
 
72 71
         // Make sure this is whitespace used for indentation.
73 72
         $line = $tokens[$stackPtr]['line'];
74
-        if ($stackPtr > 0 && $tokens[($stackPtr - 1)]['line'] === $line) {
73
+        if ($stackPtr > 0 && $tokens[($stackPtr - 1)]['line'] === $line)
74
+        {
75 75
             return;
76 76
         }
77 77
 
78
-        if (strpos($tokens[$stackPtr]['content'], " ") !== false) {
78
+        if (strpos($tokens[$stackPtr]['content'], " ") !== false)
79
+        {
79 80
             $error = 'Tabs must be used to indent lines; spaces are not allowed for code indentation';
80 81
             $phpcsFile->addError($error, $stackPtr, 'SpacesUsedForIndentation');
81 82
         }
Please login to merge, or discard this patch.
CodeIgniter/Sniffs/WhiteSpace/DisallowWitheSpaceAroundPhpTagsSniff.php 2 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -37,7 +37,7 @@
 block discarded – undo
37 37
     /**
38 38
      * Returns an array of tokens this test wants to listen for.
39 39
      *
40
-     * @return array
40
+     * @return integer[]
41 41
      */
42 42
     public function register()
43 43
     {
Please login to merge, or discard this patch.
Braces   +10 added lines, -6 removed lines patch added patch discarded remove patch
@@ -31,8 +31,7 @@  discard block
 block discarded – undo
31 31
 use PHP_CodeSniffer\Sniffs\Sniff;
32 32
 use PHP_CodeSniffer\Files\File;
33 33
 
34
-class DisallowWitheSpaceAroundPhpTagsSniff implements Sniff
35
-{
34
+class DisallowWitheSpaceAroundPhpTagsSniff implements Sniff {
36 35
 
37 36
     /**
38 37
      * Returns an array of tokens this test wants to listen for.
@@ -65,16 +64,20 @@  discard block
 block discarded – undo
65 64
         $php_tag_token = $tokens[$stackPtr];
66 65
         $php_tag_code = $php_tag_token['code'];
67 66
 
68
-        if (T_OPEN_TAG === $php_tag_code) {
67
+        if (T_OPEN_TAG === $php_tag_code)
68
+        {
69 69
             // opening php tag should be the first token.
70 70
             // any whitespace beofre an opening php tag is tokenized
71 71
             // as T_INLINE_HTML, so no need to check the content of the token.
72 72
             $isFirst = 0 === $stackPtr;
73
-            if ( ! $isFirst) {
73
+            if ( ! $isFirst)
74
+            {
74 75
                 $error = 'Any char before the opening PHP tag is prohibited. Please remove newline or indentation before the opening PHP tag.';
75 76
                 $phpcsFile->addError($error, $stackPtr);
76 77
             }
77
-        } else {
78
+        }
79
+        else
80
+        {
78 81
             // if (T_CLOSE_TAG === $php_tag_code)
79 82
             // closing php tag should be the last token
80 83
             // and it must not contain any whitespace.
@@ -82,7 +85,8 @@  discard block
 block discarded – undo
82 85
             $isLast = count($tokens) - 1 === $stackPtr;
83 86
             // both of the two closing php tags contains 2 chars exactly.
84 87
             $containsEndTagOnly = strlen($php_tag_string) > 2;
85
-            if ( ! $isLast || ! $containsEndTagOnly ) {
88
+            if ( ! $isLast || ! $containsEndTagOnly )
89
+            {
86 90
                 $error = 'Any char after the closing PHP tag is prohibited. Please removes newline or spaces after the closing PHP tag.';
87 91
                 $phpcsFile->addError($error, $stackPtr);
88 92
             }
Please login to merge, or discard this patch.