Completed
Branch develop (9c1dc5)
by Timothy
07:15
created
build/CodeIgniter/Sniffs/Commenting/InlineCommentSniff.php 5 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.
Indentation   +149 added lines, -149 removed lines patch added patch discarded remove patch
@@ -32,155 +32,155 @@
 block discarded – undo
32 32
 
33 33
 class InlineCommentSniff implements Sniff
34 34
 {
35
-    /**
36
-     * @var int Limit defining long comments.
37
-     * Long comments count $longCommentLimit or more lines.
38
-     */
39
-    public $longCommentLimit = 5;
40
-
41
-    /**
42
-     * Returns an array of tokens this test wants to listen for.
43
-     *
44
-     * @return array
45
-     */
46
-    public function register()
47
-    {
48
-        return array(
49
-            T_COMMENT
50
-        );
51
-    }//end register()
52
-
53
-    /**
54
-     * Processes this test, when one of its tokens is encountered.
55
-     *
56
-     * @param File $phpcsFile The current file being scanned.
57
-     * @param int                  $stackPtr  The position of the current token
58
-     *                                        in the stack passed in $tokens.
59
-     *
60
-     * @return void
61
-     */
62
-    public function process(File $phpcsFile, $stackPtr)
63
-    {
64
-        $tokens = $phpcsFile->getTokens();
65
-
66
-        // keep testing only if it's about the first comment of the block
67
-        $previousCommentPtr = $phpcsFile->findPrevious($tokens[$stackPtr]['code'], $stackPtr - 1);
68
-        if ($tokens[$previousCommentPtr]['line'] !== $tokens[$stackPtr]['line'] - 1) {
69
-            if (TRUE !== $this->_checkCommentStyle($phpcsFile, $stackPtr)) {
70
-                return;
71
-            }
72
-
73
-            $commentLines = $this->_getCommentBlock($phpcsFile, $stackPtr);
74
-
75
-            if (count($commentLines) >= $this->longCommentLimit) {
76
-                $this->_checkBlankLinesAroundLongComment($phpcsFile, $commentLines);
77
-            }
78
-        }
79
-    }//end process()
80
-
81
-
82
-    /**
83
-     * Add error to $phpcsFile, if comment pointed by $stackPtr doesn't start
84
-     * with '//'.
85
-     *
86
-     * @param File $phpcsFile The current file being scanned.
87
-     * @param int                  $stackPtr  The position of the current token
88
-     *                                        that has to be a comment.
89
-     *
90
-     * @return bool TRUE if the content of the token pointed by $stackPtr starts
91
-     *              with //, FALSE if an error was added to $phpcsFile.
92
-     */
93
-    private function _checkCommentStyle(File $phpcsFile, $stackPtr)
94
-    {
95
-        $tokens = $phpcsFile->getTokens();
96
-        if ($tokens[$stackPtr]['content']{0} === '#') {
97
-            $error  = 'Perl-style comments are not allowed; use "// Comment" or DocBlock comments instead';
98
-            $phpcsFile->addError($error, $stackPtr, 'WrongStyle');
99
-            return FALSE;
100
-        } else if (substr($tokens[$stackPtr]['content'], 0, 2) === '/*'
101
-            || $tokens[$stackPtr]['content']{0} === '*'
102
-        ) {
103
-            $error  = 'Multi lines comments are not allowed; use "// Comment" DocBlock comments instead';
104
-            $phpcsFile->addError($error, $stackPtr, 'WrongStyle');
105
-            return FALSE;
106
-        } else if (substr($tokens[$stackPtr]['content'], 0, 2) !== '//') {
107
-            $error  = 'Use single line or DocBlock comments within code';
108
-            $phpcsFile->addError($error, $stackPtr, 'WrongStyle');
109
-            return FALSE;
110
-        }
111
-        return TRUE;
112
-    }//_checkCommentStyle()
113
-
114
-
115
-    /**
116
-     * Gather into an array all comment lines to which $stackPtr belongs.
117
-     *
118
-     * @param File $phpcsFile The current file being scanned.
119
-     * @param int                  $stackPtr  Pointer to the first comment line.
120
-     *
121
-     * @return type array Pointers to tokens making up the comment block.
122
-     */
123
-    private function _getCommentBlock(File $phpcsFile, $stackPtr)
124
-    {
125
-        $tokens = $phpcsFile->getTokens();
126
-        $commentLines = array($stackPtr);
127
-        $nextComment  = $stackPtr;
128
-        $lastLine     = $tokens[$stackPtr]['line'];
129
-
130
-        while (($nextComment = $phpcsFile->findNext($tokens[$stackPtr]['code'], ($nextComment + 1), null, false)) !== false) {
131
-            if (($tokens[$nextComment]['line'] - 1) !== $lastLine) {
132
-                // Not part of the block.
133
-                break;
134
-            }
135
-
136
-            $lastLine       = $tokens[$nextComment]['line'];
137
-            $commentLines[] = $nextComment;
138
-        }
139
-
140
-        return $commentLines;
141
-    }//_getCommentBlock()
142
-
143
-
144
-    /**
145
-     * Add errors to $phpcsFile, if $commentLines isn't enclosed with blank lines.
146
-     *
147
-     * @param File $phpcsFile    The current file being scanned.
148
-     * @param array                $commentLines Lines of the comment block being checked.
149
-     *
150
-     * @return bool TRUE if $commentLines is enclosed with at least a blank line
151
-     * before and after, FALSE otherwise.
152
-     */
153
-    private function _checkBlankLinesAroundLongComment(File $phpcsFile, array $commentLines)
154
-    {
155
-        $hasBlankLinesAround = TRUE;
156
-        $tokens = $phpcsFile->getTokens();
157
-
158
-        // check blank line before the long comment
159
-        $firstCommentPtr = reset($commentLines);
160
-        $firstPreviousSpacePtr = $firstCommentPtr - 1;
161
-        while (T_WHITESPACE === $tokens[$firstPreviousSpacePtr]['code'] && $firstPreviousSpacePtr > 0) {
162
-            $firstPreviousSpacePtr--;
163
-        }
164
-        if ($tokens[$firstPreviousSpacePtr]['line'] >= $tokens[$firstCommentPtr]['line'] - 1) {
165
-            $error  = "Please add a blank line before comments counting more than {$this->longCommentLimit} lines.";
166
-            $phpcsFile->addError($error, $firstCommentPtr, 'LongCommentWithoutSpacing');
167
-            $hasBlankLinesAround = FALSE;
168
-        }
169
-
170
-        // check blank line after the long comment
171
-        $lastCommentPtr = end($commentLines);
172
-        $lastNextSpacePtr = $lastCommentPtr + 1;
173
-        while (T_WHITESPACE === $tokens[$lastNextSpacePtr]['code'] && $lastNextSpacePtr < count($tokens)) {
174
-            $lastNextSpacePtr++;
175
-        }
176
-        if ($tokens[$lastNextSpacePtr]['line'] <= $tokens[$lastCommentPtr]['line'] + 1) {
177
-            $error  = "Please add a blank line after comments counting more than {$this->longCommentLimit} lines.";
178
-            $phpcsFile->addError($error, $lastCommentPtr, 'LongCommentWithoutSpacing');
179
-            $hasBlankLinesAround = FALSE;
180
-        }
181
-
182
-        return $hasBlankLinesAround;
183
-    }//end _checkBlanksAroundLongComment()
35
+	/**
36
+	 * @var int Limit defining long comments.
37
+	 * Long comments count $longCommentLimit or more lines.
38
+	 */
39
+	public $longCommentLimit = 5;
40
+
41
+	/**
42
+	 * Returns an array of tokens this test wants to listen for.
43
+	 *
44
+	 * @return array
45
+	 */
46
+	public function register()
47
+	{
48
+		return array(
49
+			T_COMMENT
50
+		);
51
+	}//end register()
52
+
53
+	/**
54
+	 * Processes this test, when one of its tokens is encountered.
55
+	 *
56
+	 * @param File $phpcsFile The current file being scanned.
57
+	 * @param int                  $stackPtr  The position of the current token
58
+	 *                                        in the stack passed in $tokens.
59
+	 *
60
+	 * @return void
61
+	 */
62
+	public function process(File $phpcsFile, $stackPtr)
63
+	{
64
+		$tokens = $phpcsFile->getTokens();
65
+
66
+		// keep testing only if it's about the first comment of the block
67
+		$previousCommentPtr = $phpcsFile->findPrevious($tokens[$stackPtr]['code'], $stackPtr - 1);
68
+		if ($tokens[$previousCommentPtr]['line'] !== $tokens[$stackPtr]['line'] - 1) {
69
+			if (TRUE !== $this->_checkCommentStyle($phpcsFile, $stackPtr)) {
70
+				return;
71
+			}
72
+
73
+			$commentLines = $this->_getCommentBlock($phpcsFile, $stackPtr);
74
+
75
+			if (count($commentLines) >= $this->longCommentLimit) {
76
+				$this->_checkBlankLinesAroundLongComment($phpcsFile, $commentLines);
77
+			}
78
+		}
79
+	}//end process()
80
+
81
+
82
+	/**
83
+	 * Add error to $phpcsFile, if comment pointed by $stackPtr doesn't start
84
+	 * with '//'.
85
+	 *
86
+	 * @param File $phpcsFile The current file being scanned.
87
+	 * @param int                  $stackPtr  The position of the current token
88
+	 *                                        that has to be a comment.
89
+	 *
90
+	 * @return bool TRUE if the content of the token pointed by $stackPtr starts
91
+	 *              with //, FALSE if an error was added to $phpcsFile.
92
+	 */
93
+	private function _checkCommentStyle(File $phpcsFile, $stackPtr)
94
+	{
95
+		$tokens = $phpcsFile->getTokens();
96
+		if ($tokens[$stackPtr]['content']{0} === '#') {
97
+			$error  = 'Perl-style comments are not allowed; use "// Comment" or DocBlock comments instead';
98
+			$phpcsFile->addError($error, $stackPtr, 'WrongStyle');
99
+			return FALSE;
100
+		} else if (substr($tokens[$stackPtr]['content'], 0, 2) === '/*'
101
+			|| $tokens[$stackPtr]['content']{0} === '*'
102
+		) {
103
+			$error  = 'Multi lines comments are not allowed; use "// Comment" DocBlock comments instead';
104
+			$phpcsFile->addError($error, $stackPtr, 'WrongStyle');
105
+			return FALSE;
106
+		} else if (substr($tokens[$stackPtr]['content'], 0, 2) !== '//') {
107
+			$error  = 'Use single line or DocBlock comments within code';
108
+			$phpcsFile->addError($error, $stackPtr, 'WrongStyle');
109
+			return FALSE;
110
+		}
111
+		return TRUE;
112
+	}//_checkCommentStyle()
113
+
114
+
115
+	/**
116
+	 * Gather into an array all comment lines to which $stackPtr belongs.
117
+	 *
118
+	 * @param File $phpcsFile The current file being scanned.
119
+	 * @param int                  $stackPtr  Pointer to the first comment line.
120
+	 *
121
+	 * @return type array Pointers to tokens making up the comment block.
122
+	 */
123
+	private function _getCommentBlock(File $phpcsFile, $stackPtr)
124
+	{
125
+		$tokens = $phpcsFile->getTokens();
126
+		$commentLines = array($stackPtr);
127
+		$nextComment  = $stackPtr;
128
+		$lastLine     = $tokens[$stackPtr]['line'];
129
+
130
+		while (($nextComment = $phpcsFile->findNext($tokens[$stackPtr]['code'], ($nextComment + 1), null, false)) !== false) {
131
+			if (($tokens[$nextComment]['line'] - 1) !== $lastLine) {
132
+				// Not part of the block.
133
+				break;
134
+			}
135
+
136
+			$lastLine       = $tokens[$nextComment]['line'];
137
+			$commentLines[] = $nextComment;
138
+		}
139
+
140
+		return $commentLines;
141
+	}//_getCommentBlock()
142
+
143
+
144
+	/**
145
+	 * Add errors to $phpcsFile, if $commentLines isn't enclosed with blank lines.
146
+	 *
147
+	 * @param File $phpcsFile    The current file being scanned.
148
+	 * @param array                $commentLines Lines of the comment block being checked.
149
+	 *
150
+	 * @return bool TRUE if $commentLines is enclosed with at least a blank line
151
+	 * before and after, FALSE otherwise.
152
+	 */
153
+	private function _checkBlankLinesAroundLongComment(File $phpcsFile, array $commentLines)
154
+	{
155
+		$hasBlankLinesAround = TRUE;
156
+		$tokens = $phpcsFile->getTokens();
157
+
158
+		// check blank line before the long comment
159
+		$firstCommentPtr = reset($commentLines);
160
+		$firstPreviousSpacePtr = $firstCommentPtr - 1;
161
+		while (T_WHITESPACE === $tokens[$firstPreviousSpacePtr]['code'] && $firstPreviousSpacePtr > 0) {
162
+			$firstPreviousSpacePtr--;
163
+		}
164
+		if ($tokens[$firstPreviousSpacePtr]['line'] >= $tokens[$firstCommentPtr]['line'] - 1) {
165
+			$error  = "Please add a blank line before comments counting more than {$this->longCommentLimit} lines.";
166
+			$phpcsFile->addError($error, $firstCommentPtr, 'LongCommentWithoutSpacing');
167
+			$hasBlankLinesAround = FALSE;
168
+		}
169
+
170
+		// check blank line after the long comment
171
+		$lastCommentPtr = end($commentLines);
172
+		$lastNextSpacePtr = $lastCommentPtr + 1;
173
+		while (T_WHITESPACE === $tokens[$lastNextSpacePtr]['code'] && $lastNextSpacePtr < count($tokens)) {
174
+			$lastNextSpacePtr++;
175
+		}
176
+		if ($tokens[$lastNextSpacePtr]['line'] <= $tokens[$lastCommentPtr]['line'] + 1) {
177
+			$error  = "Please add a blank line after comments counting more than {$this->longCommentLimit} lines.";
178
+			$phpcsFile->addError($error, $lastCommentPtr, 'LongCommentWithoutSpacing');
179
+			$hasBlankLinesAround = FALSE;
180
+		}
181
+
182
+		return $hasBlankLinesAround;
183
+	}//end _checkBlanksAroundLongComment()
184 184
 
185 185
 }//end class
186 186
 
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -94,17 +94,17 @@  discard block
 block discarded – undo
94 94
     {
95 95
         $tokens = $phpcsFile->getTokens();
96 96
         if ($tokens[$stackPtr]['content']{0} === '#') {
97
-            $error  = 'Perl-style comments are not allowed; use "// Comment" or DocBlock comments instead';
97
+            $error = 'Perl-style comments are not allowed; use "// Comment" or DocBlock comments instead';
98 98
             $phpcsFile->addError($error, $stackPtr, 'WrongStyle');
99 99
             return FALSE;
100 100
         } else if (substr($tokens[$stackPtr]['content'], 0, 2) === '/*'
101 101
             || $tokens[$stackPtr]['content']{0} === '*'
102 102
         ) {
103
-            $error  = 'Multi lines comments are not allowed; use "// Comment" DocBlock comments instead';
103
+            $error = 'Multi lines comments are not allowed; use "// Comment" DocBlock comments instead';
104 104
             $phpcsFile->addError($error, $stackPtr, 'WrongStyle');
105 105
             return FALSE;
106 106
         } else if (substr($tokens[$stackPtr]['content'], 0, 2) !== '//') {
107
-            $error  = 'Use single line or DocBlock comments within code';
107
+            $error = 'Use single line or DocBlock comments within code';
108 108
             $phpcsFile->addError($error, $stackPtr, 'WrongStyle');
109 109
             return FALSE;
110 110
         }
@@ -162,7 +162,7 @@  discard block
 block discarded – undo
162 162
             $firstPreviousSpacePtr--;
163 163
         }
164 164
         if ($tokens[$firstPreviousSpacePtr]['line'] >= $tokens[$firstCommentPtr]['line'] - 1) {
165
-            $error  = "Please add a blank line before comments counting more than {$this->longCommentLimit} lines.";
165
+            $error = "Please add a blank line before comments counting more than {$this->longCommentLimit} lines.";
166 166
             $phpcsFile->addError($error, $firstCommentPtr, 'LongCommentWithoutSpacing');
167 167
             $hasBlankLinesAround = FALSE;
168 168
         }
@@ -174,7 +174,7 @@  discard block
 block discarded – undo
174 174
             $lastNextSpacePtr++;
175 175
         }
176 176
         if ($tokens[$lastNextSpacePtr]['line'] <= $tokens[$lastCommentPtr]['line'] + 1) {
177
-            $error  = "Please add a blank line after comments counting more than {$this->longCommentLimit} lines.";
177
+            $error = "Please add a blank line after comments counting more than {$this->longCommentLimit} lines.";
178 178
             $phpcsFile->addError($error, $lastCommentPtr, 'LongCommentWithoutSpacing');
179 179
             $hasBlankLinesAround = FALSE;
180 180
         }
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.
Upper-Lower-Casing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -127,7 +127,7 @@
 block discarded – undo
127 127
         $nextComment  = $stackPtr;
128 128
         $lastLine     = $tokens[$stackPtr]['line'];
129 129
 
130
-        while (($nextComment = $phpcsFile->findNext($tokens[$stackPtr]['code'], ($nextComment + 1), null, false)) !== false) {
130
+        while (($nextComment = $phpcsFile->findNext($tokens[$stackPtr]['code'], ($nextComment + 1), NULL, FALSE)) !== FALSE) {
131 131
             if (($tokens[$nextComment]['line'] - 1) !== $lastLine) {
132 132
                 // Not part of the block.
133 133
                 break;
Please login to merge, or discard this patch.
build/CodeIgniter/Sniffs/Files/ByteOrderMarkSniff.php 5 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.
Indentation   +60 added lines, -60 removed lines patch added patch discarded remove patch
@@ -32,67 +32,67 @@
 block discarded – undo
32 32
 
33 33
 class ByteOrderMarkSniff implements Sniff
34 34
 {
35
-    /**
36
-     * Returns an array of tokens this test wants to listen for.
37
-     *
38
-     * @return array
39
-     */
40
-    public function register()
41
-    {
42
-        return array( T_OPEN_TAG );
43
-    }//end register()
35
+	/**
36
+	 * Returns an array of tokens this test wants to listen for.
37
+	 *
38
+	 * @return array
39
+	 */
40
+	public function register()
41
+	{
42
+		return array( T_OPEN_TAG );
43
+	}//end register()
44 44
 
45
-    /**
46
-     * List of supported BOM definitions.
47
-     *
48
-     * Use encoding names as keys and hex BOM representations as values.
49
-     *
50
-     * @return array
51
-     */
52
-    protected function getBomDefinitions()
53
-    {
54
-        return array(
55
-            'UTF-8'       => 'efbbbf',
56
-            'UTF-16 (BE)' => 'feff',
57
-            'UTF-16 (LE)' => 'fffe',
58
-            'UTF-32 (BE)' => '0000feff',
59
-            'UTF-32 (LE)' => 'fffe0000'
60
-        );
61
-    }//end getBomDefinitions()
45
+	/**
46
+	 * List of supported BOM definitions.
47
+	 *
48
+	 * Use encoding names as keys and hex BOM representations as values.
49
+	 *
50
+	 * @return array
51
+	 */
52
+	protected function getBomDefinitions()
53
+	{
54
+		return array(
55
+			'UTF-8'       => 'efbbbf',
56
+			'UTF-16 (BE)' => 'feff',
57
+			'UTF-16 (LE)' => 'fffe',
58
+			'UTF-32 (BE)' => '0000feff',
59
+			'UTF-32 (LE)' => 'fffe0000'
60
+		);
61
+	}//end getBomDefinitions()
62 62
 
63
-    /**
64
-     * Process tokens.
65
-     *
66
-     * Actually, only proceed when we're at index 0, this should be the only case
67
-     * that will contain BOM. Then check if BOM definition matches what
68
-     * we've found as file's inline HTML. Inline HTML could be longer than just BOM
69
-     * so make sure you test as much as needed.
70
-     *
71
-     * @param File $phpcsFile The current file being scanned.
72
-     * @param int                  $stackPtr  The position of the current token
73
-     *                                        in the stack passed in $tokens.
74
-     *
75
-     * @return void
76
-     */
77
-    public function process(File $phpcsFile, $stackPtr )
78
-    {
79
-        // 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) {
82
-                return;
83
-            }
84
-        }
63
+	/**
64
+	 * Process tokens.
65
+	 *
66
+	 * Actually, only proceed when we're at index 0, this should be the only case
67
+	 * that will contain BOM. Then check if BOM definition matches what
68
+	 * we've found as file's inline HTML. Inline HTML could be longer than just BOM
69
+	 * so make sure you test as much as needed.
70
+	 *
71
+	 * @param File $phpcsFile The current file being scanned.
72
+	 * @param int                  $stackPtr  The position of the current token
73
+	 *                                        in the stack passed in $tokens.
74
+	 *
75
+	 * @return void
76
+	 */
77
+	public function process(File $phpcsFile, $stackPtr )
78
+	{
79
+		// 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) {
82
+				return;
83
+			}
84
+		}
85 85
 
86
-        $tokens = $phpcsFile->getTokens();
87
-        $fileStartString = $tokens[0]['content'];
88
-        foreach ($this->getBomDefinitions() as $bomName => $expectedBomHex) {
89
-            $bomByteLength = strlen($expectedBomHex) / 2;
90
-            $fileStartHex = bin2hex(substr($fileStartString, 0, $bomByteLength));
91
-            if ($fileStartHex === $expectedBomHex) {
92
-                $error = "File contains a $bomName byte order mark (BOM).";
93
-                $phpcsFile->addError($error, $stackPtr);
94
-                break;
95
-            }
96
-        }
97
-    }//end process()
86
+		$tokens = $phpcsFile->getTokens();
87
+		$fileStartString = $tokens[0]['content'];
88
+		foreach ($this->getBomDefinitions() as $bomName => $expectedBomHex) {
89
+			$bomByteLength = strlen($expectedBomHex) / 2;
90
+			$fileStartHex = bin2hex(substr($fileStartString, 0, $bomByteLength));
91
+			if ($fileStartHex === $expectedBomHex) {
92
+				$error = "File contains a $bomName byte order mark (BOM).";
93
+				$phpcsFile->addError($error, $stackPtr);
94
+				break;
95
+			}
96
+		}
97
+	}//end process()
98 98
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -39,7 +39,7 @@  discard block
 block discarded – undo
39 39
      */
40 40
     public function register()
41 41
     {
42
-        return array( T_OPEN_TAG );
42
+        return array(T_OPEN_TAG);
43 43
     }//end register()
44 44
 
45 45
     /**
@@ -74,7 +74,7 @@  discard block
 block discarded – undo
74 74
      *
75 75
      * @return void
76 76
      */
77
-    public function process(File $phpcsFile, $stackPtr )
77
+    public function process(File $phpcsFile, $stackPtr)
78 78
     {
79 79
         // We are only interested if this is the first open tag.
80 80
         if ($stackPtr !== 0) {
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.
Upper-Lower-Casing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -78,7 +78,7 @@
 block discarded – undo
78 78
     {
79 79
         // We are only interested if this is the first open tag.
80 80
         if ($stackPtr !== 0) {
81
-            if ($phpcsFile->findPrevious(T_OPEN_TAG, ($stackPtr - 1)) !== false) {
81
+            if ($phpcsFile->findPrevious(T_OPEN_TAG, ($stackPtr - 1)) !== FALSE) {
82 82
                 return;
83 83
             }
84 84
         }
Please login to merge, or discard this patch.
build/CodeIgniter/Sniffs/Files/Utf8EncodingSniff.php 5 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.
Indentation   +132 added lines, -132 removed lines patch added patch discarded remove patch
@@ -33,74 +33,74 @@  discard block
 block discarded – undo
33 33
 class Utf8EncodingSniff implements Sniff
34 34
 {
35 35
 
36
-    /**
37
-     * Returns an array of tokens this test wants to listen for.
38
-     *
39
-     * @return array
40
-     */
41
-    public function register()
42
-    {
43
-        return array(
44
-            T_OPEN_TAG
45
-        );
46
-
47
-    }//end register()
48
-
49
-
50
-    /**
51
-     * Processes this test, when one of its tokens is encountered.
52
-     *
53
-     * @param File $phpcsFile The current file being scanned.
54
-     * @param int                  $stackPtr  The position of the current token
55
-     *                                        in the stack passed in $tokens.
56
-     *
57
-     * @return void
58
-     */
59
-    public function process(File $phpcsFile, $stackPtr)
60
-    {
61
-        // 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) {
64
-                return;
65
-            }
66
-        }
67
-
68
-        $file_path = $phpcsFile->getFilename();
69
-        $file_name = basename($file_path);
70
-        $file_content = file_get_contents($file_path);
71
-        if (false === mb_check_encoding($file_content, 'UTF-8')) {
72
-            $error = 'File "' . $file_name . '" should be saved with Unicode (UTF-8) encoding.';
73
-            $phpcsFile->addError($error, 0);
74
-        }
75
-        if ( ! self::_checkUtf8W3c($file_content)) {
76
-            $error = 'File "' . $file_name . '" should be saved with Unicode (UTF-8) encoding, but it did not successfully pass the W3C test.';
77
-            $phpcsFile->addError($error, 0);
78
-        }
79
-        if ( ! self::_checkUtf8Rfc3629($file_content)) {
80
-            $error = 'File "' . $file_name . '" should be saved with Unicode (UTF-8) encoding, but it did not meet RFC3629 requirements.';
81
-            $phpcsFile->addError($error, 0);
82
-        }
83
-    }//end process()
84
-
85
-
86
-    /**
87
-     * Checks that the string $content contains only valid UTF-8 chars
88
-     * using W3C's method.
89
-     * Returns true if $content contains only UTF-8 chars, false otherwise.
90
-     *
91
-     * @param string $content String to check.
92
-     *
93
-     * @return bool true if $content contains only UTF-8 chars, false otherwise.
94
-     *
95
-     * @see http://w3.org/International/questions/qa-forms-utf-8.html
96
-     */
97
-    private static function _checkUtf8W3c($content)
98
-    {
99
-        $content_chunks=self::mb_chunk_split($content, 4096, '');
100
-    	foreach($content_chunks as $content_chunk)
36
+	/**
37
+	 * Returns an array of tokens this test wants to listen for.
38
+	 *
39
+	 * @return array
40
+	 */
41
+	public function register()
42
+	{
43
+		return array(
44
+			T_OPEN_TAG
45
+		);
46
+
47
+	}//end register()
48
+
49
+
50
+	/**
51
+	 * Processes this test, when one of its tokens is encountered.
52
+	 *
53
+	 * @param File $phpcsFile The current file being scanned.
54
+	 * @param int                  $stackPtr  The position of the current token
55
+	 *                                        in the stack passed in $tokens.
56
+	 *
57
+	 * @return void
58
+	 */
59
+	public function process(File $phpcsFile, $stackPtr)
60
+	{
61
+		// 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) {
64
+				return;
65
+			}
66
+		}
67
+
68
+		$file_path = $phpcsFile->getFilename();
69
+		$file_name = basename($file_path);
70
+		$file_content = file_get_contents($file_path);
71
+		if (false === mb_check_encoding($file_content, 'UTF-8')) {
72
+			$error = 'File "' . $file_name . '" should be saved with Unicode (UTF-8) encoding.';
73
+			$phpcsFile->addError($error, 0);
74
+		}
75
+		if ( ! self::_checkUtf8W3c($file_content)) {
76
+			$error = 'File "' . $file_name . '" should be saved with Unicode (UTF-8) encoding, but it did not successfully pass the W3C test.';
77
+			$phpcsFile->addError($error, 0);
78
+		}
79
+		if ( ! self::_checkUtf8Rfc3629($file_content)) {
80
+			$error = 'File "' . $file_name . '" should be saved with Unicode (UTF-8) encoding, but it did not meet RFC3629 requirements.';
81
+			$phpcsFile->addError($error, 0);
82
+		}
83
+	}//end process()
84
+
85
+
86
+	/**
87
+	 * Checks that the string $content contains only valid UTF-8 chars
88
+	 * using W3C's method.
89
+	 * Returns true if $content contains only UTF-8 chars, false otherwise.
90
+	 *
91
+	 * @param string $content String to check.
92
+	 *
93
+	 * @return bool true if $content contains only UTF-8 chars, false otherwise.
94
+	 *
95
+	 * @see http://w3.org/International/questions/qa-forms-utf-8.html
96
+	 */
97
+	private static function _checkUtf8W3c($content)
98
+	{
99
+		$content_chunks=self::mb_chunk_split($content, 4096, '');
100
+		foreach($content_chunks as $content_chunk)
101 101
 		{
102 102
 			$preg_result= preg_match(
103
-            '%^(?:
103
+			'%^(?:
104 104
                   [\x09\x0A\x0D\x20-\x7E]            # ASCII
105 105
                 | [\xC2-\xDF][\x80-\xBF]             # non-overlong 2-byte
106 106
                 |  \xE0[\xA0-\xBF][\x80-\xBF]        # excluding overlongs
@@ -110,7 +110,7 @@  discard block
 block discarded – undo
110 110
                 | [\xF1-\xF3][\x80-\xBF]{3}          # planes 4-15
111 111
                 |  \xF4[\x80-\x8F][\x80-\xBF]{2}     # plane 16
112 112
             )*$%xs',
113
-            $content_chunk
113
+			$content_chunk
114 114
 			);
115 115
 			if($preg_result!==1)
116 116
 			{
@@ -119,66 +119,66 @@  discard block
 block discarded – undo
119 119
 
120 120
 		}
121 121
 		return true;
122
-    }//end _checkUtf8W3c()
123
-
124
-    /**
125
-     * Checks that the string $content contains only valid UTF-8 chars
126
-     * using the method described in RFC 3629.
127
-     * Returns true if $content contains only UTF-8 chars, false otherwise.
128
-     *
129
-     * @param string $content String to check.
130
-     *
131
-     * @return bool true if $content contains only UTF-8 chars, false otherwise.
132
-     *
133
-     * @see http://www.php.net/manual/en/function.mb-detect-encoding.php#85294
134
-     */
135
-    private static function _checkUtf8Rfc3629($content)
136
-    {
137
-        $len = strlen($content);
138
-        for ($i = 0; $i < $len; $i++) {
139
-            $c = ord($content[$i]);
140
-            if ($c > 128) {
141
-                if (($c >= 254)) {
142
-                    return false;
143
-                } elseif ($c >= 252) {
144
-                    $bits=6;
145
-                } elseif ($c >= 248) {
146
-                    $bits=5;
147
-                } elseif ($c >= 240) {
148
-                    $bytes = 4;
149
-                } elseif ($c >= 224) {
150
-                    $bytes = 3;
151
-                } elseif ($c >= 192) {
152
-                    $bytes = 2;
153
-                } else {
154
-                    return false;
155
-                } if (($i + $bytes) > $len) {
156
-                    return false;
157
-                } while ($bytes > 1) {
158
-                    $i++;
159
-                    $b = ord($content[$i]);
160
-                    if ($b < 128 || $b > 191) {
161
-                        return false;
162
-                    }
163
-                    $bytes--;
164
-                }
165
-            }
166
-        }
167
-        return true;
168
-    }//_checkUtf8Rfc3629()
122
+	}//end _checkUtf8W3c()
123
+
124
+	/**
125
+	 * Checks that the string $content contains only valid UTF-8 chars
126
+	 * using the method described in RFC 3629.
127
+	 * Returns true if $content contains only UTF-8 chars, false otherwise.
128
+	 *
129
+	 * @param string $content String to check.
130
+	 *
131
+	 * @return bool true if $content contains only UTF-8 chars, false otherwise.
132
+	 *
133
+	 * @see http://www.php.net/manual/en/function.mb-detect-encoding.php#85294
134
+	 */
135
+	private static function _checkUtf8Rfc3629($content)
136
+	{
137
+		$len = strlen($content);
138
+		for ($i = 0; $i < $len; $i++) {
139
+			$c = ord($content[$i]);
140
+			if ($c > 128) {
141
+				if (($c >= 254)) {
142
+					return false;
143
+				} elseif ($c >= 252) {
144
+					$bits=6;
145
+				} elseif ($c >= 248) {
146
+					$bits=5;
147
+				} elseif ($c >= 240) {
148
+					$bytes = 4;
149
+				} elseif ($c >= 224) {
150
+					$bytes = 3;
151
+				} elseif ($c >= 192) {
152
+					$bytes = 2;
153
+				} else {
154
+					return false;
155
+				} if (($i + $bytes) > $len) {
156
+					return false;
157
+				} while ($bytes > 1) {
158
+					$i++;
159
+					$b = ord($content[$i]);
160
+					if ($b < 128 || $b > 191) {
161
+						return false;
162
+					}
163
+					$bytes--;
164
+				}
165
+			}
166
+		}
167
+		return true;
168
+	}//_checkUtf8Rfc3629()
169 169
 
170 170
 	 /**
171
-     * Splits a string to chunks of given size
172
-	 * This helps to avoid segmentation fault errors when large text is given
173
-     * Returns array of strings after splitting
174
-     *
175
-     * @param string $str String to split.
176
-	 * @param int $len number of characters per chunk
177
-     *
178
-     * @return array string array after splitting
179
-     *
180
-     * @see http://php.net/manual/en/function.chunk-split.php
181
-     */
171
+	  * Splits a string to chunks of given size
172
+	  * This helps to avoid segmentation fault errors when large text is given
173
+	  * Returns array of strings after splitting
174
+	  *
175
+	  * @param string $str String to split.
176
+	  * @param int $len number of characters per chunk
177
+	  *
178
+	  * @return array string array after splitting
179
+	  *
180
+	  * @see http://php.net/manual/en/function.chunk-split.php
181
+	  */
182 182
 	private static function mb_chunk_split($str, $len, $glue)
183 183
 	{
184 184
 		if (empty($str)) return false;
@@ -196,14 +196,14 @@  discard block
 block discarded – undo
196 196
 		return $new;
197 197
 	}//mb_chunk_split
198 198
 	/**
199
-     * Supporting function for mb_chunk_split
200
-     *
201
-     * @param string $str
199
+	 * Supporting function for mb_chunk_split
200
+	 *
201
+	 * @param string $str
202
+	 *
203
+	 * @return array
202 204
 	 *
203
-     * @return array
204
-     *
205
-     * @see http://php.net/manual/en/function.chunk-split.php
206
-     */
205
+	 * @see http://php.net/manual/en/function.chunk-split.php
206
+	 */
207 207
 	private static function mbStringToArray ($str)
208 208
 	{
209 209
 		if (empty($str)) return false;
Please login to merge, or discard this patch.
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -96,10 +96,10 @@  discard block
 block discarded – undo
96 96
      */
97 97
     private static function _checkUtf8W3c($content)
98 98
     {
99
-        $content_chunks=self::mb_chunk_split($content, 4096, '');
100
-    	foreach($content_chunks as $content_chunk)
99
+        $content_chunks = self::mb_chunk_split($content, 4096, '');
100
+    	foreach ($content_chunks as $content_chunk)
101 101
 		{
102
-			$preg_result= preg_match(
102
+			$preg_result = preg_match(
103 103
             '%^(?:
104 104
                   [\x09\x0A\x0D\x20-\x7E]            # ASCII
105 105
                 | [\xC2-\xDF][\x80-\xBF]             # non-overlong 2-byte
@@ -112,7 +112,7 @@  discard block
 block discarded – undo
112 112
             )*$%xs',
113 113
             $content_chunk
114 114
 			);
115
-			if($preg_result!==1)
115
+			if ($preg_result !== 1)
116 116
 			{
117 117
 				return false;
118 118
 			}
@@ -141,9 +141,9 @@  discard block
 block discarded – undo
141 141
                 if (($c >= 254)) {
142 142
                     return false;
143 143
                 } elseif ($c >= 252) {
144
-                    $bits=6;
144
+                    $bits = 6;
145 145
                 } elseif ($c >= 248) {
146
-                    $bits=5;
146
+                    $bits = 5;
147 147
                 } elseif ($c >= 240) {
148 148
                     $bytes = 4;
149 149
                 } elseif ($c >= 224) {
@@ -182,14 +182,14 @@  discard block
 block discarded – undo
182 182
 	private static function mb_chunk_split($str, $len, $glue)
183 183
 	{
184 184
 		if (empty($str)) return false;
185
-		$array = self::mbStringToArray ($str);
185
+		$array = self::mbStringToArray($str);
186 186
 		$n = -1;
187 187
 		$new = Array();
188 188
 		foreach ($array as $char) {
189 189
 			$n++;
190
-			if ($n < $len) $new []= $char;
190
+			if ($n < $len) $new [] = $char;
191 191
 			elseif ($n == $len) {
192
-				$new []= $glue . $char;
192
+				$new [] = $glue . $char;
193 193
 				$n = 0;
194 194
 			}
195 195
 		}
@@ -204,7 +204,7 @@  discard block
 block discarded – undo
204 204
      *
205 205
      * @see http://php.net/manual/en/function.chunk-split.php
206 206
      */
207
-	private static function mbStringToArray ($str)
207
+	private static function mbStringToArray($str)
208 208
 	{
209 209
 		if (empty($str)) return false;
210 210
 		$len = mb_strlen($str);
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.
Upper-Lower-Casing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
60 60
     {
61 61
         // We are only interested if this is the first open tag.
62 62
         if ($stackPtr !== 0) {
63
-            if ($phpcsFile->findPrevious(T_OPEN_TAG, ($stackPtr - 1)) !== false) {
63
+            if ($phpcsFile->findPrevious(T_OPEN_TAG, ($stackPtr - 1)) !== FALSE) {
64 64
                 return;
65 65
             }
66 66
         }
@@ -68,7 +68,7 @@  discard block
 block discarded – undo
68 68
         $file_path = $phpcsFile->getFilename();
69 69
         $file_name = basename($file_path);
70 70
         $file_content = file_get_contents($file_path);
71
-        if (false === mb_check_encoding($file_content, 'UTF-8')) {
71
+        if (FALSE === mb_check_encoding($file_content, 'UTF-8')) {
72 72
             $error = 'File "' . $file_name . '" should be saved with Unicode (UTF-8) encoding.';
73 73
             $phpcsFile->addError($error, 0);
74 74
         }
@@ -114,11 +114,11 @@  discard block
 block discarded – undo
114 114
 			);
115 115
 			if($preg_result!==1)
116 116
 			{
117
-				return false;
117
+				return FALSE;
118 118
 			}
119 119
 
120 120
 		}
121
-		return true;
121
+		return TRUE;
122 122
     }//end _checkUtf8W3c()
123 123
 
124 124
     /**
@@ -139,7 +139,7 @@  discard block
 block discarded – undo
139 139
             $c = ord($content[$i]);
140 140
             if ($c > 128) {
141 141
                 if (($c >= 254)) {
142
-                    return false;
142
+                    return FALSE;
143 143
                 } elseif ($c >= 252) {
144 144
                     $bits=6;
145 145
                 } elseif ($c >= 248) {
@@ -151,20 +151,20 @@  discard block
 block discarded – undo
151 151
                 } elseif ($c >= 192) {
152 152
                     $bytes = 2;
153 153
                 } else {
154
-                    return false;
154
+                    return FALSE;
155 155
                 } if (($i + $bytes) > $len) {
156
-                    return false;
156
+                    return FALSE;
157 157
                 } while ($bytes > 1) {
158 158
                     $i++;
159 159
                     $b = ord($content[$i]);
160 160
                     if ($b < 128 || $b > 191) {
161
-                        return false;
161
+                        return FALSE;
162 162
                     }
163 163
                     $bytes--;
164 164
                 }
165 165
             }
166 166
         }
167
-        return true;
167
+        return TRUE;
168 168
     }//_checkUtf8Rfc3629()
169 169
 
170 170
 	 /**
@@ -181,10 +181,10 @@  discard block
 block discarded – undo
181 181
      */
182 182
 	private static function mb_chunk_split($str, $len, $glue)
183 183
 	{
184
-		if (empty($str)) return false;
184
+		if (empty($str)) return FALSE;
185 185
 		$array = self::mbStringToArray ($str);
186 186
 		$n = -1;
187
-		$new = Array();
187
+		$new = array();
188 188
 		foreach ($array as $char) {
189 189
 			$n++;
190 190
 			if ($n < $len) $new []= $char;
@@ -206,7 +206,7 @@  discard block
 block discarded – undo
206 206
      */
207 207
 	private static function mbStringToArray ($str)
208 208
 	{
209
-		if (empty($str)) return false;
209
+		if (empty($str)) return FALSE;
210 210
 		$len = mb_strlen($str);
211 211
 		$array = array();
212 212
 		for ($i = 0; $i < $len; $i++) {
Please login to merge, or discard this patch.
build/CodeIgniter/Sniffs/Operators/LogicalOperatorAndSniff.php 3 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.
Indentation   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -33,47 +33,47 @@
 block discarded – undo
33 33
 class LogicalOperatorAndSniff implements Sniff
34 34
 {
35 35
 	/**
36
-     * Returns an array of tokens this test wants to listen for: symbolic and literal operators and.
37
-     *
38
-     * @return array
39
-     */
40
-    public function register()
41
-    {
42
-        return array(
43
-            T_LOGICAL_AND,
44
-        );
36
+	 * Returns an array of tokens this test wants to listen for: symbolic and literal operators and.
37
+	 *
38
+	 * @return array
39
+	 */
40
+	public function register()
41
+	{
42
+		return array(
43
+			T_LOGICAL_AND,
44
+		);
45 45
 
46
-    }//end register()
46
+	}//end register()
47 47
 
48 48
 
49
-    /**
50
-     * Processes this test, when one of its tokens is encountered.
51
-     *
52
-     * @param File $phpcsFile The current file being scanned.
53
-     * @param int                  $stackPtr  The position of the current token
54
-     *                                        in the stack passed in $tokens.
55
-     *
56
-     * @return void
57
-     */
58
-    public function process(File $phpcsFile, $stackPtr)
59
-    {
60
-        $tokens = $phpcsFile->getTokens();
49
+	/**
50
+	 * Processes this test, when one of its tokens is encountered.
51
+	 *
52
+	 * @param File $phpcsFile The current file being scanned.
53
+	 * @param int                  $stackPtr  The position of the current token
54
+	 *                                        in the stack passed in $tokens.
55
+	 *
56
+	 * @return void
57
+	 */
58
+	public function process(File $phpcsFile, $stackPtr)
59
+	{
60
+		$tokens = $phpcsFile->getTokens();
61 61
 
62
-        $operator_token = $tokens[$stackPtr];
63
-        $operator_string = $operator_token['content'];
64
-        $operator_code = $operator_token['code'];
62
+		$operator_token = $tokens[$stackPtr];
63
+		$operator_string = $operator_token['content'];
64
+		$operator_code = $operator_token['code'];
65 65
 
66
-        if ($operator_string !== strtoupper($operator_string)) {
67
-            $error_message = 'Logical operator should be in upper case;'
68
-                . ' use "' . strtoupper($operator_string)
69
-                . '" instead of "' . $operator_string . '"';
70
-            $phpcsFile->addError($error_message, $stackPtr, 'LowercaseLogicalOperator');
71
-        }
66
+		if ($operator_string !== strtoupper($operator_string)) {
67
+			$error_message = 'Logical operator should be in upper case;'
68
+				. ' use "' . strtoupper($operator_string)
69
+				. '" instead of "' . $operator_string . '"';
70
+			$phpcsFile->addError($error_message, $stackPtr, 'LowercaseLogicalOperator');
71
+		}
72 72
 
73
-        $warning_message = 'The symbolic form "&&" is preferred over the literal form "AND"';
74
-        $phpcsFile->addWarning($warning_message, $stackPtr, 'UseOfLiteralAndOperator');
73
+		$warning_message = 'The symbolic form "&&" is preferred over the literal form "AND"';
74
+		$phpcsFile->addWarning($warning_message, $stackPtr, 'UseOfLiteralAndOperator');
75 75
 
76
-    }//end process()
76
+	}//end process()
77 77
 
78 78
 
79 79
 }//end class
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/UppercaseLogicalOperatorOrSniff.php 3 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.
Indentation   +40 added lines, -40 removed lines patch added patch discarded remove patch
@@ -32,51 +32,51 @@
 block discarded – undo
32 32
 
33 33
 class UppercaseLogicalOperatorOrSniff implements Sniff
34 34
 {
35
-    /**
36
-     * Returns an array of tokens this test wants to listen for: literal and symbolic operators or.
37
-     *
38
-     * @return array
39
-     */
40
-    public function register()
41
-    {
42
-        return array(
43
-            T_BOOLEAN_OR,
44
-            T_LOGICAL_OR,
45
-        );
35
+	/**
36
+	 * Returns an array of tokens this test wants to listen for: literal and symbolic operators or.
37
+	 *
38
+	 * @return array
39
+	 */
40
+	public function register()
41
+	{
42
+		return array(
43
+			T_BOOLEAN_OR,
44
+			T_LOGICAL_OR,
45
+		);
46 46
 
47
-    }//end register()
47
+	}//end register()
48 48
 
49 49
 
50
-    /**
51
-     * Processes this test, when one of its tokens is encountered.
52
-     *
53
-     * @param File $phpcsFile The current file being scanned.
54
-     * @param int                  $stackPtr  The position of the current token
55
-     *                                        in the stack passed in $tokens.
56
-     *
57
-     * @return void
58
-     */
59
-    public function process(File $phpcsFile, $stackPtr)
60
-    {
61
-        $tokens = $phpcsFile->getTokens();
50
+	/**
51
+	 * Processes this test, when one of its tokens is encountered.
52
+	 *
53
+	 * @param File $phpcsFile The current file being scanned.
54
+	 * @param int                  $stackPtr  The position of the current token
55
+	 *                                        in the stack passed in $tokens.
56
+	 *
57
+	 * @return void
58
+	 */
59
+	public function process(File $phpcsFile, $stackPtr)
60
+	{
61
+		$tokens = $phpcsFile->getTokens();
62 62
 
63
-        $operator_token = $tokens[$stackPtr];
64
-        $operator_string = $operator_token['content'];
65
-        $operator_code = $operator_token['code'];
63
+		$operator_token = $tokens[$stackPtr];
64
+		$operator_string = $operator_token['content'];
65
+		$operator_code = $operator_token['code'];
66 66
 
67
-        if ($operator_code == T_BOOLEAN_OR) {
68
-            $error_message = 'Logical operator "' . $operator_string
69
-                . '" is prohibited; use "OR" instead';
70
-            $phpcsFile->addError($error_message, $stackPtr, 'UseOf||InsteadOfOR');
71
-        }
72
-        // it is literal, if it is not symbolic
73
-        else if ($operator_string !== strtoupper($operator_string)) {
74
-            $error_message = 'Logical operator should be in upper case;'
75
-                . ' use "' . strtoupper($operator_string)
76
-                . '" instead of "' . $operator_string . '"';
77
-            $phpcsFile->addError($error_message, $stackPtr, 'UseOfLowercaseOr');
78
-        }
79
-    }//end process()
67
+		if ($operator_code == T_BOOLEAN_OR) {
68
+			$error_message = 'Logical operator "' . $operator_string
69
+				. '" is prohibited; use "OR" instead';
70
+			$phpcsFile->addError($error_message, $stackPtr, 'UseOf||InsteadOfOR');
71
+		}
72
+		// it is literal, if it is not symbolic
73
+		else if ($operator_string !== strtoupper($operator_string)) {
74
+			$error_message = 'Logical operator should be in upper case;'
75
+				. ' use "' . strtoupper($operator_string)
76
+				. '" instead of "' . $operator_string . '"';
77
+			$phpcsFile->addError($error_message, $stackPtr, 'UseOfLowercaseOr');
78
+		}
79
+	}//end process()
80 80
 
81 81
 
82 82
 }//end class
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 5 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.
Indentation   +123 added lines, -123 removed lines patch added patch discarded remove patch
@@ -327,137 +327,137 @@
 block discarded – undo
327 327
  */
328 328
 class DoubleQuoteUsageSniff extends VariableUsageSniff
329 329
 {
330
-    /**
331
-     * Returns an array of tokens this test wants to listen for.
332
-     *
333
-     * @return array
334
-     */
335
-    public function register()
336
-    {
337
-        return array(
338
-            T_DOUBLE_QUOTED_STRING,
339
-            T_CONSTANT_ENCAPSED_STRING,
340
-        );
341
-    }//end register()
330
+	/**
331
+	 * Returns an array of tokens this test wants to listen for.
332
+	 *
333
+	 * @return array
334
+	 */
335
+	public function register()
336
+	{
337
+		return array(
338
+			T_DOUBLE_QUOTED_STRING,
339
+			T_CONSTANT_ENCAPSED_STRING,
340
+		);
341
+	}//end register()
342 342
 
343
-    /**
344
-     * Processes this test, when one of its tokens is encountered.
345
-     *
346
-     * @param File $phpcsFile The current file being scanned.
347
-     * @param int                  $stackPtr  The position of the current token
348
-     *                                        in the stack passed in $tokens.
349
-     *
350
-     * @return void
351
-     */
352
-    public function process(File $phpcsFile, $stackPtr)
353
-    {
354
-        // no variable are in the string from here
355
-        $tokens = $phpcsFile->getTokens();
356
-        $qtString = $tokens[$stackPtr]['content'];
357
-        // makes sure that it is about a double quote string,
358
-        // since variables are not parsed out of double quoted string
359
-        $open_qt_str = substr($qtString, 0, 1);
343
+	/**
344
+	 * Processes this test, when one of its tokens is encountered.
345
+	 *
346
+	 * @param File $phpcsFile The current file being scanned.
347
+	 * @param int                  $stackPtr  The position of the current token
348
+	 *                                        in the stack passed in $tokens.
349
+	 *
350
+	 * @return void
351
+	 */
352
+	public function process(File $phpcsFile, $stackPtr)
353
+	{
354
+		// no variable are in the string from here
355
+		$tokens = $phpcsFile->getTokens();
356
+		$qtString = $tokens[$stackPtr]['content'];
357
+		// makes sure that it is about a double quote string,
358
+		// since variables are not parsed out of double quoted string
359
+		$open_qt_str = substr($qtString, 0, 1);
360 360
 
361
-        // clean the enclosing quotes
362
-        $qtString = substr($qtString, 1, strlen($qtString) - 1 - 1);
361
+		// clean the enclosing quotes
362
+		$qtString = substr($qtString, 1, strlen($qtString) - 1 - 1);
363 363
 
364
-        if (0 === strcmp($open_qt_str, '"')) {
365
-            $this->processDoubleQuotedString($phpcsFile, $stackPtr, $qtString);
366
-        } else if (0 === strcmp($open_qt_str, "'")) {
367
-            $this->processSingleQuotedString($phpcsFile, $stackPtr, $qtString);
368
-        }
369
-    }//end process()
364
+		if (0 === strcmp($open_qt_str, '"')) {
365
+			$this->processDoubleQuotedString($phpcsFile, $stackPtr, $qtString);
366
+		} else if (0 === strcmp($open_qt_str, "'")) {
367
+			$this->processSingleQuotedString($phpcsFile, $stackPtr, $qtString);
368
+		}
369
+	}//end process()
370 370
 
371 371
 
372
-    /**
373
-     * Processes this test, when the token encountered is a double-quoted string.
374
-     *
375
-     * @param File $phpcsFile The current file being scanned.
376
-     * @param int                  $stackPtr  The position of the current token
377
-     *                                        in the stack passed in $tokens.
378
-     * @param string               $qtString  The double-quoted string content,
379
-     *                                        i.e. without quotes.
380
-     *
381
-     * @return void
382
-     */
383
-    protected function processDoubleQuotedString (File $phpcsFile, $stackPtr, $qtString)
384
-    {
385
-        // so there should be at least a single quote or a special char
386
-        // if there are the 2 kinds of quote and no special char, then add a warning
387
-        $has_variable = parent::processDoubleQuotedString($phpcsFile, $stackPtr, '"'.$qtString.'"');
388
-        $has_specific_sequence = $this->_hasSpecificSequence($qtString);
389
-        $dbl_qt_at = strpos($qtString, '"');
390
-        $smpl_qt_at = strpos($qtString, "'");
391
-        if (false === $has_variable && false === $has_specific_sequence
392
-            && false === $smpl_qt_at
393
-        ) {
394
-            $error = 'Single-quoted strings should be used unless it contains variables, special chars like \n or single quotes.';
395
-            $phpcsFile->addError($error, $stackPtr);
396
-        } else if (false !== $smpl_qt_at && false !== $dbl_qt_at
397
-            && false === $has_variable && false === $has_specific_sequence
398
-        ) {
399
-            $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.';
400
-            $phpcsFile->addWarning($warning, $stackPtr);
401
-        }
402
-    }//end processDoubleQuotedString()
372
+	/**
373
+	 * Processes this test, when the token encountered is a double-quoted string.
374
+	 *
375
+	 * @param File $phpcsFile The current file being scanned.
376
+	 * @param int                  $stackPtr  The position of the current token
377
+	 *                                        in the stack passed in $tokens.
378
+	 * @param string               $qtString  The double-quoted string content,
379
+	 *                                        i.e. without quotes.
380
+	 *
381
+	 * @return void
382
+	 */
383
+	protected function processDoubleQuotedString (File $phpcsFile, $stackPtr, $qtString)
384
+	{
385
+		// so there should be at least a single quote or a special char
386
+		// if there are the 2 kinds of quote and no special char, then add a warning
387
+		$has_variable = parent::processDoubleQuotedString($phpcsFile, $stackPtr, '"'.$qtString.'"');
388
+		$has_specific_sequence = $this->_hasSpecificSequence($qtString);
389
+		$dbl_qt_at = strpos($qtString, '"');
390
+		$smpl_qt_at = strpos($qtString, "'");
391
+		if (false === $has_variable && false === $has_specific_sequence
392
+			&& false === $smpl_qt_at
393
+		) {
394
+			$error = 'Single-quoted strings should be used unless it contains variables, special chars like \n or single quotes.';
395
+			$phpcsFile->addError($error, $stackPtr);
396
+		} else if (false !== $smpl_qt_at && false !== $dbl_qt_at
397
+			&& false === $has_variable && false === $has_specific_sequence
398
+		) {
399
+			$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.';
400
+			$phpcsFile->addWarning($warning, $stackPtr);
401
+		}
402
+	}//end processDoubleQuotedString()
403 403
 
404 404
 
405
-    /**
406
-     * Processes this test, when the token encountered is a single-quoted string.
407
-     *
408
-     * @param File $phpcsFile The current file being scanned.
409
-     * @param int                  $stackPtr  The position of the current token
410
-     *                                        in the stack passed in $tokens.
411
-     * @param string               $qtString  The single-quoted string content,
412
-     *                                        i.e. without quotes.
413
-     *
414
-     * @return void
415
-     */
416
-    protected function processSingleQuotedString (File $phpcsFile, $stackPtr, $qtString)
417
-    {
418
-        // if there is single quotes without additional double quotes,
419
-        // then user is allowed to use double quote to avoid having to
420
-        // escape single quotes. Don't add the warning, if an error was
421
-        // already added, because a variable was found in a single-quoted
422
-        // string.
423
-        $has_variable = parent::processSingleQuotedString($phpcsFile, $stackPtr, "'".$qtString."'");
424
-        $dbl_qt_at = strpos($qtString, '"');
425
-        $smpl_qt_at = strpos($qtString, "'");
426
-        if (false === $has_variable && false !== $smpl_qt_at && false === $dbl_qt_at) {
427
-            $warning = 'You may also use double-quoted strings if the string contains single quotes, so you do not have to use escape characters.';
428
-            $phpcsFile->addWarning($warning, $stackPtr);
429
-        }
430
-    }//end processSingleQuotedString()
405
+	/**
406
+	 * Processes this test, when the token encountered is a single-quoted string.
407
+	 *
408
+	 * @param File $phpcsFile The current file being scanned.
409
+	 * @param int                  $stackPtr  The position of the current token
410
+	 *                                        in the stack passed in $tokens.
411
+	 * @param string               $qtString  The single-quoted string content,
412
+	 *                                        i.e. without quotes.
413
+	 *
414
+	 * @return void
415
+	 */
416
+	protected function processSingleQuotedString (File $phpcsFile, $stackPtr, $qtString)
417
+	{
418
+		// if there is single quotes without additional double quotes,
419
+		// then user is allowed to use double quote to avoid having to
420
+		// escape single quotes. Don't add the warning, if an error was
421
+		// already added, because a variable was found in a single-quoted
422
+		// string.
423
+		$has_variable = parent::processSingleQuotedString($phpcsFile, $stackPtr, "'".$qtString."'");
424
+		$dbl_qt_at = strpos($qtString, '"');
425
+		$smpl_qt_at = strpos($qtString, "'");
426
+		if (false === $has_variable && false !== $smpl_qt_at && false === $dbl_qt_at) {
427
+			$warning = 'You may also use double-quoted strings if the string contains single quotes, so you do not have to use escape characters.';
428
+			$phpcsFile->addWarning($warning, $stackPtr);
429
+		}
430
+	}//end processSingleQuotedString()
431 431
 
432
-    /**
433
-     * Return TRUE, if a sequence of chars that is parsed in a specific way
434
-     * in double-quoted strings is found, FALSE otherwise.
435
-     *
436
-     * @param string $string String in which sequence of special chars will
437
-     * be researched.
438
-     *
439
-     * @return TRUE, if a sequence of chars that is parsed in a specific way
440
-     * in double-quoted strings is found, FALSE otherwise.
441
-     *
442
-     * @link http://www.php.net/manual/en/language.types.string.php#language.types.string.syntax.double
443
-     */
444
-    private function _hasSpecificSequence($string)
445
-    {
446
-        $hasSpecificSequence = FALSE;
447
-        $specialMeaningStrs = array('\n', '\r', '\t', '\v', '\f');
448
-        foreach ($specialMeaningStrs as $splStr) {
449
-            if (FALSE !== strpos($string, $splStr)) {
450
-                $hasSpecificSequence = TRUE;
451
-            }
452
-        }
453
-        $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)) {
456
-                $hasSpecificSequence = TRUE;
457
-            }
458
-        }
459
-        return $hasSpecificSequence;
460
-    }//end _hasSpecificSequence()
432
+	/**
433
+	 * Return TRUE, if a sequence of chars that is parsed in a specific way
434
+	 * in double-quoted strings is found, FALSE otherwise.
435
+	 *
436
+	 * @param string $string String in which sequence of special chars will
437
+	 * be researched.
438
+	 *
439
+	 * @return TRUE, if a sequence of chars that is parsed in a specific way
440
+	 * in double-quoted strings is found, FALSE otherwise.
441
+	 *
442
+	 * @link http://www.php.net/manual/en/language.types.string.php#language.types.string.syntax.double
443
+	 */
444
+	private function _hasSpecificSequence($string)
445
+	{
446
+		$hasSpecificSequence = FALSE;
447
+		$specialMeaningStrs = array('\n', '\r', '\t', '\v', '\f');
448
+		foreach ($specialMeaningStrs as $splStr) {
449
+			if (FALSE !== strpos($string, $splStr)) {
450
+				$hasSpecificSequence = TRUE;
451
+			}
452
+		}
453
+		$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)) {
456
+				$hasSpecificSequence = TRUE;
457
+			}
458
+		}
459
+		return $hasSpecificSequence;
460
+	}//end _hasSpecificSequence()
461 461
 
462 462
 }//end class
463 463
 
Please login to merge, or discard this patch.
Spacing   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -89,10 +89,10 @@  discard block
 block discarded – undo
89 89
 	 *
90 90
 	 * @return void
91 91
 	 */
92
-	protected function processDoubleQuotedString (File $phpcsFile, $stackPtr, $dblQtString)
92
+	protected function processDoubleQuotedString(File $phpcsFile, $stackPtr, $dblQtString)
93 93
 	{
94 94
 		$variableFound = FALSE;
95
-		$strTokens = token_get_all('<?php '.$dblQtString);
95
+		$strTokens = token_get_all('<?php ' . $dblQtString);
96 96
 		$strPtr = 1; // skip php opening tag added by ourselves
97 97
 		$requireDblQuotes = FALSE;
98 98
 		while ($strPtr < count($strTokens)) {
@@ -136,10 +136,10 @@  discard block
 block discarded – undo
136 136
 	 *
137 137
 	 * @return void
138 138
 	 */
139
-	protected function processSingleQuotedString (File $phpcsFile, $stackPtr, $sglQtString)
139
+	protected function processSingleQuotedString(File $phpcsFile, $stackPtr, $sglQtString)
140 140
 	{
141 141
 		$variableFound = FALSE;
142
-		$strTokens = token_get_all('<?php '.$sglQtString);
142
+		$strTokens = token_get_all('<?php ' . $sglQtString);
143 143
 		$strPtr = 1; // skip php opening tag added by ourselves
144 144
 		while ($strPtr < count($strTokens)) {
145 145
 			$strToken = $strTokens[$strPtr];
@@ -171,17 +171,17 @@  discard block
 block discarded – undo
171 171
 	 * @return array The attribute name associated to index 'var', an array with
172 172
 	 * indexes 'obj' and 'attr' or an array with indexes 'arr' and 'idx'.
173 173
 	 */
174
-	private function _parseVariable ($strTokens, &$strPtr)
174
+	private function _parseVariable($strTokens, &$strPtr)
175 175
 	{
176 176
 		if ( ! in_array($strTokens[$strPtr][0], array(T_VARIABLE, T_STRING_VARNAME))) {
177
-			throw new Exception ('Expected variable name.');
177
+			throw new Exception('Expected variable name.');
178 178
 		}
179 179
 		$var = $strTokens[$strPtr][1];
180 180
 		$strPtr++;
181 181
 		$startStrPtr = $strPtr;
182 182
 		try {
183 183
 			$attr = $this->_parseObjectAttribute($strTokens, $strPtr);
184
-			return array ('obj' => $var, 'attr' => $attr);
184
+			return array('obj' => $var, 'attr' => $attr);
185 185
 		} catch (Exception $err) {
186 186
 			if ($strPtr !== $startStrPtr) {
187 187
 				throw $err;
@@ -189,13 +189,13 @@  discard block
 block discarded – undo
189 189
 		}
190 190
 		try {
191 191
 			$idx = $this->_parseArrayIndexes($strTokens, $strPtr);
192
-			return array ('arr' => $var, 'idx' => $idx);
192
+			return array('arr' => $var, 'idx' => $idx);
193 193
 		} catch (Exception $err) {
194 194
 			if ($strPtr !== $startStrPtr) {
195 195
 				throw $err;
196 196
 			}
197 197
 		}
198
-		return array ('var' => $var);
198
+		return array('var' => $var);
199 199
 	}//end _parseVariable()
200 200
 
201 201
 
@@ -215,21 +215,21 @@  discard block
 block discarded – undo
215 215
 	 * @return mixed The attribute name as a string, an array with indexes
216 216
 	 * 'obj' and 'attr' or an array with indexes 'arr' and 'idx'.
217 217
 	 */
218
-	private function _parseObjectAttribute ($strTokens, &$strPtr)
218
+	private function _parseObjectAttribute($strTokens, &$strPtr)
219 219
 	{
220 220
 		if (T_OBJECT_OPERATOR !== $strTokens[$strPtr][0]) {
221
-			throw new Exception ('Expected ->.');
221
+			throw new Exception('Expected ->.');
222 222
 		}
223 223
 		$strPtr++;
224 224
 		if (T_STRING !== $strTokens[$strPtr][0]) {
225
-			throw new Exception ('Expected an object attribute.');
225
+			throw new Exception('Expected an object attribute.');
226 226
 		}
227 227
 		$attr = $strTokens[$strPtr][1];
228 228
 		$strPtr++;
229 229
 		$startStrPtr = $strPtr;
230 230
 		try {
231 231
 			$sub_attr = $this->_parseObjectAttribute($strTokens, $strPtr);
232
-			return array ('obj' => $attr, 'attr' => $sub_attr);
232
+			return array('obj' => $attr, 'attr' => $sub_attr);
233 233
 		} catch (Exception $err) {
234 234
 			if ($strPtr !== $startStrPtr) {
235 235
 				throw $err;
@@ -237,7 +237,7 @@  discard block
 block discarded – undo
237 237
 		}
238 238
 		try {
239 239
 			$idx = $this->_parseArrayIndexes($strTokens, $strPtr);
240
-			return array ('arr' => $attr, 'idx' => $idx);
240
+			return array('arr' => $attr, 'idx' => $idx);
241 241
 		} catch (Exception $err) {
242 242
 			if ($strPtr !== $startStrPtr) {
243 243
 				throw $err;
@@ -260,7 +260,7 @@  discard block
 block discarded – undo
260 260
 	 *
261 261
 	 * @return array Indexes in the same order as in the string.
262 262
 	 */
263
-	private function _parseArrayIndexes ($strTokens, &$strPtr)
263
+	private function _parseArrayIndexes($strTokens, &$strPtr)
264 264
 	{
265 265
 		$indexes = array($this->_parseArrayIndex($strTokens, $strPtr));
266 266
 		try {
@@ -290,19 +290,19 @@  discard block
 block discarded – undo
290 290
 	 *
291 291
 	 * @return string Index between the 2 square brackets
292 292
 	 */
293
-	private function _parseArrayIndex ($strTokens, &$strPtr)
293
+	private function _parseArrayIndex($strTokens, &$strPtr)
294 294
 	{
295 295
 		if ('[' !== $strTokens[$strPtr]) {
296
-			throw new Exception ('Expected [.');
296
+			throw new Exception('Expected [.');
297 297
 		}
298 298
 		$strPtr++;
299
-		if (! in_array($strTokens[$strPtr][0], array(T_CONSTANT_ENCAPSED_STRING, T_LNUMBER))) {
300
-			throw new Exception ('Expected an array index.');
299
+		if ( ! in_array($strTokens[$strPtr][0], array(T_CONSTANT_ENCAPSED_STRING, T_LNUMBER))) {
300
+			throw new Exception('Expected an array index.');
301 301
 		}
302 302
 		$index = $strTokens[$strPtr][1];
303 303
 		$strPtr++;
304 304
 		if (']' !== $strTokens[$strPtr]) {
305
-			throw new Exception ('Expected ].');
305
+			throw new Exception('Expected ].');
306 306
 		}
307 307
 		$strPtr++;
308 308
 		return $index;
@@ -380,11 +380,11 @@  discard block
 block discarded – undo
380 380
      *
381 381
      * @return void
382 382
      */
383
-    protected function processDoubleQuotedString (File $phpcsFile, $stackPtr, $qtString)
383
+    protected function processDoubleQuotedString(File $phpcsFile, $stackPtr, $qtString)
384 384
     {
385 385
         // so there should be at least a single quote or a special char
386 386
         // if there are the 2 kinds of quote and no special char, then add a warning
387
-        $has_variable = parent::processDoubleQuotedString($phpcsFile, $stackPtr, '"'.$qtString.'"');
387
+        $has_variable = parent::processDoubleQuotedString($phpcsFile, $stackPtr, '"' . $qtString . '"');
388 388
         $has_specific_sequence = $this->_hasSpecificSequence($qtString);
389 389
         $dbl_qt_at = strpos($qtString, '"');
390 390
         $smpl_qt_at = strpos($qtString, "'");
@@ -413,14 +413,14 @@  discard block
 block discarded – undo
413 413
      *
414 414
      * @return void
415 415
      */
416
-    protected function processSingleQuotedString (File $phpcsFile, $stackPtr, $qtString)
416
+    protected function processSingleQuotedString(File $phpcsFile, $stackPtr, $qtString)
417 417
     {
418 418
         // if there is single quotes without additional double quotes,
419 419
         // then user is allowed to use double quote to avoid having to
420 420
         // escape single quotes. Don't add the warning, if an error was
421 421
         // already added, because a variable was found in a single-quoted
422 422
         // string.
423
-        $has_variable = parent::processSingleQuotedString($phpcsFile, $stackPtr, "'".$qtString."'");
423
+        $has_variable = parent::processSingleQuotedString($phpcsFile, $stackPtr, "'" . $qtString . "'");
424 424
         $dbl_qt_at = strpos($qtString, '"');
425 425
         $smpl_qt_at = strpos($qtString, "'");
426 426
         if (false === $has_variable && false !== $smpl_qt_at && false === $dbl_qt_at) {
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.
Upper-Lower-Casing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -115,7 +115,7 @@  discard block
 block discarded – undo
115 115
 					// $strPtr++;
116 116
 				} else if (T_VARIABLE === $strToken[0]) {
117 117
 					$variableFound = TRUE;
118
-					$error = "Variable {$strToken[1]} in double-quoted strings should be enclosed with curly braces. Please consider {{$strToken[1]}}";
118
+					$error = "variable {$strToken[1]} in double-quoted strings should be enclosed with curly braces. Please consider {{$strToken[1]}}";
119 119
 					$phpcsFile->addError($error, $stackPtr);
120 120
 				}
121 121
 			}
@@ -388,13 +388,13 @@  discard block
 block discarded – undo
388 388
         $has_specific_sequence = $this->_hasSpecificSequence($qtString);
389 389
         $dbl_qt_at = strpos($qtString, '"');
390 390
         $smpl_qt_at = strpos($qtString, "'");
391
-        if (false === $has_variable && false === $has_specific_sequence
392
-            && false === $smpl_qt_at
391
+        if (FALSE === $has_variable && FALSE === $has_specific_sequence
392
+            && FALSE === $smpl_qt_at
393 393
         ) {
394 394
             $error = 'Single-quoted strings should be used unless it contains variables, special chars like \n or single quotes.';
395 395
             $phpcsFile->addError($error, $stackPtr);
396
-        } else if (false !== $smpl_qt_at && false !== $dbl_qt_at
397
-            && false === $has_variable && false === $has_specific_sequence
396
+        } else if (FALSE !== $smpl_qt_at && FALSE !== $dbl_qt_at
397
+            && FALSE === $has_variable && FALSE === $has_specific_sequence
398 398
         ) {
399 399
             $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.';
400 400
             $phpcsFile->addWarning($warning, $stackPtr);
@@ -423,7 +423,7 @@  discard block
 block discarded – undo
423 423
         $has_variable = parent::processSingleQuotedString($phpcsFile, $stackPtr, "'".$qtString."'");
424 424
         $dbl_qt_at = strpos($qtString, '"');
425 425
         $smpl_qt_at = strpos($qtString, "'");
426
-        if (false === $has_variable && false !== $smpl_qt_at && false === $dbl_qt_at) {
426
+        if (FALSE === $has_variable && FALSE !== $smpl_qt_at && FALSE === $dbl_qt_at) {
427 427
             $warning = 'You may also use double-quoted strings if the string contains single quotes, so you do not have to use escape characters.';
428 428
             $phpcsFile->addWarning($warning, $stackPtr);
429 429
         }
Please login to merge, or discard this patch.
build/CodeIgniter/Sniffs/WhiteSpace/LogicalNotSpacingSniff.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -36,7 +36,7 @@
 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 string[]
40 40
      */
41 41
     public function register()
42 42
     {
Please login to merge, or discard this patch.
Indentation   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -33,41 +33,41 @@
 block discarded – undo
33 33
 class LogicalNotSpacingSniff implements Sniff
34 34
 {
35 35
 
36
-    /**
37
-     * Returns an array of tokens this test wants to listen for.
38
-     *
39
-     * @return array
40
-     */
41
-    public function register()
42
-    {
43
-        return array(
44
-            T_BOOLEAN_NOT,
45
-        );
46
-    }//end register()
36
+	/**
37
+	 * Returns an array of tokens this test wants to listen for.
38
+	 *
39
+	 * @return array
40
+	 */
41
+	public function register()
42
+	{
43
+		return array(
44
+			T_BOOLEAN_NOT,
45
+		);
46
+	}//end register()
47 47
 
48 48
 
49
-    /**
50
-     * Processes this test, when one of its tokens is encountered.
51
-     *
52
-     * @param File $phpcsFile The current file being scanned.
53
-     * @param int                  $stackPtr  The position of the current token
54
-     *                                        in the stack passed in $tokens.
55
-     *
56
-     * @return void
57
-     */
58
-    public function process(File $phpcsFile, $stackPtr)
59
-    {
60
-        $tokens = $phpcsFile->getTokens();
49
+	/**
50
+	 * Processes this test, when one of its tokens is encountered.
51
+	 *
52
+	 * @param File $phpcsFile The current file being scanned.
53
+	 * @param int                  $stackPtr  The position of the current token
54
+	 *                                        in the stack passed in $tokens.
55
+	 *
56
+	 * @return void
57
+	 */
58
+	public function process(File $phpcsFile, $stackPtr)
59
+	{
60
+		$tokens = $phpcsFile->getTokens();
61 61
 
62
-        $operator_token = $tokens[$stackPtr];
62
+		$operator_token = $tokens[$stackPtr];
63 63
 
64
-        $previous_token = $tokens[$stackPtr - 1];
65
-        $next_token = $tokens[$stackPtr + 1];
66
-        if (T_WHITESPACE !== $previous_token['code'] || T_WHITESPACE !== $next_token['code']) {
67
-            $error = 'Logical operator ! should always be preceded and followed with a whitespace.';
68
-            $phpcsFile->addError($error, $stackPtr);
69
-        }
70
-    }//end process()
64
+		$previous_token = $tokens[$stackPtr - 1];
65
+		$next_token = $tokens[$stackPtr + 1];
66
+		if (T_WHITESPACE !== $previous_token['code'] || T_WHITESPACE !== $next_token['code']) {
67
+			$error = 'Logical operator ! should always be preceded and followed with a whitespace.';
68
+			$phpcsFile->addError($error, $stackPtr);
69
+		}
70
+	}//end process()
71 71
 
72 72
 
73 73
 }//end class
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 LogicalNotSpacingSniff implements Sniff
34
-{
33
+class LogicalNotSpacingSniff implements Sniff {
35 34
 
36 35
     /**
37 36
      * Returns an array of tokens this test wants to listen for.
@@ -63,7 +62,8 @@  discard block
 block discarded – undo
63 62
 
64 63
         $previous_token = $tokens[$stackPtr - 1];
65 64
         $next_token = $tokens[$stackPtr + 1];
66
-        if (T_WHITESPACE !== $previous_token['code'] || T_WHITESPACE !== $next_token['code']) {
65
+        if (T_WHITESPACE !== $previous_token['code'] || T_WHITESPACE !== $next_token['code'])
66
+        {
67 67
             $error = 'Logical operator ! should always be preceded and followed with a whitespace.';
68 68
             $phpcsFile->addError($error, $stackPtr);
69 69
         }
Please login to merge, or discard this patch.
build/CodeIgniter/UnusedSniffs/Files/ClosingLocationCommentSniff.php 5 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -50,7 +50,7 @@  discard block
 block discarded – undo
50 50
     /**
51 51
      * Returns an array of tokens this test wants to listen for.
52 52
      *
53
-     * @return array
53
+     * @return integer[]
54 54
      */
55 55
     public function register()
56 56
     {
@@ -134,7 +134,7 @@  discard block
 block discarded – undo
134 134
      * application root. Parent directory of the application root are allowed
135 135
      * but not mandatory.
136 136
      *
137
-     * @return string|bool The relative path from $appRoot to $filePath, or
137
+     * @return false|string The relative path from $appRoot to $filePath, or
138 138
      * false if $appRoot cannot be found in $filePath.
139 139
      */
140 140
     private static function _getLocationPath ($filePath, $appRoot)
Please login to merge, or discard this patch.
Indentation   +132 added lines, -132 removed lines patch added patch discarded remove patch
@@ -45,138 +45,138 @@
 block discarded – undo
45 45
 
46 46
 class ClosingLocationCommentSniff extends AbstractClosingCommentSniff
47 47
 {
48
-    public $applicationRoot = '/application/';
49
-
50
-    /**
51
-     * Returns an array of tokens this test wants to listen for.
52
-     *
53
-     * @return array
54
-     */
55
-    public function register()
56
-    {
57
-        return array(
58
-            T_OPEN_TAG
59
-        );
60
-
61
-    }//end register()
62
-
63
-
64
-    /**
65
-     * Processes this test, when one of its tokens is encountered.
66
-     *
67
-     * @param File $phpcsFile The current file being scanned.
68
-     * @param int                  $stackPtr  The position of the current token
69
-     *                                        in the stack passed in $tokens.
70
-     *
71
-     * @return void
72
-     */
73
-    public function process(File $phpcsFile, $stackPtr)
74
-    {
75
-        // We are only interested if this is the first open tag.
76
-        if ($stackPtr !== 0) {
77
-            if ($phpcsFile->findPrevious(T_OPEN_TAG, ($stackPtr - 1)) !== false) {
78
-                return;
79
-            }
80
-        }
81
-
82
-        $filePath = $phpcsFile->getFilename();
83
-        $tokens = $phpcsFile->getTokens();
84
-        // removes the application root from the beginning of the file path
85
-        $locationPath = self::_getLocationPath($filePath, $this->_getAppRoot());
86
-        // add an error, if application root doesn't exist in current file path
87
-        if (false === $locationPath) {
88
-            $error = 'Unable to find "' . $this->_getAppRoot() . '" in file path "' . $filePath . '". Please set your project\'s application root.';
89
-            $phpcsFile->addError($error, count($tokens) - 1);
90
-            return;
91
-        }
92
-        // generates the expected comment
93
-        $commentTemplate = "Location: $locationPath";
94
-
95
-        $currentToken = count($tokens) - 1;
96
-        $hasClosingLocationComment = false;
97
-        $isNotAWhitespaceOrAComment = false;
98
-        while ($currentToken >= 0
99
-            && ! $isNotAWhitespaceOrAComment
100
-            && ! $hasClosingLocationComment
101
-        ) {
102
-            $token = $tokens[$currentToken];
103
-            $tokenCode = $token['code'];
104
-            if (T_COMMENT === $tokenCode) {
105
-                $commentString = self::_getCommentContent($token['content']);
106
-                if (0 === strcmp($commentString, $commentTemplate)) {
107
-                    $hasClosingLocationComment = true;
108
-                }
109
-            } else if (T_WHITESPACE === $tokenCode) {
110
-                // Whitespaces are allowed between the closing file comment,
111
-                //other comments and end of file
112
-            } else {
113
-                $isNotAWhitespaceOrAComment = true;
114
-            }
115
-            $currentToken--;
116
-        }
117
-
118
-        if ( ! $hasClosingLocationComment) {
119
-            $error = 'No comment block marks the end of file instead of the closing PHP tag. Please add a comment block containing only "' . $commentTemplate . '".';
120
-            $phpcsFile->addError($error, $currentToken);
121
-        }
122
-    }//end process()
123
-
124
-
125
-    /**
126
-     * Returns the relative path from $appRoot to $filePath, or false if
127
-     * $appRoot cannot be found in $filePath, because $appRoot is not a parent
128
-     * of $filePath.
129
-     *
130
-     * @param string $filePath Full path to the file being proceed.
131
-     * @param string $appRoot  Partial or full path to the CodeIgniter
132
-     * application root of the file being proceed. It must not contain the
133
-     * full path to the application root, but at least the name of the
134
-     * application root. Parent directory of the application root are allowed
135
-     * but not mandatory.
136
-     *
137
-     * @return string|bool The relative path from $appRoot to $filePath, or
138
-     * false if $appRoot cannot be found in $filePath.
139
-     */
140
-    private static function _getLocationPath ($filePath, $appRoot)
141
-    {
142
-        // removes the path to application root
143
-        // from the beginning of the file path
144
-        $appRootAt = strpos($filePath, $appRoot);
145
-        if (false === $appRootAt) {
146
-            return false;
147
-        }
148
-        $localPath = substr($filePath, $appRootAt + strlen($appRoot));
149
-        // ensures the location path to be a relative path starting with "./".
150
-        if ( ! self::_stringStartsWith($localPath, './')) {
151
-            $localPath = './' . $localPath;
152
-        } else if ( ! self::_stringStartsWith($localPath, '.')
153
-            && self::_stringStartsWith($localPath, '/')
154
-        ) {
155
-            $localPath = '.' . $localPath;
156
-        }
157
-        return $localPath;
158
-    }//end _getLocationPath()
159
-
160
-
161
-    /**
162
-     * Returns the application root that should be used first.
163
-     *
164
-     * There are several ways to configure the application root.
165
-     * In order of priority :
166
-     *   - Configuration variable ci_application_root.
167
-     *   - Rule property applicationRoot.
168
-     *   - Default value '/application/'
169
-     *
170
-     * @return string Path to your project application root.
171
-     */
172
-    private function _getAppRoot()
173
-    {
174
-        $appRoot = Common::getConfigData('ci_application_root');
175
-        if (null === $appRoot) {
176
-            $appRoot = $this->applicationRoot;
177
-        }
178
-        return $appRoot;
179
-    }//end _getAppRoot()
48
+	public $applicationRoot = '/application/';
49
+
50
+	/**
51
+	 * Returns an array of tokens this test wants to listen for.
52
+	 *
53
+	 * @return array
54
+	 */
55
+	public function register()
56
+	{
57
+		return array(
58
+			T_OPEN_TAG
59
+		);
60
+
61
+	}//end register()
62
+
63
+
64
+	/**
65
+	 * Processes this test, when one of its tokens is encountered.
66
+	 *
67
+	 * @param File $phpcsFile The current file being scanned.
68
+	 * @param int                  $stackPtr  The position of the current token
69
+	 *                                        in the stack passed in $tokens.
70
+	 *
71
+	 * @return void
72
+	 */
73
+	public function process(File $phpcsFile, $stackPtr)
74
+	{
75
+		// We are only interested if this is the first open tag.
76
+		if ($stackPtr !== 0) {
77
+			if ($phpcsFile->findPrevious(T_OPEN_TAG, ($stackPtr - 1)) !== false) {
78
+				return;
79
+			}
80
+		}
81
+
82
+		$filePath = $phpcsFile->getFilename();
83
+		$tokens = $phpcsFile->getTokens();
84
+		// removes the application root from the beginning of the file path
85
+		$locationPath = self::_getLocationPath($filePath, $this->_getAppRoot());
86
+		// add an error, if application root doesn't exist in current file path
87
+		if (false === $locationPath) {
88
+			$error = 'Unable to find "' . $this->_getAppRoot() . '" in file path "' . $filePath . '". Please set your project\'s application root.';
89
+			$phpcsFile->addError($error, count($tokens) - 1);
90
+			return;
91
+		}
92
+		// generates the expected comment
93
+		$commentTemplate = "Location: $locationPath";
94
+
95
+		$currentToken = count($tokens) - 1;
96
+		$hasClosingLocationComment = false;
97
+		$isNotAWhitespaceOrAComment = false;
98
+		while ($currentToken >= 0
99
+			&& ! $isNotAWhitespaceOrAComment
100
+			&& ! $hasClosingLocationComment
101
+		) {
102
+			$token = $tokens[$currentToken];
103
+			$tokenCode = $token['code'];
104
+			if (T_COMMENT === $tokenCode) {
105
+				$commentString = self::_getCommentContent($token['content']);
106
+				if (0 === strcmp($commentString, $commentTemplate)) {
107
+					$hasClosingLocationComment = true;
108
+				}
109
+			} else if (T_WHITESPACE === $tokenCode) {
110
+				// Whitespaces are allowed between the closing file comment,
111
+				//other comments and end of file
112
+			} else {
113
+				$isNotAWhitespaceOrAComment = true;
114
+			}
115
+			$currentToken--;
116
+		}
117
+
118
+		if ( ! $hasClosingLocationComment) {
119
+			$error = 'No comment block marks the end of file instead of the closing PHP tag. Please add a comment block containing only "' . $commentTemplate . '".';
120
+			$phpcsFile->addError($error, $currentToken);
121
+		}
122
+	}//end process()
123
+
124
+
125
+	/**
126
+	 * Returns the relative path from $appRoot to $filePath, or false if
127
+	 * $appRoot cannot be found in $filePath, because $appRoot is not a parent
128
+	 * of $filePath.
129
+	 *
130
+	 * @param string $filePath Full path to the file being proceed.
131
+	 * @param string $appRoot  Partial or full path to the CodeIgniter
132
+	 * application root of the file being proceed. It must not contain the
133
+	 * full path to the application root, but at least the name of the
134
+	 * application root. Parent directory of the application root are allowed
135
+	 * but not mandatory.
136
+	 *
137
+	 * @return string|bool The relative path from $appRoot to $filePath, or
138
+	 * false if $appRoot cannot be found in $filePath.
139
+	 */
140
+	private static function _getLocationPath ($filePath, $appRoot)
141
+	{
142
+		// removes the path to application root
143
+		// from the beginning of the file path
144
+		$appRootAt = strpos($filePath, $appRoot);
145
+		if (false === $appRootAt) {
146
+			return false;
147
+		}
148
+		$localPath = substr($filePath, $appRootAt + strlen($appRoot));
149
+		// ensures the location path to be a relative path starting with "./".
150
+		if ( ! self::_stringStartsWith($localPath, './')) {
151
+			$localPath = './' . $localPath;
152
+		} else if ( ! self::_stringStartsWith($localPath, '.')
153
+			&& self::_stringStartsWith($localPath, '/')
154
+		) {
155
+			$localPath = '.' . $localPath;
156
+		}
157
+		return $localPath;
158
+	}//end _getLocationPath()
159
+
160
+
161
+	/**
162
+	 * Returns the application root that should be used first.
163
+	 *
164
+	 * There are several ways to configure the application root.
165
+	 * In order of priority :
166
+	 *   - Configuration variable ci_application_root.
167
+	 *   - Rule property applicationRoot.
168
+	 *   - Default value '/application/'
169
+	 *
170
+	 * @return string Path to your project application root.
171
+	 */
172
+	private function _getAppRoot()
173
+	{
174
+		$appRoot = Common::getConfigData('ci_application_root');
175
+		if (null === $appRoot) {
176
+			$appRoot = $this->applicationRoot;
177
+		}
178
+		return $appRoot;
179
+	}//end _getAppRoot()
180 180
 }//end class
181 181
 
182 182
 ?>
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -137,7 +137,7 @@
 block discarded – undo
137 137
      * @return string|bool The relative path from $appRoot to $filePath, or
138 138
      * false if $appRoot cannot be found in $filePath.
139 139
      */
140
-    private static function _getLocationPath ($filePath, $appRoot)
140
+    private static function _getLocationPath($filePath, $appRoot)
141 141
     {
142 142
         // removes the path to application root
143 143
         // from the beginning of the file path
Please login to merge, or discard this patch.
Braces   +27 added lines, -14 removed lines patch added patch discarded remove patch
@@ -43,8 +43,7 @@  discard block
 block discarded – undo
43 43
 use PHP_CodeSniffer\Files\File;
44 44
 use PHP_CodeSniffer\Util\Common;
45 45
 
46
-class ClosingLocationCommentSniff extends AbstractClosingCommentSniff
47
-{
46
+class ClosingLocationCommentSniff extends AbstractClosingCommentSniff {
48 47
     public $applicationRoot = '/application/';
49 48
 
50 49
     /**
@@ -73,8 +72,10 @@  discard block
 block discarded – undo
73 72
     public function process(File $phpcsFile, $stackPtr)
74 73
     {
75 74
         // We are only interested if this is the first open tag.
76
-        if ($stackPtr !== 0) {
77
-            if ($phpcsFile->findPrevious(T_OPEN_TAG, ($stackPtr - 1)) !== false) {
75
+        if ($stackPtr !== 0)
76
+        {
77
+            if ($phpcsFile->findPrevious(T_OPEN_TAG, ($stackPtr - 1)) !== false)
78
+            {
78 79
                 return;
79 80
             }
80 81
         }
@@ -84,7 +85,8 @@  discard block
 block discarded – undo
84 85
         // removes the application root from the beginning of the file path
85 86
         $locationPath = self::_getLocationPath($filePath, $this->_getAppRoot());
86 87
         // add an error, if application root doesn't exist in current file path
87
-        if (false === $locationPath) {
88
+        if (false === $locationPath)
89
+        {
88 90
             $error = 'Unable to find "' . $this->_getAppRoot() . '" in file path "' . $filePath . '". Please set your project\'s application root.';
89 91
             $phpcsFile->addError($error, count($tokens) - 1);
90 92
             return;
@@ -101,21 +103,28 @@  discard block
 block discarded – undo
101 103
         ) {
102 104
             $token = $tokens[$currentToken];
103 105
             $tokenCode = $token['code'];
104
-            if (T_COMMENT === $tokenCode) {
106
+            if (T_COMMENT === $tokenCode)
107
+            {
105 108
                 $commentString = self::_getCommentContent($token['content']);
106
-                if (0 === strcmp($commentString, $commentTemplate)) {
109
+                if (0 === strcmp($commentString, $commentTemplate))
110
+                {
107 111
                     $hasClosingLocationComment = true;
108 112
                 }
109
-            } else if (T_WHITESPACE === $tokenCode) {
113
+            }
114
+            else if (T_WHITESPACE === $tokenCode)
115
+            {
110 116
                 // Whitespaces are allowed between the closing file comment,
111 117
                 //other comments and end of file
112
-            } else {
118
+            }
119
+            else
120
+            {
113 121
                 $isNotAWhitespaceOrAComment = true;
114 122
             }
115 123
             $currentToken--;
116 124
         }
117 125
 
118
-        if ( ! $hasClosingLocationComment) {
126
+        if ( ! $hasClosingLocationComment)
127
+        {
119 128
             $error = 'No comment block marks the end of file instead of the closing PHP tag. Please add a comment block containing only "' . $commentTemplate . '".';
120 129
             $phpcsFile->addError($error, $currentToken);
121 130
         }
@@ -142,14 +151,17 @@  discard block
 block discarded – undo
142 151
         // removes the path to application root
143 152
         // from the beginning of the file path
144 153
         $appRootAt = strpos($filePath, $appRoot);
145
-        if (false === $appRootAt) {
154
+        if (false === $appRootAt)
155
+        {
146 156
             return false;
147 157
         }
148 158
         $localPath = substr($filePath, $appRootAt + strlen($appRoot));
149 159
         // ensures the location path to be a relative path starting with "./".
150
-        if ( ! self::_stringStartsWith($localPath, './')) {
160
+        if ( ! self::_stringStartsWith($localPath, './'))
161
+        {
151 162
             $localPath = './' . $localPath;
152
-        } else if ( ! self::_stringStartsWith($localPath, '.')
163
+        }
164
+        else if ( ! self::_stringStartsWith($localPath, '.')
153 165
             && self::_stringStartsWith($localPath, '/')
154 166
         ) {
155 167
             $localPath = '.' . $localPath;
@@ -172,7 +184,8 @@  discard block
 block discarded – undo
172 184
     private function _getAppRoot()
173 185
     {
174 186
         $appRoot = Common::getConfigData('ci_application_root');
175
-        if (null === $appRoot) {
187
+        if (null === $appRoot)
188
+        {
176 189
             $appRoot = $this->applicationRoot;
177 190
         }
178 191
         return $appRoot;
Please login to merge, or discard this patch.
Upper-Lower-Casing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -74,7 +74,7 @@  discard block
 block discarded – undo
74 74
     {
75 75
         // We are only interested if this is the first open tag.
76 76
         if ($stackPtr !== 0) {
77
-            if ($phpcsFile->findPrevious(T_OPEN_TAG, ($stackPtr - 1)) !== false) {
77
+            if ($phpcsFile->findPrevious(T_OPEN_TAG, ($stackPtr - 1)) !== FALSE) {
78 78
                 return;
79 79
             }
80 80
         }
@@ -84,7 +84,7 @@  discard block
 block discarded – undo
84 84
         // removes the application root from the beginning of the file path
85 85
         $locationPath = self::_getLocationPath($filePath, $this->_getAppRoot());
86 86
         // add an error, if application root doesn't exist in current file path
87
-        if (false === $locationPath) {
87
+        if (FALSE === $locationPath) {
88 88
             $error = 'Unable to find "' . $this->_getAppRoot() . '" in file path "' . $filePath . '". Please set your project\'s application root.';
89 89
             $phpcsFile->addError($error, count($tokens) - 1);
90 90
             return;
@@ -93,8 +93,8 @@  discard block
 block discarded – undo
93 93
         $commentTemplate = "Location: $locationPath";
94 94
 
95 95
         $currentToken = count($tokens) - 1;
96
-        $hasClosingLocationComment = false;
97
-        $isNotAWhitespaceOrAComment = false;
96
+        $hasClosingLocationComment = FALSE;
97
+        $isNotAWhitespaceOrAComment = FALSE;
98 98
         while ($currentToken >= 0
99 99
             && ! $isNotAWhitespaceOrAComment
100 100
             && ! $hasClosingLocationComment
@@ -104,13 +104,13 @@  discard block
 block discarded – undo
104 104
             if (T_COMMENT === $tokenCode) {
105 105
                 $commentString = self::_getCommentContent($token['content']);
106 106
                 if (0 === strcmp($commentString, $commentTemplate)) {
107
-                    $hasClosingLocationComment = true;
107
+                    $hasClosingLocationComment = TRUE;
108 108
                 }
109 109
             } else if (T_WHITESPACE === $tokenCode) {
110 110
                 // Whitespaces are allowed between the closing file comment,
111 111
                 //other comments and end of file
112 112
             } else {
113
-                $isNotAWhitespaceOrAComment = true;
113
+                $isNotAWhitespaceOrAComment = TRUE;
114 114
             }
115 115
             $currentToken--;
116 116
         }
@@ -142,8 +142,8 @@  discard block
 block discarded – undo
142 142
         // removes the path to application root
143 143
         // from the beginning of the file path
144 144
         $appRootAt = strpos($filePath, $appRoot);
145
-        if (false === $appRootAt) {
146
-            return false;
145
+        if (FALSE === $appRootAt) {
146
+            return FALSE;
147 147
         }
148 148
         $localPath = substr($filePath, $appRootAt + strlen($appRoot));
149 149
         // ensures the location path to be a relative path starting with "./".
@@ -172,7 +172,7 @@  discard block
 block discarded – undo
172 172
     private function _getAppRoot()
173 173
     {
174 174
         $appRoot = Common::getConfigData('ci_application_root');
175
-        if (null === $appRoot) {
175
+        if (NULL === $appRoot) {
176 176
             $appRoot = $this->applicationRoot;
177 177
         }
178 178
         return $appRoot;
Please login to merge, or discard this patch.
RoboFile.php 3 patches
Doc Comments   +5 added lines, -1 removed lines patch added patch discarded remove patch
@@ -2,6 +2,10 @@  discard block
 block discarded – undo
2 2
 if ( ! function_exists('glob_recursive'))
3 3
 {
4 4
 	// Does not support flag GLOB_BRACE
5
+
6
+	/**
7
+	 * @param string $pattern
8
+	 */
5 9
 	function glob_recursive($pattern, $flags = 0)
6 10
 	{
7 11
 		$files = glob($pattern, $flags);
@@ -320,7 +324,7 @@  discard block
 block discarded – undo
320 324
 	 * Shortcut for joining an array of command arguments
321 325
 	 * and then running it
322 326
 	 *
323
-	 * @param array $cmd_parts - command arguments
327
+	 * @param string[] $cmd_parts - command arguments
324 328
 	 * @param string $join_on - what to join the command arguments with
325 329
 	 */
326 330
 	protected function _run(array $cmd_parts, $join_on = ' ')
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -6,9 +6,9 @@  discard block
 block discarded – undo
6 6
 	{
7 7
 		$files = glob($pattern, $flags);
8 8
 
9
-		foreach (glob(dirname($pattern).'/*', GLOB_ONLYDIR|GLOB_NOSORT) as $dir)
9
+		foreach (glob(dirname($pattern) . '/*', GLOB_ONLYDIR | GLOB_NOSORT) as $dir)
10 10
 		{
11
-			$files = array_merge($files, glob_recursive($dir.'/'.basename($pattern), $flags));
11
+			$files = array_merge($files, glob_recursive($dir . '/' . basename($pattern), $flags));
12 12
 		}
13 13
 
14 14
 		return $files;
@@ -80,13 +80,13 @@  discard block
 block discarded – undo
80 80
 			'build/humbug.json',
81 81
 			'build/humbug-log.txt',
82 82
 		];
83
-		array_map(function ($file) {
83
+		array_map(function($file) {
84 84
 			@unlink($file);
85 85
 		}, $cleanFiles);
86 86
 
87 87
 		// So the task doesn't complain,
88 88
 		// make any 'missing' dirs to cleanup
89
-		array_map(function ($dir) {
89
+		array_map(function($dir) {
90 90
 			if ( ! is_dir($dir))
91 91
 			{
92 92
 				`mkdir -p {$dir}`;
@@ -130,7 +130,7 @@  discard block
 block discarded – undo
130 130
 
131 131
 		$chunks = array_chunk($files, 6);
132 132
 
133
-		foreach($chunks as $chunk)
133
+		foreach ($chunks as $chunk)
134 134
 		{
135 135
 			$this->parallelLint($chunk);
136 136
 		}
@@ -241,10 +241,10 @@  discard block
 block discarded – undo
241 241
 			->monitor('composer.json', function() {
242 242
 				$this->taskComposerUpdate()->run();
243 243
 			})
244
-			->monitor('src', function () {
244
+			->monitor('src', function() {
245 245
 				$this->taskExec('test')->run();
246 246
 			})
247
-			->monitor('tests', function () {
247
+			->monitor('tests', function() {
248 248
 				$this->taskExec('test')->run();
249 249
 			})
250 250
 			->run();
@@ -295,7 +295,7 @@  discard block
 block discarded – undo
295 295
 			->timeout(5)
296 296
 			->printed(FALSE);
297 297
 
298
-		foreach($chunk as $file)
298
+		foreach ($chunk as $file)
299 299
 		{
300 300
 			$task = $task->process("php -l {$file}");
301 301
 		}
Please login to merge, or discard this patch.
Upper-Lower-Casing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -104,7 +104,7 @@  discard block
 block discarded – undo
104 104
 	{
105 105
 		$this->taskPhpUnit()
106 106
 			->configFile('build/phpunit.xml')
107
-			->printed(true)
107
+			->printed(TRUE)
108 108
 			->run();
109 109
 	}
110 110
 
@@ -228,7 +228,7 @@  discard block
 block discarded – undo
228 228
 		$this->lint();
229 229
 		$this->taskPHPUnit()
230 230
 			->configFile('phpunit.xml')
231
-			->printed(true)
231
+			->printed(TRUE)
232 232
 			->run();
233 233
 	}
234 234
 
Please login to merge, or discard this patch.