Completed
Pull Request — develop (#1492)
by Zack
18:42
created
PHPCompatibility/Sniffs/Lists/NewListReferenceAssignmentSniff.php 3 patches
Indentation   +37 added lines, -37 removed lines patch added patch discarded remove patch
@@ -25,43 +25,43 @@
 block discarded – undo
25 25
  */
26 26
 class NewListReferenceAssignmentSniff extends NewKeyedListSniff
27 27
 {
28
-    /**
29
-     * The token(s) within the list construct which is being targeted.
30
-     *
31
-     * @var array
32
-     */
33
-    protected $targetsInList = array(
34
-        \T_BITWISE_AND => \T_BITWISE_AND,
35
-    );
28
+	/**
29
+	 * The token(s) within the list construct which is being targeted.
30
+	 *
31
+	 * @var array
32
+	 */
33
+	protected $targetsInList = array(
34
+		\T_BITWISE_AND => \T_BITWISE_AND,
35
+	);
36 36
 
37
-    /**
38
-     * Do a version check to determine if this sniff needs to run at all.
39
-     *
40
-     * @return bool
41
-     */
42
-    protected function bowOutEarly()
43
-    {
44
-        return ($this->supportsBelow('7.2') === false);
45
-    }
37
+	/**
38
+	 * Do a version check to determine if this sniff needs to run at all.
39
+	 *
40
+	 * @return bool
41
+	 */
42
+	protected function bowOutEarly()
43
+	{
44
+		return ($this->supportsBelow('7.2') === false);
45
+	}
46 46
 
47
-    /**
48
-     * Examine the contents of a list construct to determine whether an error needs to be thrown.
49
-     *
50
-     * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned.
51
-     * @param int                   $opener    The position of the list open token.
52
-     * @param int                   $closer    The position of the list close token.
53
-     *
54
-     * @return void
55
-     */
56
-    protected function examineList(File $phpcsFile, $opener, $closer)
57
-    {
58
-        $start = $opener;
59
-        while (($start = $this->hasTargetInList($phpcsFile, $start, $closer)) !== false) {
60
-            $phpcsFile->addError(
61
-                'Reference assignments within list constructs are not supported in PHP 7.2 or earlier.',
62
-                $start,
63
-                'Found'
64
-            );
65
-        }
66
-    }
47
+	/**
48
+	 * Examine the contents of a list construct to determine whether an error needs to be thrown.
49
+	 *
50
+	 * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned.
51
+	 * @param int                   $opener    The position of the list open token.
52
+	 * @param int                   $closer    The position of the list close token.
53
+	 *
54
+	 * @return void
55
+	 */
56
+	protected function examineList(File $phpcsFile, $opener, $closer)
57
+	{
58
+		$start = $opener;
59
+		while (($start = $this->hasTargetInList($phpcsFile, $start, $closer)) !== false) {
60
+			$phpcsFile->addError(
61
+				'Reference assignments within list constructs are not supported in PHP 7.2 or earlier.',
62
+				$start,
63
+				'Found'
64
+			);
65
+		}
66
+	}
67 67
 }
Please login to merge, or discard this patch.
Spacing   +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
     protected function bowOutEarly()
43 43
     {
44
-        return ($this->supportsBelow('7.2') === false);
44
+        return ( $this->supportsBelow( '7.2' ) === false );
45 45
     }
46 46
 
47 47
     /**
@@ -53,10 +53,10 @@  discard block
 block discarded – undo
53 53
      *
54 54
      * @return void
55 55
      */
56
-    protected function examineList(File $phpcsFile, $opener, $closer)
56
+    protected function examineList( File $phpcsFile, $opener, $closer )
57 57
     {
58 58
         $start = $opener;
59
-        while (($start = $this->hasTargetInList($phpcsFile, $start, $closer)) !== false) {
59
+        while ( ( $start = $this->hasTargetInList( $phpcsFile, $start, $closer ) ) !== false ) {
60 60
             $phpcsFile->addError(
61 61
                 'Reference assignments within list constructs are not supported in PHP 7.2 or earlier.',
62 62
                 $start,
Please login to merge, or discard this patch.
Braces   +3 added lines, -6 removed lines patch added patch discarded remove patch
@@ -23,8 +23,7 @@  discard block
 block discarded – undo
23 23
  * @package  PHPCompatibility
24 24
  * @author   Juliette Reinders Folmer <[email protected]>
25 25
  */
26
-class NewListReferenceAssignmentSniff extends NewKeyedListSniff
27
-{
26
+class NewListReferenceAssignmentSniff extends NewKeyedListSniff {
28 27
     /**
29 28
      * The token(s) within the list construct which is being targeted.
30 29
      *
@@ -39,8 +38,7 @@  discard block
 block discarded – undo
39 38
      *
40 39
      * @return bool
41 40
      */
42
-    protected function bowOutEarly()
43
-    {
41
+    protected function bowOutEarly() {
44 42
         return ($this->supportsBelow('7.2') === false);
45 43
     }
46 44
 
@@ -53,8 +51,7 @@  discard block
 block discarded – undo
53 51
      *
54 52
      * @return void
55 53
      */
56
-    protected function examineList(File $phpcsFile, $opener, $closer)
57
-    {
54
+    protected function examineList(File $phpcsFile, $opener, $closer) {
58 55
         $start = $opener;
59 56
         while (($start = $this->hasTargetInList($phpcsFile, $start, $closer)) !== false) {
60 57
             $phpcsFile->addError(
Please login to merge, or discard this patch.
php-compatibility/PHPCompatibility/Sniffs/Lists/AssignmentOrderSniff.php 3 patches
Indentation   +131 added lines, -131 removed lines patch added patch discarded remove patch
@@ -30,154 +30,154 @@
 block discarded – undo
30 30
 class AssignmentOrderSniff extends Sniff
31 31
 {
32 32
 
33
-    /**
34
-     * Returns an array of tokens this test wants to listen for.
35
-     *
36
-     * @return array
37
-     */
38
-    public function register()
39
-    {
40
-        return array(
41
-            \T_LIST,
42
-            \T_OPEN_SHORT_ARRAY,
43
-        );
44
-    }
45
-
46
-
47
-    /**
48
-     * Processes this test, when one of its tokens is encountered.
49
-     *
50
-     * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned.
51
-     * @param int                   $stackPtr  The position of the current token in the
52
-     *                                         stack passed in $tokens.
53
-     *
54
-     * @return void|int Void if not a valid list. If a list construct has been
55
-     *                  examined, the stack pointer to the list closer to skip
56
-     *                  passed any nested lists which don't need to be examined again.
57
-     */
58
-    public function process(File $phpcsFile, $stackPtr)
59
-    {
60
-        if ($this->supportsAbove('7.0') === false) {
61
-            return;
62
-        }
63
-
64
-        $tokens = $phpcsFile->getTokens();
65
-
66
-        if ($tokens[$stackPtr]['code'] === \T_OPEN_SHORT_ARRAY
67
-            && $this->isShortList($phpcsFile, $stackPtr) === false
68
-        ) {
69
-            // Short array, not short list.
70
-            return;
71
-        }
72
-
73
-        if ($tokens[$stackPtr]['code'] === \T_LIST) {
74
-            $nextNonEmpty = $phpcsFile->findNext(Tokens::$emptyTokens, ($stackPtr + 1), null, true);
75
-            if ($nextNonEmpty === false
76
-                || $tokens[$nextNonEmpty]['code'] !== \T_OPEN_PARENTHESIS
77
-                || isset($tokens[$nextNonEmpty]['parenthesis_closer']) === false
78
-            ) {
79
-                // Parse error or live coding.
80
-                return;
81
-            }
82
-
83
-            $opener = $nextNonEmpty;
84
-            $closer = $tokens[$nextNonEmpty]['parenthesis_closer'];
85
-        } else {
86
-            // Short list syntax.
87
-            $opener = $stackPtr;
88
-
89
-            if (isset($tokens[$stackPtr]['bracket_closer'])) {
90
-                $closer = $tokens[$stackPtr]['bracket_closer'];
91
-            }
92
-        }
93
-
94
-        if (isset($opener, $closer) === false) {
95
-            return;
96
-        }
97
-
98
-        /*
33
+	/**
34
+	 * Returns an array of tokens this test wants to listen for.
35
+	 *
36
+	 * @return array
37
+	 */
38
+	public function register()
39
+	{
40
+		return array(
41
+			\T_LIST,
42
+			\T_OPEN_SHORT_ARRAY,
43
+		);
44
+	}
45
+
46
+
47
+	/**
48
+	 * Processes this test, when one of its tokens is encountered.
49
+	 *
50
+	 * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned.
51
+	 * @param int                   $stackPtr  The position of the current token in the
52
+	 *                                         stack passed in $tokens.
53
+	 *
54
+	 * @return void|int Void if not a valid list. If a list construct has been
55
+	 *                  examined, the stack pointer to the list closer to skip
56
+	 *                  passed any nested lists which don't need to be examined again.
57
+	 */
58
+	public function process(File $phpcsFile, $stackPtr)
59
+	{
60
+		if ($this->supportsAbove('7.0') === false) {
61
+			return;
62
+		}
63
+
64
+		$tokens = $phpcsFile->getTokens();
65
+
66
+		if ($tokens[$stackPtr]['code'] === \T_OPEN_SHORT_ARRAY
67
+			&& $this->isShortList($phpcsFile, $stackPtr) === false
68
+		) {
69
+			// Short array, not short list.
70
+			return;
71
+		}
72
+
73
+		if ($tokens[$stackPtr]['code'] === \T_LIST) {
74
+			$nextNonEmpty = $phpcsFile->findNext(Tokens::$emptyTokens, ($stackPtr + 1), null, true);
75
+			if ($nextNonEmpty === false
76
+				|| $tokens[$nextNonEmpty]['code'] !== \T_OPEN_PARENTHESIS
77
+				|| isset($tokens[$nextNonEmpty]['parenthesis_closer']) === false
78
+			) {
79
+				// Parse error or live coding.
80
+				return;
81
+			}
82
+
83
+			$opener = $nextNonEmpty;
84
+			$closer = $tokens[$nextNonEmpty]['parenthesis_closer'];
85
+		} else {
86
+			// Short list syntax.
87
+			$opener = $stackPtr;
88
+
89
+			if (isset($tokens[$stackPtr]['bracket_closer'])) {
90
+				$closer = $tokens[$stackPtr]['bracket_closer'];
91
+			}
92
+		}
93
+
94
+		if (isset($opener, $closer) === false) {
95
+			return;
96
+		}
97
+
98
+		/*
99 99
          * OK, so we have the opener & closer, now we need to check all the variables in the
100 100
          * list() to see if there are duplicates as that's the problem.
101 101
          */
102
-        $hasVars = $phpcsFile->findNext(array(\T_VARIABLE, \T_DOLLAR), ($opener + 1), $closer);
103
-        if ($hasVars === false) {
104
-            // Empty list, not our concern.
105
-            return ($closer + 1);
106
-        }
107
-
108
-        // Set the variable delimiters based on the list type being examined.
109
-        $stopPoints = array(\T_COMMA);
110
-        if ($tokens[$stackPtr]['code'] === \T_OPEN_SHORT_ARRAY) {
111
-            $stopPoints[] = \T_CLOSE_SHORT_ARRAY;
112
-        } else {
113
-            $stopPoints[] = \T_CLOSE_PARENTHESIS;
114
-        }
115
-
116
-        $listVars      = array();
117
-        $lastStopPoint = $opener;
118
-
119
-        /*
102
+		$hasVars = $phpcsFile->findNext(array(\T_VARIABLE, \T_DOLLAR), ($opener + 1), $closer);
103
+		if ($hasVars === false) {
104
+			// Empty list, not our concern.
105
+			return ($closer + 1);
106
+		}
107
+
108
+		// Set the variable delimiters based on the list type being examined.
109
+		$stopPoints = array(\T_COMMA);
110
+		if ($tokens[$stackPtr]['code'] === \T_OPEN_SHORT_ARRAY) {
111
+			$stopPoints[] = \T_CLOSE_SHORT_ARRAY;
112
+		} else {
113
+			$stopPoints[] = \T_CLOSE_PARENTHESIS;
114
+		}
115
+
116
+		$listVars      = array();
117
+		$lastStopPoint = $opener;
118
+
119
+		/*
120 120
          * Create a list of all variables used within the `list()` construct.
121 121
          * We're not concerned with whether these are nested or not, as any duplicate
122 122
          * variable name used will be problematic, independent of nesting.
123 123
          */
124
-        do {
125
-            $nextStopPoint = $phpcsFile->findNext($stopPoints, ($lastStopPoint + 1), $closer);
126
-            if ($nextStopPoint === false) {
127
-                $nextStopPoint = $closer;
128
-            }
129
-
130
-            // Also detect this in PHP 7.1 keyed lists.
131
-            $hasDoubleArrow = $phpcsFile->findNext(\T_DOUBLE_ARROW, ($lastStopPoint + 1), $nextStopPoint);
132
-            if ($hasDoubleArrow !== false) {
133
-                $lastStopPoint = $hasDoubleArrow;
134
-            }
135
-
136
-            // Find the start of the variable, allowing for variable variables.
137
-            $nextStartPoint = $phpcsFile->findNext(array(\T_VARIABLE, \T_DOLLAR), ($lastStopPoint + 1), $nextStopPoint);
138
-            if ($nextStartPoint === false) {
139
-                // Skip past empty bits in the list, i.e. `list( $a, , ,)`.
140
-                $lastStopPoint = $nextStopPoint;
141
-                continue;
142
-            }
143
-
144
-            /*
124
+		do {
125
+			$nextStopPoint = $phpcsFile->findNext($stopPoints, ($lastStopPoint + 1), $closer);
126
+			if ($nextStopPoint === false) {
127
+				$nextStopPoint = $closer;
128
+			}
129
+
130
+			// Also detect this in PHP 7.1 keyed lists.
131
+			$hasDoubleArrow = $phpcsFile->findNext(\T_DOUBLE_ARROW, ($lastStopPoint + 1), $nextStopPoint);
132
+			if ($hasDoubleArrow !== false) {
133
+				$lastStopPoint = $hasDoubleArrow;
134
+			}
135
+
136
+			// Find the start of the variable, allowing for variable variables.
137
+			$nextStartPoint = $phpcsFile->findNext(array(\T_VARIABLE, \T_DOLLAR), ($lastStopPoint + 1), $nextStopPoint);
138
+			if ($nextStartPoint === false) {
139
+				// Skip past empty bits in the list, i.e. `list( $a, , ,)`.
140
+				$lastStopPoint = $nextStopPoint;
141
+				continue;
142
+			}
143
+
144
+			/*
145 145
              * Gather the content of all non-empty tokens to determine the "variable name".
146 146
              * Variable name in this context includes array or object property syntaxes, such
147 147
              * as `$a['name']` and `$b->property`.
148 148
              */
149
-            $varContent = '';
149
+			$varContent = '';
150 150
 
151
-            for ($i = $nextStartPoint; $i < $nextStopPoint; $i++) {
152
-                if (isset(Tokens::$emptyTokens[$tokens[$i]['code']])) {
153
-                    continue;
154
-                }
151
+			for ($i = $nextStartPoint; $i < $nextStopPoint; $i++) {
152
+				if (isset(Tokens::$emptyTokens[$tokens[$i]['code']])) {
153
+					continue;
154
+				}
155 155
 
156
-                $varContent .= $tokens[$i]['content'];
157
-            }
156
+				$varContent .= $tokens[$i]['content'];
157
+			}
158 158
 
159
-            if ($varContent !== '') {
160
-                $listVars[] = $varContent;
161
-            }
159
+			if ($varContent !== '') {
160
+				$listVars[] = $varContent;
161
+			}
162 162
 
163
-            $lastStopPoint = $nextStopPoint;
163
+			$lastStopPoint = $nextStopPoint;
164 164
 
165
-        } while ($lastStopPoint < $closer);
165
+		} while ($lastStopPoint < $closer);
166 166
 
167
-        if (empty($listVars)) {
168
-            // Shouldn't be possible, but just in case.
169
-            return ($closer + 1);
170
-        }
167
+		if (empty($listVars)) {
168
+			// Shouldn't be possible, but just in case.
169
+			return ($closer + 1);
170
+		}
171 171
 
172
-        // Verify that all variables used in the list() construct are unique.
173
-        if (\count($listVars) !== \count(array_unique($listVars))) {
174
-            $phpcsFile->addError(
175
-                'list() will assign variable from left-to-right since PHP 7.0. Ensure all variables in list() are unique to prevent unexpected results.',
176
-                $stackPtr,
177
-                'Affected'
178
-            );
179
-        }
172
+		// Verify that all variables used in the list() construct are unique.
173
+		if (\count($listVars) !== \count(array_unique($listVars))) {
174
+			$phpcsFile->addError(
175
+				'list() will assign variable from left-to-right since PHP 7.0. Ensure all variables in list() are unique to prevent unexpected results.',
176
+				$stackPtr,
177
+				'Affected'
178
+			);
179
+		}
180 180
 
181
-        return ($closer + 1);
182
-    }
181
+		return ($closer + 1);
182
+	}
183 183
 }
Please login to merge, or discard this patch.
Spacing   +36 added lines, -36 removed lines patch added patch discarded remove patch
@@ -55,43 +55,43 @@  discard block
 block discarded – undo
55 55
      *                  examined, the stack pointer to the list closer to skip
56 56
      *                  passed any nested lists which don't need to be examined again.
57 57
      */
58
-    public function process(File $phpcsFile, $stackPtr)
58
+    public function process( File $phpcsFile, $stackPtr )
59 59
     {
60
-        if ($this->supportsAbove('7.0') === false) {
60
+        if ( $this->supportsAbove( '7.0' ) === false ) {
61 61
             return;
62 62
         }
63 63
 
64 64
         $tokens = $phpcsFile->getTokens();
65 65
 
66
-        if ($tokens[$stackPtr]['code'] === \T_OPEN_SHORT_ARRAY
67
-            && $this->isShortList($phpcsFile, $stackPtr) === false
66
+        if ( $tokens[ $stackPtr ][ 'code' ] === \T_OPEN_SHORT_ARRAY
67
+            && $this->isShortList( $phpcsFile, $stackPtr ) === false
68 68
         ) {
69 69
             // Short array, not short list.
70 70
             return;
71 71
         }
72 72
 
73
-        if ($tokens[$stackPtr]['code'] === \T_LIST) {
74
-            $nextNonEmpty = $phpcsFile->findNext(Tokens::$emptyTokens, ($stackPtr + 1), null, true);
75
-            if ($nextNonEmpty === false
76
-                || $tokens[$nextNonEmpty]['code'] !== \T_OPEN_PARENTHESIS
77
-                || isset($tokens[$nextNonEmpty]['parenthesis_closer']) === false
73
+        if ( $tokens[ $stackPtr ][ 'code' ] === \T_LIST ) {
74
+            $nextNonEmpty = $phpcsFile->findNext( Tokens::$emptyTokens, ( $stackPtr + 1 ), null, true );
75
+            if ( $nextNonEmpty === false
76
+                || $tokens[ $nextNonEmpty ][ 'code' ] !== \T_OPEN_PARENTHESIS
77
+                || isset( $tokens[ $nextNonEmpty ][ 'parenthesis_closer' ] ) === false
78 78
             ) {
79 79
                 // Parse error or live coding.
80 80
                 return;
81 81
             }
82 82
 
83 83
             $opener = $nextNonEmpty;
84
-            $closer = $tokens[$nextNonEmpty]['parenthesis_closer'];
84
+            $closer = $tokens[ $nextNonEmpty ][ 'parenthesis_closer' ];
85 85
         } else {
86 86
             // Short list syntax.
87 87
             $opener = $stackPtr;
88 88
 
89
-            if (isset($tokens[$stackPtr]['bracket_closer'])) {
90
-                $closer = $tokens[$stackPtr]['bracket_closer'];
89
+            if ( isset( $tokens[ $stackPtr ][ 'bracket_closer' ] ) ) {
90
+                $closer = $tokens[ $stackPtr ][ 'bracket_closer' ];
91 91
             }
92 92
         }
93 93
 
94
-        if (isset($opener, $closer) === false) {
94
+        if ( isset( $opener, $closer ) === false ) {
95 95
             return;
96 96
         }
97 97
 
@@ -99,18 +99,18 @@  discard block
 block discarded – undo
99 99
          * OK, so we have the opener & closer, now we need to check all the variables in the
100 100
          * list() to see if there are duplicates as that's the problem.
101 101
          */
102
-        $hasVars = $phpcsFile->findNext(array(\T_VARIABLE, \T_DOLLAR), ($opener + 1), $closer);
103
-        if ($hasVars === false) {
102
+        $hasVars = $phpcsFile->findNext( array( \T_VARIABLE, \T_DOLLAR ), ( $opener + 1 ), $closer );
103
+        if ( $hasVars === false ) {
104 104
             // Empty list, not our concern.
105
-            return ($closer + 1);
105
+            return ( $closer + 1 );
106 106
         }
107 107
 
108 108
         // Set the variable delimiters based on the list type being examined.
109
-        $stopPoints = array(\T_COMMA);
110
-        if ($tokens[$stackPtr]['code'] === \T_OPEN_SHORT_ARRAY) {
111
-            $stopPoints[] = \T_CLOSE_SHORT_ARRAY;
109
+        $stopPoints = array( \T_COMMA );
110
+        if ( $tokens[ $stackPtr ][ 'code' ] === \T_OPEN_SHORT_ARRAY ) {
111
+            $stopPoints[ ] = \T_CLOSE_SHORT_ARRAY;
112 112
         } else {
113
-            $stopPoints[] = \T_CLOSE_PARENTHESIS;
113
+            $stopPoints[ ] = \T_CLOSE_PARENTHESIS;
114 114
         }
115 115
 
116 116
         $listVars      = array();
@@ -122,20 +122,20 @@  discard block
 block discarded – undo
122 122
          * variable name used will be problematic, independent of nesting.
123 123
          */
124 124
         do {
125
-            $nextStopPoint = $phpcsFile->findNext($stopPoints, ($lastStopPoint + 1), $closer);
126
-            if ($nextStopPoint === false) {
125
+            $nextStopPoint = $phpcsFile->findNext( $stopPoints, ( $lastStopPoint + 1 ), $closer );
126
+            if ( $nextStopPoint === false ) {
127 127
                 $nextStopPoint = $closer;
128 128
             }
129 129
 
130 130
             // Also detect this in PHP 7.1 keyed lists.
131
-            $hasDoubleArrow = $phpcsFile->findNext(\T_DOUBLE_ARROW, ($lastStopPoint + 1), $nextStopPoint);
132
-            if ($hasDoubleArrow !== false) {
131
+            $hasDoubleArrow = $phpcsFile->findNext( \T_DOUBLE_ARROW, ( $lastStopPoint + 1 ), $nextStopPoint );
132
+            if ( $hasDoubleArrow !== false ) {
133 133
                 $lastStopPoint = $hasDoubleArrow;
134 134
             }
135 135
 
136 136
             // Find the start of the variable, allowing for variable variables.
137
-            $nextStartPoint = $phpcsFile->findNext(array(\T_VARIABLE, \T_DOLLAR), ($lastStopPoint + 1), $nextStopPoint);
138
-            if ($nextStartPoint === false) {
137
+            $nextStartPoint = $phpcsFile->findNext( array( \T_VARIABLE, \T_DOLLAR ), ( $lastStopPoint + 1 ), $nextStopPoint );
138
+            if ( $nextStartPoint === false ) {
139 139
                 // Skip past empty bits in the list, i.e. `list( $a, , ,)`.
140 140
                 $lastStopPoint = $nextStopPoint;
141 141
                 continue;
@@ -148,29 +148,29 @@  discard block
 block discarded – undo
148 148
              */
149 149
             $varContent = '';
150 150
 
151
-            for ($i = $nextStartPoint; $i < $nextStopPoint; $i++) {
152
-                if (isset(Tokens::$emptyTokens[$tokens[$i]['code']])) {
151
+            for ( $i = $nextStartPoint; $i < $nextStopPoint; $i++ ) {
152
+                if ( isset( Tokens::$emptyTokens[ $tokens[ $i ][ 'code' ] ] ) ) {
153 153
                     continue;
154 154
                 }
155 155
 
156
-                $varContent .= $tokens[$i]['content'];
156
+                $varContent .= $tokens[ $i ][ 'content' ];
157 157
             }
158 158
 
159
-            if ($varContent !== '') {
160
-                $listVars[] = $varContent;
159
+            if ( $varContent !== '' ) {
160
+                $listVars[ ] = $varContent;
161 161
             }
162 162
 
163 163
             $lastStopPoint = $nextStopPoint;
164 164
 
165
-        } while ($lastStopPoint < $closer);
165
+        } while ( $lastStopPoint < $closer );
166 166
 
167
-        if (empty($listVars)) {
167
+        if ( empty( $listVars ) ) {
168 168
             // Shouldn't be possible, but just in case.
169
-            return ($closer + 1);
169
+            return ( $closer + 1 );
170 170
         }
171 171
 
172 172
         // Verify that all variables used in the list() construct are unique.
173
-        if (\count($listVars) !== \count(array_unique($listVars))) {
173
+        if ( \count( $listVars ) !== \count( array_unique( $listVars ) ) ) {
174 174
             $phpcsFile->addError(
175 175
                 'list() will assign variable from left-to-right since PHP 7.0. Ensure all variables in list() are unique to prevent unexpected results.',
176 176
                 $stackPtr,
@@ -178,6 +178,6 @@  discard block
 block discarded – undo
178 178
             );
179 179
         }
180 180
 
181
-        return ($closer + 1);
181
+        return ( $closer + 1 );
182 182
     }
183 183
 }
Please login to merge, or discard this patch.
Braces   +3 added lines, -6 removed lines patch added patch discarded remove patch
@@ -27,16 +27,14 @@  discard block
 block discarded – undo
27 27
  * @package  PHPCompatibility
28 28
  * @author   Juliette Reinders Folmer <[email protected]>
29 29
  */
30
-class AssignmentOrderSniff extends Sniff
31
-{
30
+class AssignmentOrderSniff extends Sniff {
32 31
 
33 32
     /**
34 33
      * Returns an array of tokens this test wants to listen for.
35 34
      *
36 35
      * @return array
37 36
      */
38
-    public function register()
39
-    {
37
+    public function register() {
40 38
         return array(
41 39
             \T_LIST,
42 40
             \T_OPEN_SHORT_ARRAY,
@@ -55,8 +53,7 @@  discard block
 block discarded – undo
55 53
      *                  examined, the stack pointer to the list closer to skip
56 54
      *                  passed any nested lists which don't need to be examined again.
57 55
      */
58
-    public function process(File $phpcsFile, $stackPtr)
59
-    {
56
+    public function process(File $phpcsFile, $stackPtr) {
60 57
         if ($this->supportsAbove('7.0') === false) {
61 58
             return;
62 59
         }
Please login to merge, or discard this patch.
PHPCompatibility/Sniffs/Syntax/NewDynamicAccessToStaticSniff.php 4 patches
Indentation   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -30,56 +30,56 @@
 block discarded – undo
30 30
 class NewDynamicAccessToStaticSniff extends Sniff
31 31
 {
32 32
 
33
-    /**
34
-     * Returns an array of tokens this test wants to listen for.
35
-     *
36
-     * @return array
37
-     */
38
-    public function register()
39
-    {
40
-        return array(
41
-            \T_DOUBLE_COLON,
42
-        );
43
-    }
33
+	/**
34
+	 * Returns an array of tokens this test wants to listen for.
35
+	 *
36
+	 * @return array
37
+	 */
38
+	public function register()
39
+	{
40
+		return array(
41
+			\T_DOUBLE_COLON,
42
+		);
43
+	}
44 44
 
45
-    /**
46
-     * Processes this test, when one of its tokens is encountered.
47
-     *
48
-     * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned.
49
-     * @param int                   $stackPtr  The position of the current token in the
50
-     *                                         stack passed in $tokens.
51
-     *
52
-     * @return void
53
-     */
54
-    public function process(File $phpcsFile, $stackPtr)
55
-    {
56
-        if ($this->supportsBelow('5.2') === false) {
57
-            return;
58
-        }
45
+	/**
46
+	 * Processes this test, when one of its tokens is encountered.
47
+	 *
48
+	 * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned.
49
+	 * @param int                   $stackPtr  The position of the current token in the
50
+	 *                                         stack passed in $tokens.
51
+	 *
52
+	 * @return void
53
+	 */
54
+	public function process(File $phpcsFile, $stackPtr)
55
+	{
56
+		if ($this->supportsBelow('5.2') === false) {
57
+			return;
58
+		}
59 59
 
60
-        $tokens       = $phpcsFile->getTokens();
61
-        $prevNonEmpty = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($stackPtr - 1), null, true);
60
+		$tokens       = $phpcsFile->getTokens();
61
+		$prevNonEmpty = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($stackPtr - 1), null, true);
62 62
 
63
-        // Disregard `static::` as well. Late static binding is reported by another sniff.
64
-        if ($tokens[$prevNonEmpty]['code'] === \T_SELF
65
-            || $tokens[$prevNonEmpty]['code'] === \T_PARENT
66
-            || $tokens[$prevNonEmpty]['code'] === \T_STATIC
67
-        ) {
68
-            return;
69
-        }
63
+		// Disregard `static::` as well. Late static binding is reported by another sniff.
64
+		if ($tokens[$prevNonEmpty]['code'] === \T_SELF
65
+			|| $tokens[$prevNonEmpty]['code'] === \T_PARENT
66
+			|| $tokens[$prevNonEmpty]['code'] === \T_STATIC
67
+		) {
68
+			return;
69
+		}
70 70
 
71
-        if ($tokens[$prevNonEmpty]['code'] === \T_STRING) {
72
-            $prevPrevNonEmpty = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($prevNonEmpty - 1), null, true);
71
+		if ($tokens[$prevNonEmpty]['code'] === \T_STRING) {
72
+			$prevPrevNonEmpty = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($prevNonEmpty - 1), null, true);
73 73
 
74
-            if ($tokens[$prevPrevNonEmpty]['code'] !== \T_OBJECT_OPERATOR) {
75
-                return;
76
-            }
77
-        }
74
+			if ($tokens[$prevPrevNonEmpty]['code'] !== \T_OBJECT_OPERATOR) {
75
+				return;
76
+			}
77
+		}
78 78
 
79
-        $phpcsFile->addError(
80
-            'Static class properties and methods, as well as class constants, could not be accessed using a dynamic (variable) classname in PHP 5.2 or earlier.',
81
-            $stackPtr,
82
-            'Found'
83
-        );
84
-    }
79
+		$phpcsFile->addError(
80
+			'Static class properties and methods, as well as class constants, could not be accessed using a dynamic (variable) classname in PHP 5.2 or earlier.',
81
+			$stackPtr,
82
+			'Found'
83
+		);
84
+	}
85 85
 }
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -51,27 +51,27 @@
 block discarded – undo
51 51
      *
52 52
      * @return void
53 53
      */
54
-    public function process(File $phpcsFile, $stackPtr)
54
+    public function process( File $phpcsFile, $stackPtr )
55 55
     {
56
-        if ($this->supportsBelow('5.2') === false) {
56
+        if ( $this->supportsBelow( '5.2' ) === false ) {
57 57
             return;
58 58
         }
59 59
 
60 60
         $tokens       = $phpcsFile->getTokens();
61
-        $prevNonEmpty = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($stackPtr - 1), null, true);
61
+        $prevNonEmpty = $phpcsFile->findPrevious( Tokens::$emptyTokens, ( $stackPtr - 1 ), null, true );
62 62
 
63 63
         // Disregard `static::` as well. Late static binding is reported by another sniff.
64
-        if ($tokens[$prevNonEmpty]['code'] === \T_SELF
65
-            || $tokens[$prevNonEmpty]['code'] === \T_PARENT
66
-            || $tokens[$prevNonEmpty]['code'] === \T_STATIC
64
+        if ( $tokens[ $prevNonEmpty ][ 'code' ] === \T_SELF
65
+            || $tokens[ $prevNonEmpty ][ 'code' ] === \T_PARENT
66
+            || $tokens[ $prevNonEmpty ][ 'code' ] === \T_STATIC
67 67
         ) {
68 68
             return;
69 69
         }
70 70
 
71
-        if ($tokens[$prevNonEmpty]['code'] === \T_STRING) {
72
-            $prevPrevNonEmpty = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($prevNonEmpty - 1), null, true);
71
+        if ( $tokens[ $prevNonEmpty ][ 'code' ] === \T_STRING ) {
72
+            $prevPrevNonEmpty = $phpcsFile->findPrevious( Tokens::$emptyTokens, ( $prevNonEmpty - 1 ), null, true );
73 73
 
74
-            if ($tokens[$prevPrevNonEmpty]['code'] !== \T_OBJECT_OPERATOR) {
74
+            if ( $tokens[ $prevPrevNonEmpty ][ 'code' ] !== \T_OBJECT_OPERATOR ) {
75 75
                 return;
76 76
             }
77 77
         }
Please login to merge, or discard this patch.
Braces   +3 added lines, -6 removed lines patch added patch discarded remove patch
@@ -27,16 +27,14 @@  discard block
 block discarded – undo
27 27
  * @package  PHPCompatibility
28 28
  * @author   Juliette Reinders Folmer <[email protected]>
29 29
  */
30
-class NewDynamicAccessToStaticSniff extends Sniff
31
-{
30
+class NewDynamicAccessToStaticSniff extends Sniff {
32 31
 
33 32
     /**
34 33
      * Returns an array of tokens this test wants to listen for.
35 34
      *
36 35
      * @return array
37 36
      */
38
-    public function register()
39
-    {
37
+    public function register() {
40 38
         return array(
41 39
             \T_DOUBLE_COLON,
42 40
         );
@@ -51,8 +49,7 @@  discard block
 block discarded – undo
51 49
      *
52 50
      * @return void
53 51
      */
54
-    public function process(File $phpcsFile, $stackPtr)
55
-    {
52
+    public function process(File $phpcsFile, $stackPtr) {
56 53
         if ($this->supportsBelow('5.2') === false) {
57 54
             return;
58 55
         }
Please login to merge, or discard this patch.
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -65,7 +65,7 @@
 block discarded – undo
65 65
     /**
66 66
      * Returns an array of tokens this test wants to listen for.
67 67
      *
68
-     * @return array
68
+     * @return integer[]
69 69
      */
70 70
     public function register()
71 71
     {
Please login to merge, or discard this patch.
php-compatibility/PHPCompatibility/Sniffs/Syntax/NewShortArraySniff.php 4 patches
Indentation   +37 added lines, -37 removed lines patch added patch discarded remove patch
@@ -28,47 +28,47 @@
 block discarded – undo
28 28
 class NewShortArraySniff extends Sniff
29 29
 {
30 30
 
31
-    /**
32
-     * Returns an array of tokens this test wants to listen for.
33
-     *
34
-     * @return array
35
-     */
36
-    public function register()
37
-    {
38
-        return array(
39
-            \T_OPEN_SHORT_ARRAY,
40
-            \T_CLOSE_SHORT_ARRAY,
41
-        );
42
-    }
31
+	/**
32
+	 * Returns an array of tokens this test wants to listen for.
33
+	 *
34
+	 * @return array
35
+	 */
36
+	public function register()
37
+	{
38
+		return array(
39
+			\T_OPEN_SHORT_ARRAY,
40
+			\T_CLOSE_SHORT_ARRAY,
41
+		);
42
+	}
43 43
 
44 44
 
45
-    /**
46
-     * Processes this test, when one of its tokens is encountered.
47
-     *
48
-     * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned.
49
-     * @param int                   $stackPtr  The position of the current token in
50
-     *                                         the stack passed in $tokens.
51
-     *
52
-     * @return void
53
-     */
54
-    public function process(File $phpcsFile, $stackPtr)
55
-    {
56
-        if ($this->supportsBelow('5.3') === false) {
57
-            return;
58
-        }
45
+	/**
46
+	 * Processes this test, when one of its tokens is encountered.
47
+	 *
48
+	 * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned.
49
+	 * @param int                   $stackPtr  The position of the current token in
50
+	 *                                         the stack passed in $tokens.
51
+	 *
52
+	 * @return void
53
+	 */
54
+	public function process(File $phpcsFile, $stackPtr)
55
+	{
56
+		if ($this->supportsBelow('5.3') === false) {
57
+			return;
58
+		}
59 59
 
60
-        $tokens = $phpcsFile->getTokens();
61
-        $token  = $tokens[$stackPtr];
60
+		$tokens = $phpcsFile->getTokens();
61
+		$token  = $tokens[$stackPtr];
62 62
 
63
-        $error = '%s is available since 5.4';
64
-        $data  = array();
63
+		$error = '%s is available since 5.4';
64
+		$data  = array();
65 65
 
66
-        if ($token['type'] === 'T_OPEN_SHORT_ARRAY') {
67
-            $data[] = 'Short array syntax (open)';
68
-        } elseif ($token['type'] === 'T_CLOSE_SHORT_ARRAY') {
69
-            $data[] = 'Short array syntax (close)';
70
-        }
66
+		if ($token['type'] === 'T_OPEN_SHORT_ARRAY') {
67
+			$data[] = 'Short array syntax (open)';
68
+		} elseif ($token['type'] === 'T_CLOSE_SHORT_ARRAY') {
69
+			$data[] = 'Short array syntax (close)';
70
+		}
71 71
 
72
-        $phpcsFile->addError($error, $stackPtr, 'Found', $data);
73
-    }
72
+		$phpcsFile->addError($error, $stackPtr, 'Found', $data);
73
+	}
74 74
 }
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -51,24 +51,24 @@
 block discarded – undo
51 51
      *
52 52
      * @return void
53 53
      */
54
-    public function process(File $phpcsFile, $stackPtr)
54
+    public function process( File $phpcsFile, $stackPtr )
55 55
     {
56
-        if ($this->supportsBelow('5.3') === false) {
56
+        if ( $this->supportsBelow( '5.3' ) === false ) {
57 57
             return;
58 58
         }
59 59
 
60 60
         $tokens = $phpcsFile->getTokens();
61
-        $token  = $tokens[$stackPtr];
61
+        $token  = $tokens[ $stackPtr ];
62 62
 
63 63
         $error = '%s is available since 5.4';
64 64
         $data  = array();
65 65
 
66
-        if ($token['type'] === 'T_OPEN_SHORT_ARRAY') {
67
-            $data[] = 'Short array syntax (open)';
68
-        } elseif ($token['type'] === 'T_CLOSE_SHORT_ARRAY') {
69
-            $data[] = 'Short array syntax (close)';
66
+        if ( $token[ 'type' ] === 'T_OPEN_SHORT_ARRAY' ) {
67
+            $data[ ] = 'Short array syntax (open)';
68
+        } elseif ( $token[ 'type' ] === 'T_CLOSE_SHORT_ARRAY' ) {
69
+            $data[ ] = 'Short array syntax (close)';
70 70
         }
71 71
 
72
-        $phpcsFile->addError($error, $stackPtr, 'Found', $data);
72
+        $phpcsFile->addError( $error, $stackPtr, 'Found', $data );
73 73
     }
74 74
 }
Please login to merge, or discard this patch.
Braces   +3 added lines, -6 removed lines patch added patch discarded remove patch
@@ -25,16 +25,14 @@  discard block
 block discarded – undo
25 25
  * @package  PHPCompatibility
26 26
  * @author   Alex Miroshnikov <[email protected]>
27 27
  */
28
-class NewShortArraySniff extends Sniff
29
-{
28
+class NewShortArraySniff extends Sniff {
30 29
 
31 30
     /**
32 31
      * Returns an array of tokens this test wants to listen for.
33 32
      *
34 33
      * @return array
35 34
      */
36
-    public function register()
37
-    {
35
+    public function register() {
38 36
         return array(
39 37
             \T_OPEN_SHORT_ARRAY,
40 38
             \T_CLOSE_SHORT_ARRAY,
@@ -51,8 +49,7 @@  discard block
 block discarded – undo
51 49
      *
52 50
      * @return void
53 51
      */
54
-    public function process(File $phpcsFile, $stackPtr)
55
-    {
52
+    public function process(File $phpcsFile, $stackPtr) {
56 53
         if ($this->supportsBelow('5.3') === false) {
57 54
             return;
58 55
         }
Please login to merge, or discard this patch.
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -31,7 +31,7 @@
 block discarded – undo
31 31
     /**
32 32
      * Returns an array of tokens this test wants to listen for.
33 33
      *
34
-     * @return array
34
+     * @return string[]
35 35
      */
36 36
     public function register()
37 37
     {
Please login to merge, or discard this patch.
PHPCompatibility/Sniffs/Syntax/RemovedNewReferenceSniff.php 4 patches
Indentation   +38 added lines, -38 removed lines patch added patch discarded remove patch
@@ -31,47 +31,47 @@
 block discarded – undo
31 31
 class RemovedNewReferenceSniff extends Sniff
32 32
 {
33 33
 
34
-    /**
35
-     * Returns an array of tokens this test wants to listen for.
36
-     *
37
-     * @return array
38
-     */
39
-    public function register()
40
-    {
41
-        return array(\T_NEW);
42
-    }
34
+	/**
35
+	 * Returns an array of tokens this test wants to listen for.
36
+	 *
37
+	 * @return array
38
+	 */
39
+	public function register()
40
+	{
41
+		return array(\T_NEW);
42
+	}
43 43
 
44
-    /**
45
-     * Processes this test, when one of its tokens is encountered.
46
-     *
47
-     * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned.
48
-     * @param int                   $stackPtr  The position of the current token in the
49
-     *                                         stack passed in $tokens.
50
-     *
51
-     * @return void
52
-     */
53
-    public function process(File $phpcsFile, $stackPtr)
54
-    {
55
-        if ($this->supportsAbove('5.3') === false) {
56
-            return;
57
-        }
44
+	/**
45
+	 * Processes this test, when one of its tokens is encountered.
46
+	 *
47
+	 * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned.
48
+	 * @param int                   $stackPtr  The position of the current token in the
49
+	 *                                         stack passed in $tokens.
50
+	 *
51
+	 * @return void
52
+	 */
53
+	public function process(File $phpcsFile, $stackPtr)
54
+	{
55
+		if ($this->supportsAbove('5.3') === false) {
56
+			return;
57
+		}
58 58
 
59
-        $tokens       = $phpcsFile->getTokens();
60
-        $prevNonEmpty = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($stackPtr - 1), null, true);
61
-        if ($prevNonEmpty === false || $tokens[$prevNonEmpty]['type'] !== 'T_BITWISE_AND') {
62
-            return;
63
-        }
59
+		$tokens       = $phpcsFile->getTokens();
60
+		$prevNonEmpty = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($stackPtr - 1), null, true);
61
+		if ($prevNonEmpty === false || $tokens[$prevNonEmpty]['type'] !== 'T_BITWISE_AND') {
62
+			return;
63
+		}
64 64
 
65
-        $error     = 'Assigning the return value of new by reference is deprecated in PHP 5.3';
66
-        $isError   = false;
67
-        $errorCode = 'Deprecated';
65
+		$error     = 'Assigning the return value of new by reference is deprecated in PHP 5.3';
66
+		$isError   = false;
67
+		$errorCode = 'Deprecated';
68 68
 
69
-        if ($this->supportsAbove('7.0') === true) {
70
-            $error    .= ' and has been removed in PHP 7.0';
71
-            $isError   = true;
72
-            $errorCode = 'Removed';
73
-        }
69
+		if ($this->supportsAbove('7.0') === true) {
70
+			$error    .= ' and has been removed in PHP 7.0';
71
+			$isError   = true;
72
+			$errorCode = 'Removed';
73
+		}
74 74
 
75
-        $this->addMessage($phpcsFile, $error, $stackPtr, $isError, $errorCode);
76
-    }
75
+		$this->addMessage($phpcsFile, $error, $stackPtr, $isError, $errorCode);
76
+	}
77 77
 }
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -38,7 +38,7 @@  discard block
 block discarded – undo
38 38
      */
39 39
     public function register()
40 40
     {
41
-        return array(\T_NEW);
41
+        return array( \T_NEW );
42 42
     }
43 43
 
44 44
     /**
@@ -50,15 +50,15 @@  discard block
 block discarded – undo
50 50
      *
51 51
      * @return void
52 52
      */
53
-    public function process(File $phpcsFile, $stackPtr)
53
+    public function process( File $phpcsFile, $stackPtr )
54 54
     {
55
-        if ($this->supportsAbove('5.3') === false) {
55
+        if ( $this->supportsAbove( '5.3' ) === false ) {
56 56
             return;
57 57
         }
58 58
 
59 59
         $tokens       = $phpcsFile->getTokens();
60
-        $prevNonEmpty = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($stackPtr - 1), null, true);
61
-        if ($prevNonEmpty === false || $tokens[$prevNonEmpty]['type'] !== 'T_BITWISE_AND') {
60
+        $prevNonEmpty = $phpcsFile->findPrevious( Tokens::$emptyTokens, ( $stackPtr - 1 ), null, true );
61
+        if ( $prevNonEmpty === false || $tokens[ $prevNonEmpty ][ 'type' ] !== 'T_BITWISE_AND' ) {
62 62
             return;
63 63
         }
64 64
 
@@ -66,12 +66,12 @@  discard block
 block discarded – undo
66 66
         $isError   = false;
67 67
         $errorCode = 'Deprecated';
68 68
 
69
-        if ($this->supportsAbove('7.0') === true) {
69
+        if ( $this->supportsAbove( '7.0' ) === true ) {
70 70
             $error    .= ' and has been removed in PHP 7.0';
71 71
             $isError   = true;
72 72
             $errorCode = 'Removed';
73 73
         }
74 74
 
75
-        $this->addMessage($phpcsFile, $error, $stackPtr, $isError, $errorCode);
75
+        $this->addMessage( $phpcsFile, $error, $stackPtr, $isError, $errorCode );
76 76
     }
77 77
 }
Please login to merge, or discard this patch.
Braces   +3 added lines, -6 removed lines patch added patch discarded remove patch
@@ -28,16 +28,14 @@  discard block
 block discarded – undo
28 28
  * @author    Wim Godden <[email protected]>
29 29
  * @copyright 2012 Cu.be Solutions bvba
30 30
  */
31
-class RemovedNewReferenceSniff extends Sniff
32
-{
31
+class RemovedNewReferenceSniff extends Sniff {
33 32
 
34 33
     /**
35 34
      * Returns an array of tokens this test wants to listen for.
36 35
      *
37 36
      * @return array
38 37
      */
39
-    public function register()
40
-    {
38
+    public function register() {
41 39
         return array(\T_NEW);
42 40
     }
43 41
 
@@ -50,8 +48,7 @@  discard block
 block discarded – undo
50 48
      *
51 49
      * @return void
52 50
      */
53
-    public function process(File $phpcsFile, $stackPtr)
54
-    {
51
+    public function process(File $phpcsFile, $stackPtr) {
55 52
         if ($this->supportsAbove('5.3') === false) {
56 53
             return;
57 54
         }
Please login to merge, or discard this patch.
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -65,7 +65,7 @@
 block discarded – undo
65 65
     /**
66 66
      * Returns an array of tokens this test wants to listen for.
67 67
      *
68
-     * @return array
68
+     * @return integer[]
69 69
      */
70 70
     public function register()
71 71
     {
Please login to merge, or discard this patch.
PHPCompatibility/Sniffs/Syntax/NewFunctionCallTrailingCommaSniff.php 4 patches
Indentation   +74 added lines, -74 removed lines patch added patch discarded remove patch
@@ -26,90 +26,90 @@
 block discarded – undo
26 26
  */
27 27
 class NewFunctionCallTrailingCommaSniff extends Sniff
28 28
 {
29
-    /**
30
-     * Returns an array of tokens this test wants to listen for.
31
-     *
32
-     * @return array
33
-     */
34
-    public function register()
35
-    {
36
-        return array(
37
-            \T_STRING,
38
-            \T_VARIABLE,
39
-            \T_ISSET,
40
-            \T_UNSET,
41
-        );
42
-    }
29
+	/**
30
+	 * Returns an array of tokens this test wants to listen for.
31
+	 *
32
+	 * @return array
33
+	 */
34
+	public function register()
35
+	{
36
+		return array(
37
+			\T_STRING,
38
+			\T_VARIABLE,
39
+			\T_ISSET,
40
+			\T_UNSET,
41
+		);
42
+	}
43 43
 
44 44
 
45
-    /**
46
-     * Processes this test, when one of its tokens is encountered.
47
-     *
48
-     * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned.
49
-     * @param int                   $stackPtr  The position of the current token in
50
-     *                                         the stack passed in $tokens.
51
-     *
52
-     * @return void
53
-     */
54
-    public function process(File $phpcsFile, $stackPtr)
55
-    {
56
-        if ($this->supportsBelow('7.2') === false) {
57
-            return;
58
-        }
45
+	/**
46
+	 * Processes this test, when one of its tokens is encountered.
47
+	 *
48
+	 * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned.
49
+	 * @param int                   $stackPtr  The position of the current token in
50
+	 *                                         the stack passed in $tokens.
51
+	 *
52
+	 * @return void
53
+	 */
54
+	public function process(File $phpcsFile, $stackPtr)
55
+	{
56
+		if ($this->supportsBelow('7.2') === false) {
57
+			return;
58
+		}
59 59
 
60
-        $tokens = $phpcsFile->getTokens();
60
+		$tokens = $phpcsFile->getTokens();
61 61
 
62
-        $nextNonEmpty = $phpcsFile->findNext(Tokens::$emptyTokens, ($stackPtr + 1), null, true);
63
-        if ($tokens[$nextNonEmpty]['code'] !== \T_OPEN_PARENTHESIS
64
-            || isset($tokens[$nextNonEmpty]['parenthesis_closer']) === false
65
-        ) {
66
-            return;
67
-        }
62
+		$nextNonEmpty = $phpcsFile->findNext(Tokens::$emptyTokens, ($stackPtr + 1), null, true);
63
+		if ($tokens[$nextNonEmpty]['code'] !== \T_OPEN_PARENTHESIS
64
+			|| isset($tokens[$nextNonEmpty]['parenthesis_closer']) === false
65
+		) {
66
+			return;
67
+		}
68 68
 
69
-        if ($tokens[$stackPtr]['code'] === \T_STRING) {
70
-            $ignore = array(
71
-                \T_FUNCTION        => true,
72
-                \T_CONST           => true,
73
-                \T_USE             => true,
74
-            );
69
+		if ($tokens[$stackPtr]['code'] === \T_STRING) {
70
+			$ignore = array(
71
+				\T_FUNCTION        => true,
72
+				\T_CONST           => true,
73
+				\T_USE             => true,
74
+			);
75 75
 
76
-            $prevNonEmpty = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($stackPtr - 1), null, true);
77
-            if (isset($ignore[$tokens[$prevNonEmpty]['code']]) === true) {
78
-                // Not a function call.
79
-                return;
80
-            }
81
-        }
76
+			$prevNonEmpty = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($stackPtr - 1), null, true);
77
+			if (isset($ignore[$tokens[$prevNonEmpty]['code']]) === true) {
78
+				// Not a function call.
79
+				return;
80
+			}
81
+		}
82 82
 
83
-        $closer            = $tokens[$nextNonEmpty]['parenthesis_closer'];
84
-        $lastInParenthesis = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($closer - 1), $nextNonEmpty, true);
83
+		$closer            = $tokens[$nextNonEmpty]['parenthesis_closer'];
84
+		$lastInParenthesis = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($closer - 1), $nextNonEmpty, true);
85 85
 
86
-        if ($tokens[$lastInParenthesis]['code'] !== \T_COMMA) {
87
-            return;
88
-        }
86
+		if ($tokens[$lastInParenthesis]['code'] !== \T_COMMA) {
87
+			return;
88
+		}
89 89
 
90
-        $data = array();
91
-        switch ($tokens[$stackPtr]['code']) {
92
-            case \T_ISSET:
93
-                $data[]    = 'calls to isset()';
94
-                $errorCode = 'FoundInIsset';
95
-                break;
90
+		$data = array();
91
+		switch ($tokens[$stackPtr]['code']) {
92
+			case \T_ISSET:
93
+				$data[]    = 'calls to isset()';
94
+				$errorCode = 'FoundInIsset';
95
+				break;
96 96
 
97
-            case \T_UNSET:
98
-                $data[]    = 'calls to unset()';
99
-                $errorCode = 'FoundInUnset';
100
-                break;
97
+			case \T_UNSET:
98
+				$data[]    = 'calls to unset()';
99
+				$errorCode = 'FoundInUnset';
100
+				break;
101 101
 
102
-            default:
103
-                $data[]    = 'function calls';
104
-                $errorCode = 'FoundInFunctionCall';
105
-                break;
106
-        }
102
+			default:
103
+				$data[]    = 'function calls';
104
+				$errorCode = 'FoundInFunctionCall';
105
+				break;
106
+		}
107 107
 
108
-        $phpcsFile->addError(
109
-            'Trailing comma\'s are not allowed in %s in PHP 7.2 or earlier',
110
-            $lastInParenthesis,
111
-            $errorCode,
112
-            $data
113
-        );
114
-    }
108
+		$phpcsFile->addError(
109
+			'Trailing comma\'s are not allowed in %s in PHP 7.2 or earlier',
110
+			$lastInParenthesis,
111
+			$errorCode,
112
+			$data
113
+		);
114
+	}
115 115
 }
Please login to merge, or discard this patch.
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -51,56 +51,56 @@
 block discarded – undo
51 51
      *
52 52
      * @return void
53 53
      */
54
-    public function process(File $phpcsFile, $stackPtr)
54
+    public function process( File $phpcsFile, $stackPtr )
55 55
     {
56
-        if ($this->supportsBelow('7.2') === false) {
56
+        if ( $this->supportsBelow( '7.2' ) === false ) {
57 57
             return;
58 58
         }
59 59
 
60 60
         $tokens = $phpcsFile->getTokens();
61 61
 
62
-        $nextNonEmpty = $phpcsFile->findNext(Tokens::$emptyTokens, ($stackPtr + 1), null, true);
63
-        if ($tokens[$nextNonEmpty]['code'] !== \T_OPEN_PARENTHESIS
64
-            || isset($tokens[$nextNonEmpty]['parenthesis_closer']) === false
62
+        $nextNonEmpty = $phpcsFile->findNext( Tokens::$emptyTokens, ( $stackPtr + 1 ), null, true );
63
+        if ( $tokens[ $nextNonEmpty ][ 'code' ] !== \T_OPEN_PARENTHESIS
64
+            || isset( $tokens[ $nextNonEmpty ][ 'parenthesis_closer' ] ) === false
65 65
         ) {
66 66
             return;
67 67
         }
68 68
 
69
-        if ($tokens[$stackPtr]['code'] === \T_STRING) {
69
+        if ( $tokens[ $stackPtr ][ 'code' ] === \T_STRING ) {
70 70
             $ignore = array(
71 71
                 \T_FUNCTION        => true,
72 72
                 \T_CONST           => true,
73 73
                 \T_USE             => true,
74 74
             );
75 75
 
76
-            $prevNonEmpty = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($stackPtr - 1), null, true);
77
-            if (isset($ignore[$tokens[$prevNonEmpty]['code']]) === true) {
76
+            $prevNonEmpty = $phpcsFile->findPrevious( Tokens::$emptyTokens, ( $stackPtr - 1 ), null, true );
77
+            if ( isset( $ignore[ $tokens[ $prevNonEmpty ][ 'code' ] ] ) === true ) {
78 78
                 // Not a function call.
79 79
                 return;
80 80
             }
81 81
         }
82 82
 
83
-        $closer            = $tokens[$nextNonEmpty]['parenthesis_closer'];
84
-        $lastInParenthesis = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($closer - 1), $nextNonEmpty, true);
83
+        $closer            = $tokens[ $nextNonEmpty ][ 'parenthesis_closer' ];
84
+        $lastInParenthesis = $phpcsFile->findPrevious( Tokens::$emptyTokens, ( $closer - 1 ), $nextNonEmpty, true );
85 85
 
86
-        if ($tokens[$lastInParenthesis]['code'] !== \T_COMMA) {
86
+        if ( $tokens[ $lastInParenthesis ][ 'code' ] !== \T_COMMA ) {
87 87
             return;
88 88
         }
89 89
 
90 90
         $data = array();
91
-        switch ($tokens[$stackPtr]['code']) {
91
+        switch ( $tokens[ $stackPtr ][ 'code' ] ) {
92 92
             case \T_ISSET:
93
-                $data[]    = 'calls to isset()';
93
+                $data[ ]    = 'calls to isset()';
94 94
                 $errorCode = 'FoundInIsset';
95 95
                 break;
96 96
 
97 97
             case \T_UNSET:
98
-                $data[]    = 'calls to unset()';
98
+                $data[ ]    = 'calls to unset()';
99 99
                 $errorCode = 'FoundInUnset';
100 100
                 break;
101 101
 
102 102
             default:
103
-                $data[]    = 'function calls';
103
+                $data[ ]    = 'function calls';
104 104
                 $errorCode = 'FoundInFunctionCall';
105 105
                 break;
106 106
         }
Please login to merge, or discard this patch.
Braces   +3 added lines, -6 removed lines patch added patch discarded remove patch
@@ -24,15 +24,13 @@  discard block
 block discarded – undo
24 24
  * @package  PHPCompatibility
25 25
  * @author   Juliette Reinders Folmer <[email protected]>
26 26
  */
27
-class NewFunctionCallTrailingCommaSniff extends Sniff
28
-{
27
+class NewFunctionCallTrailingCommaSniff extends Sniff {
29 28
     /**
30 29
      * Returns an array of tokens this test wants to listen for.
31 30
      *
32 31
      * @return array
33 32
      */
34
-    public function register()
35
-    {
33
+    public function register() {
36 34
         return array(
37 35
             \T_STRING,
38 36
             \T_VARIABLE,
@@ -51,8 +49,7 @@  discard block
 block discarded – undo
51 49
      *
52 50
      * @return void
53 51
      */
54
-    public function process(File $phpcsFile, $stackPtr)
55
-    {
52
+    public function process(File $phpcsFile, $stackPtr) {
56 53
         if ($this->supportsBelow('7.2') === false) {
57 54
             return;
58 55
         }
Please login to merge, or discard this patch.
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -65,7 +65,7 @@
 block discarded – undo
65 65
     /**
66 66
      * Returns an array of tokens this test wants to listen for.
67 67
      *
68
-     * @return array
68
+     * @return integer[]
69 69
      */
70 70
     public function register()
71 71
     {
Please login to merge, or discard this patch.
PHPCompatibility/Sniffs/Syntax/NewFlexibleHeredocNowdocSniff.php 3 patches
Indentation   +190 added lines, -190 removed lines patch added patch discarded remove patch
@@ -33,215 +33,215 @@
 block discarded – undo
33 33
 class NewFlexibleHeredocNowdocSniff extends 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
-        $targets = array(
44
-            \T_END_HEREDOC,
45
-            \T_END_NOWDOC,
46
-        );
47
-
48
-        if (version_compare(\PHP_VERSION_ID, '70299', '>') === false) {
49
-            // Start identifier of a PHP 7.3 flexible heredoc/nowdoc.
50
-            $targets[] = \T_STRING;
51
-        }
52
-
53
-        return $targets;
54
-    }
55
-
56
-
57
-    /**
58
-     * Processes this test, when one of its tokens is encountered.
59
-     *
60
-     * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned.
61
-     * @param int                   $stackPtr  The position of the current token in the
62
-     *                                         stack passed in $tokens.
63
-     *
64
-     * @return void
65
-     */
66
-    public function process(File $phpcsFile, $stackPtr)
67
-    {
68
-        /*
36
+	/**
37
+	 * Returns an array of tokens this test wants to listen for.
38
+	 *
39
+	 * @return array
40
+	 */
41
+	public function register()
42
+	{
43
+		$targets = array(
44
+			\T_END_HEREDOC,
45
+			\T_END_NOWDOC,
46
+		);
47
+
48
+		if (version_compare(\PHP_VERSION_ID, '70299', '>') === false) {
49
+			// Start identifier of a PHP 7.3 flexible heredoc/nowdoc.
50
+			$targets[] = \T_STRING;
51
+		}
52
+
53
+		return $targets;
54
+	}
55
+
56
+
57
+	/**
58
+	 * Processes this test, when one of its tokens is encountered.
59
+	 *
60
+	 * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned.
61
+	 * @param int                   $stackPtr  The position of the current token in the
62
+	 *                                         stack passed in $tokens.
63
+	 *
64
+	 * @return void
65
+	 */
66
+	public function process(File $phpcsFile, $stackPtr)
67
+	{
68
+		/*
69 69
          * Due to a tokenizer bug which gets hit when the PHP 7.3 heredoc/nowdoc syntax
70 70
          * is used, this part of the sniff cannot possibly work on PHPCS < 2.6.0.
71 71
          * See upstream issue #928.
72 72
          */
73
-        if ($this->supportsBelow('7.2') === true && version_compare(PHPCSHelper::getVersion(), '2.6.0', '>=')) {
74
-            $this->detectIndentedNonStandAloneClosingMarker($phpcsFile, $stackPtr);
75
-        }
76
-
77
-        $tokens = $phpcsFile->getTokens();
78
-        if ($this->supportsAbove('7.3') === true && $tokens[$stackPtr]['code'] !== \T_STRING) {
79
-            $this->detectClosingMarkerInBody($phpcsFile, $stackPtr);
80
-        }
81
-    }
82
-
83
-
84
-    /**
85
-     * Detect indented and/or non-stand alone closing markers.
86
-     *
87
-     * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned.
88
-     * @param int                   $stackPtr  The position of the current token in the
89
-     *                                         stack passed in $tokens.
90
-     *
91
-     * @return void
92
-     */
93
-    protected function detectIndentedNonStandAloneClosingMarker(File $phpcsFile, $stackPtr)
94
-    {
95
-        $tokens            = $phpcsFile->getTokens();
96
-        $indentError       = 'Heredoc/nowdoc with an indented closing marker is not supported in PHP 7.2 or earlier.';
97
-        $indentErrorCode   = 'IndentedClosingMarker';
98
-        $trailingError     = 'Having code - other than a semi-colon or new line - after the closing marker of a heredoc/nowdoc is not supported in PHP 7.2 or earlier.';
99
-        $trailingErrorCode = 'ClosingMarkerNoNewLine';
100
-
101
-        if (version_compare(\PHP_VERSION_ID, '70299', '>') === true) {
102
-
103
-            /*
73
+		if ($this->supportsBelow('7.2') === true && version_compare(PHPCSHelper::getVersion(), '2.6.0', '>=')) {
74
+			$this->detectIndentedNonStandAloneClosingMarker($phpcsFile, $stackPtr);
75
+		}
76
+
77
+		$tokens = $phpcsFile->getTokens();
78
+		if ($this->supportsAbove('7.3') === true && $tokens[$stackPtr]['code'] !== \T_STRING) {
79
+			$this->detectClosingMarkerInBody($phpcsFile, $stackPtr);
80
+		}
81
+	}
82
+
83
+
84
+	/**
85
+	 * Detect indented and/or non-stand alone closing markers.
86
+	 *
87
+	 * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned.
88
+	 * @param int                   $stackPtr  The position of the current token in the
89
+	 *                                         stack passed in $tokens.
90
+	 *
91
+	 * @return void
92
+	 */
93
+	protected function detectIndentedNonStandAloneClosingMarker(File $phpcsFile, $stackPtr)
94
+	{
95
+		$tokens            = $phpcsFile->getTokens();
96
+		$indentError       = 'Heredoc/nowdoc with an indented closing marker is not supported in PHP 7.2 or earlier.';
97
+		$indentErrorCode   = 'IndentedClosingMarker';
98
+		$trailingError     = 'Having code - other than a semi-colon or new line - after the closing marker of a heredoc/nowdoc is not supported in PHP 7.2 or earlier.';
99
+		$trailingErrorCode = 'ClosingMarkerNoNewLine';
100
+
101
+		if (version_compare(\PHP_VERSION_ID, '70299', '>') === true) {
102
+
103
+			/*
104 104
              * Check for indented closing marker.
105 105
              */
106
-            if (ltrim($tokens[$stackPtr]['content']) !== $tokens[$stackPtr]['content']) {
107
-                $phpcsFile->addError($indentError, $stackPtr, $indentErrorCode);
108
-            }
106
+			if (ltrim($tokens[$stackPtr]['content']) !== $tokens[$stackPtr]['content']) {
107
+				$phpcsFile->addError($indentError, $stackPtr, $indentErrorCode);
108
+			}
109 109
 
110
-            /*
110
+			/*
111 111
              * Check for tokens after the closing marker.
112 112
              */
113
-            $nextNonWhitespace = $phpcsFile->findNext(array(\T_WHITESPACE, \T_SEMICOLON), ($stackPtr + 1), null, true);
114
-            if ($tokens[$stackPtr]['line'] === $tokens[$nextNonWhitespace]['line']) {
115
-                $phpcsFile->addError($trailingError, $stackPtr, $trailingErrorCode);
116
-            }
117
-        } else {
118
-            // For PHP < 7.3, we're only interested in T_STRING tokens.
119
-            if ($tokens[$stackPtr]['code'] !== \T_STRING) {
120
-                return;
121
-            }
113
+			$nextNonWhitespace = $phpcsFile->findNext(array(\T_WHITESPACE, \T_SEMICOLON), ($stackPtr + 1), null, true);
114
+			if ($tokens[$stackPtr]['line'] === $tokens[$nextNonWhitespace]['line']) {
115
+				$phpcsFile->addError($trailingError, $stackPtr, $trailingErrorCode);
116
+			}
117
+		} else {
118
+			// For PHP < 7.3, we're only interested in T_STRING tokens.
119
+			if ($tokens[$stackPtr]['code'] !== \T_STRING) {
120
+				return;
121
+			}
122 122
 
123
-            if (preg_match('`^<<<([\'"]?)([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)\1[\r\n]+`', $tokens[$stackPtr]['content'], $matches) !== 1) {
124
-                // Not the start of a PHP 7.3 flexible heredoc/nowdoc.
125
-                return;
126
-            }
123
+			if (preg_match('`^<<<([\'"]?)([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)\1[\r\n]+`', $tokens[$stackPtr]['content'], $matches) !== 1) {
124
+				// Not the start of a PHP 7.3 flexible heredoc/nowdoc.
125
+				return;
126
+			}
127 127
 
128
-            $identifier = $matches[2];
128
+			$identifier = $matches[2];
129 129
 
130
-            for ($i = ($stackPtr + 1); $i <= $phpcsFile->numTokens; $i++) {
131
-                if ($tokens[$i]['code'] !== \T_ENCAPSED_AND_WHITESPACE) {
132
-                    continue;
133
-                }
130
+			for ($i = ($stackPtr + 1); $i <= $phpcsFile->numTokens; $i++) {
131
+				if ($tokens[$i]['code'] !== \T_ENCAPSED_AND_WHITESPACE) {
132
+					continue;
133
+				}
134 134
 
135
-                $trimmed = ltrim($tokens[$i]['content']);
135
+				$trimmed = ltrim($tokens[$i]['content']);
136 136
 
137
-                if (strpos($trimmed, $identifier) !== 0) {
138
-                    continue;
139
-                }
137
+				if (strpos($trimmed, $identifier) !== 0) {
138
+					continue;
139
+				}
140 140
 
141
-                // OK, we've found the PHP 7.3 flexible heredoc/nowdoc closing marker.
141
+				// OK, we've found the PHP 7.3 flexible heredoc/nowdoc closing marker.
142 142
 
143
-                /*
143
+				/*
144 144
                  * Check for indented closing marker.
145 145
                  */
146
-                if ($trimmed !== $tokens[$i]['content']) {
147
-                    // Indent found before closing marker.
148
-                    $phpcsFile->addError($indentError, $i, $indentErrorCode);
149
-                }
146
+				if ($trimmed !== $tokens[$i]['content']) {
147
+					// Indent found before closing marker.
148
+					$phpcsFile->addError($indentError, $i, $indentErrorCode);
149
+				}
150 150
 
151
-                /*
151
+				/*
152 152
                  * Check for tokens after the closing marker.
153 153
                  */
154
-                // Remove the identifier.
155
-                $afterMarker = substr($trimmed, \strlen($identifier));
156
-                // Remove a potential semi-colon at the beginning of what's left of the string.
157
-                $afterMarker = ltrim($afterMarker, ';');
158
-                // Remove new line characters at the end of the string.
159
-                $afterMarker = rtrim($afterMarker, "\r\n");
160
-
161
-                if ($afterMarker !== '') {
162
-                    $phpcsFile->addError($trailingError, $i, $trailingErrorCode);
163
-                }
164
-
165
-                break;
166
-            }
167
-        }
168
-    }
169
-
170
-
171
-    /**
172
-     * Detect heredoc/nowdoc identifiers at the start of lines in the heredoc/nowdoc body.
173
-     *
174
-     * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned.
175
-     * @param int                   $stackPtr  The position of the current token in the
176
-     *                                         stack passed in $tokens.
177
-     *
178
-     * @return void
179
-     */
180
-    protected function detectClosingMarkerInBody(File $phpcsFile, $stackPtr)
181
-    {
182
-        $tokens    = $phpcsFile->getTokens();
183
-        $error     = 'The body of a heredoc/nowdoc can not contain the heredoc/nowdoc closing marker as text at the start of a line since PHP 7.3.';
184
-        $errorCode = 'ClosingMarkerNoNewLine';
185
-
186
-        if (version_compare(\PHP_VERSION_ID, '70299', '>') === true) {
187
-            $nextNonWhitespace = $phpcsFile->findNext(\T_WHITESPACE, ($stackPtr + 1), null, true, null, true);
188
-            if ($nextNonWhitespace === false
189
-                || $tokens[$nextNonWhitespace]['code'] === \T_SEMICOLON
190
-                || (($tokens[$nextNonWhitespace]['code'] === \T_COMMA
191
-                    || $tokens[$nextNonWhitespace]['code'] === \T_STRING_CONCAT)
192
-                    && $tokens[$nextNonWhitespace]['line'] !== $tokens[$stackPtr]['line'])
193
-            ) {
194
-                // This is most likely a correctly identified closing marker.
195
-                return;
196
-            }
197
-
198
-            // The real closing tag has to be before the next heredoc/nowdoc.
199
-            $nextHereNowDoc = $phpcsFile->findNext(array(\T_START_HEREDOC, \T_START_NOWDOC), ($stackPtr + 1));
200
-            if ($nextHereNowDoc === false) {
201
-                $nextHereNowDoc = null;
202
-            }
203
-
204
-            $identifier        = trim($tokens[$stackPtr]['content']);
205
-            $realClosingMarker = $stackPtr;
206
-
207
-            while (($realClosingMarker = $phpcsFile->findNext(\T_STRING, ($realClosingMarker + 1), $nextHereNowDoc, false, $identifier)) !== false) {
208
-
209
-                $prevNonWhitespace = $phpcsFile->findPrevious(\T_WHITESPACE, ($realClosingMarker - 1), null, true);
210
-                if ($prevNonWhitespace === false
211
-                    || $tokens[$prevNonWhitespace]['line'] === $tokens[$realClosingMarker]['line']
212
-                ) {
213
-                    // Marker text found, but not at the start of the line.
214
-                    continue;
215
-                }
216
-
217
-                // The original T_END_HEREDOC/T_END_NOWDOC was most likely incorrect as we've found
218
-                // a possible alternative closing marker.
219
-                $phpcsFile->addError($error, $stackPtr, $errorCode);
220
-
221
-                break;
222
-            }
223
-
224
-        } else {
225
-            if (isset($tokens[$stackPtr]['scope_closer'], $tokens[$stackPtr]['scope_opener']) === true
226
-                && $tokens[$stackPtr]['scope_closer'] === $stackPtr
227
-            ) {
228
-                $opener = $tokens[$stackPtr]['scope_opener'];
229
-            } else {
230
-                // PHPCS < 3.0.2 did not add scope_* values for Nowdocs.
231
-                $opener = $phpcsFile->findPrevious(\T_START_NOWDOC, ($stackPtr - 1));
232
-                if ($opener === false) {
233
-                    return;
234
-                }
235
-            }
236
-
237
-            $quotedIdentifier = preg_quote($tokens[$stackPtr]['content'], '`');
238
-
239
-            // Throw an error for each line in the body which starts with the identifier.
240
-            for ($i = ($opener + 1); $i < $stackPtr; $i++) {
241
-                if (preg_match('`^[ \t]*' . $quotedIdentifier . '\b`', $tokens[$i]['content']) === 1) {
242
-                    $phpcsFile->addError($error, $i, $errorCode);
243
-                }
244
-            }
245
-        }
246
-    }
154
+				// Remove the identifier.
155
+				$afterMarker = substr($trimmed, \strlen($identifier));
156
+				// Remove a potential semi-colon at the beginning of what's left of the string.
157
+				$afterMarker = ltrim($afterMarker, ';');
158
+				// Remove new line characters at the end of the string.
159
+				$afterMarker = rtrim($afterMarker, "\r\n");
160
+
161
+				if ($afterMarker !== '') {
162
+					$phpcsFile->addError($trailingError, $i, $trailingErrorCode);
163
+				}
164
+
165
+				break;
166
+			}
167
+		}
168
+	}
169
+
170
+
171
+	/**
172
+	 * Detect heredoc/nowdoc identifiers at the start of lines in the heredoc/nowdoc body.
173
+	 *
174
+	 * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned.
175
+	 * @param int                   $stackPtr  The position of the current token in the
176
+	 *                                         stack passed in $tokens.
177
+	 *
178
+	 * @return void
179
+	 */
180
+	protected function detectClosingMarkerInBody(File $phpcsFile, $stackPtr)
181
+	{
182
+		$tokens    = $phpcsFile->getTokens();
183
+		$error     = 'The body of a heredoc/nowdoc can not contain the heredoc/nowdoc closing marker as text at the start of a line since PHP 7.3.';
184
+		$errorCode = 'ClosingMarkerNoNewLine';
185
+
186
+		if (version_compare(\PHP_VERSION_ID, '70299', '>') === true) {
187
+			$nextNonWhitespace = $phpcsFile->findNext(\T_WHITESPACE, ($stackPtr + 1), null, true, null, true);
188
+			if ($nextNonWhitespace === false
189
+				|| $tokens[$nextNonWhitespace]['code'] === \T_SEMICOLON
190
+				|| (($tokens[$nextNonWhitespace]['code'] === \T_COMMA
191
+					|| $tokens[$nextNonWhitespace]['code'] === \T_STRING_CONCAT)
192
+					&& $tokens[$nextNonWhitespace]['line'] !== $tokens[$stackPtr]['line'])
193
+			) {
194
+				// This is most likely a correctly identified closing marker.
195
+				return;
196
+			}
197
+
198
+			// The real closing tag has to be before the next heredoc/nowdoc.
199
+			$nextHereNowDoc = $phpcsFile->findNext(array(\T_START_HEREDOC, \T_START_NOWDOC), ($stackPtr + 1));
200
+			if ($nextHereNowDoc === false) {
201
+				$nextHereNowDoc = null;
202
+			}
203
+
204
+			$identifier        = trim($tokens[$stackPtr]['content']);
205
+			$realClosingMarker = $stackPtr;
206
+
207
+			while (($realClosingMarker = $phpcsFile->findNext(\T_STRING, ($realClosingMarker + 1), $nextHereNowDoc, false, $identifier)) !== false) {
208
+
209
+				$prevNonWhitespace = $phpcsFile->findPrevious(\T_WHITESPACE, ($realClosingMarker - 1), null, true);
210
+				if ($prevNonWhitespace === false
211
+					|| $tokens[$prevNonWhitespace]['line'] === $tokens[$realClosingMarker]['line']
212
+				) {
213
+					// Marker text found, but not at the start of the line.
214
+					continue;
215
+				}
216
+
217
+				// The original T_END_HEREDOC/T_END_NOWDOC was most likely incorrect as we've found
218
+				// a possible alternative closing marker.
219
+				$phpcsFile->addError($error, $stackPtr, $errorCode);
220
+
221
+				break;
222
+			}
223
+
224
+		} else {
225
+			if (isset($tokens[$stackPtr]['scope_closer'], $tokens[$stackPtr]['scope_opener']) === true
226
+				&& $tokens[$stackPtr]['scope_closer'] === $stackPtr
227
+			) {
228
+				$opener = $tokens[$stackPtr]['scope_opener'];
229
+			} else {
230
+				// PHPCS < 3.0.2 did not add scope_* values for Nowdocs.
231
+				$opener = $phpcsFile->findPrevious(\T_START_NOWDOC, ($stackPtr - 1));
232
+				if ($opener === false) {
233
+					return;
234
+				}
235
+			}
236
+
237
+			$quotedIdentifier = preg_quote($tokens[$stackPtr]['content'], '`');
238
+
239
+			// Throw an error for each line in the body which starts with the identifier.
240
+			for ($i = ($opener + 1); $i < $stackPtr; $i++) {
241
+				if (preg_match('`^[ \t]*' . $quotedIdentifier . '\b`', $tokens[$i]['content']) === 1) {
242
+					$phpcsFile->addError($error, $i, $errorCode);
243
+				}
244
+			}
245
+		}
246
+	}
247 247
 }
Please login to merge, or discard this patch.
Spacing   +53 added lines, -53 removed lines patch added patch discarded remove patch
@@ -45,9 +45,9 @@  discard block
 block discarded – undo
45 45
             \T_END_NOWDOC,
46 46
         );
47 47
 
48
-        if (version_compare(\PHP_VERSION_ID, '70299', '>') === false) {
48
+        if ( version_compare( \PHP_VERSION_ID, '70299', '>' ) === false ) {
49 49
             // Start identifier of a PHP 7.3 flexible heredoc/nowdoc.
50
-            $targets[] = \T_STRING;
50
+            $targets[ ] = \T_STRING;
51 51
         }
52 52
 
53 53
         return $targets;
@@ -63,20 +63,20 @@  discard block
 block discarded – undo
63 63
      *
64 64
      * @return void
65 65
      */
66
-    public function process(File $phpcsFile, $stackPtr)
66
+    public function process( File $phpcsFile, $stackPtr )
67 67
     {
68 68
         /*
69 69
          * Due to a tokenizer bug which gets hit when the PHP 7.3 heredoc/nowdoc syntax
70 70
          * is used, this part of the sniff cannot possibly work on PHPCS < 2.6.0.
71 71
          * See upstream issue #928.
72 72
          */
73
-        if ($this->supportsBelow('7.2') === true && version_compare(PHPCSHelper::getVersion(), '2.6.0', '>=')) {
74
-            $this->detectIndentedNonStandAloneClosingMarker($phpcsFile, $stackPtr);
73
+        if ( $this->supportsBelow( '7.2' ) === true && version_compare( PHPCSHelper::getVersion(), '2.6.0', '>=' ) ) {
74
+            $this->detectIndentedNonStandAloneClosingMarker( $phpcsFile, $stackPtr );
75 75
         }
76 76
 
77 77
         $tokens = $phpcsFile->getTokens();
78
-        if ($this->supportsAbove('7.3') === true && $tokens[$stackPtr]['code'] !== \T_STRING) {
79
-            $this->detectClosingMarkerInBody($phpcsFile, $stackPtr);
78
+        if ( $this->supportsAbove( '7.3' ) === true && $tokens[ $stackPtr ][ 'code' ] !== \T_STRING ) {
79
+            $this->detectClosingMarkerInBody( $phpcsFile, $stackPtr );
80 80
         }
81 81
     }
82 82
 
@@ -90,7 +90,7 @@  discard block
 block discarded – undo
90 90
      *
91 91
      * @return void
92 92
      */
93
-    protected function detectIndentedNonStandAloneClosingMarker(File $phpcsFile, $stackPtr)
93
+    protected function detectIndentedNonStandAloneClosingMarker( File $phpcsFile, $stackPtr )
94 94
     {
95 95
         $tokens            = $phpcsFile->getTokens();
96 96
         $indentError       = 'Heredoc/nowdoc with an indented closing marker is not supported in PHP 7.2 or earlier.';
@@ -98,43 +98,43 @@  discard block
 block discarded – undo
98 98
         $trailingError     = 'Having code - other than a semi-colon or new line - after the closing marker of a heredoc/nowdoc is not supported in PHP 7.2 or earlier.';
99 99
         $trailingErrorCode = 'ClosingMarkerNoNewLine';
100 100
 
101
-        if (version_compare(\PHP_VERSION_ID, '70299', '>') === true) {
101
+        if ( version_compare( \PHP_VERSION_ID, '70299', '>' ) === true ) {
102 102
 
103 103
             /*
104 104
              * Check for indented closing marker.
105 105
              */
106
-            if (ltrim($tokens[$stackPtr]['content']) !== $tokens[$stackPtr]['content']) {
107
-                $phpcsFile->addError($indentError, $stackPtr, $indentErrorCode);
106
+            if ( ltrim( $tokens[ $stackPtr ][ 'content' ] ) !== $tokens[ $stackPtr ][ 'content' ] ) {
107
+                $phpcsFile->addError( $indentError, $stackPtr, $indentErrorCode );
108 108
             }
109 109
 
110 110
             /*
111 111
              * Check for tokens after the closing marker.
112 112
              */
113
-            $nextNonWhitespace = $phpcsFile->findNext(array(\T_WHITESPACE, \T_SEMICOLON), ($stackPtr + 1), null, true);
114
-            if ($tokens[$stackPtr]['line'] === $tokens[$nextNonWhitespace]['line']) {
115
-                $phpcsFile->addError($trailingError, $stackPtr, $trailingErrorCode);
113
+            $nextNonWhitespace = $phpcsFile->findNext( array( \T_WHITESPACE, \T_SEMICOLON ), ( $stackPtr + 1 ), null, true );
114
+            if ( $tokens[ $stackPtr ][ 'line' ] === $tokens[ $nextNonWhitespace ][ 'line' ] ) {
115
+                $phpcsFile->addError( $trailingError, $stackPtr, $trailingErrorCode );
116 116
             }
117 117
         } else {
118 118
             // For PHP < 7.3, we're only interested in T_STRING tokens.
119
-            if ($tokens[$stackPtr]['code'] !== \T_STRING) {
119
+            if ( $tokens[ $stackPtr ][ 'code' ] !== \T_STRING ) {
120 120
                 return;
121 121
             }
122 122
 
123
-            if (preg_match('`^<<<([\'"]?)([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)\1[\r\n]+`', $tokens[$stackPtr]['content'], $matches) !== 1) {
123
+            if ( preg_match( '`^<<<([\'"]?)([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)\1[\r\n]+`', $tokens[ $stackPtr ][ 'content' ], $matches ) !== 1 ) {
124 124
                 // Not the start of a PHP 7.3 flexible heredoc/nowdoc.
125 125
                 return;
126 126
             }
127 127
 
128
-            $identifier = $matches[2];
128
+            $identifier = $matches[ 2 ];
129 129
 
130
-            for ($i = ($stackPtr + 1); $i <= $phpcsFile->numTokens; $i++) {
131
-                if ($tokens[$i]['code'] !== \T_ENCAPSED_AND_WHITESPACE) {
130
+            for ( $i = ( $stackPtr + 1 ); $i <= $phpcsFile->numTokens; $i++ ) {
131
+                if ( $tokens[ $i ][ 'code' ] !== \T_ENCAPSED_AND_WHITESPACE ) {
132 132
                     continue;
133 133
                 }
134 134
 
135
-                $trimmed = ltrim($tokens[$i]['content']);
135
+                $trimmed = ltrim( $tokens[ $i ][ 'content' ] );
136 136
 
137
-                if (strpos($trimmed, $identifier) !== 0) {
137
+                if ( strpos( $trimmed, $identifier ) !== 0 ) {
138 138
                     continue;
139 139
                 }
140 140
 
@@ -143,23 +143,23 @@  discard block
 block discarded – undo
143 143
                 /*
144 144
                  * Check for indented closing marker.
145 145
                  */
146
-                if ($trimmed !== $tokens[$i]['content']) {
146
+                if ( $trimmed !== $tokens[ $i ][ 'content' ] ) {
147 147
                     // Indent found before closing marker.
148
-                    $phpcsFile->addError($indentError, $i, $indentErrorCode);
148
+                    $phpcsFile->addError( $indentError, $i, $indentErrorCode );
149 149
                 }
150 150
 
151 151
                 /*
152 152
                  * Check for tokens after the closing marker.
153 153
                  */
154 154
                 // Remove the identifier.
155
-                $afterMarker = substr($trimmed, \strlen($identifier));
155
+                $afterMarker = substr( $trimmed, \strlen( $identifier ) );
156 156
                 // Remove a potential semi-colon at the beginning of what's left of the string.
157
-                $afterMarker = ltrim($afterMarker, ';');
157
+                $afterMarker = ltrim( $afterMarker, ';' );
158 158
                 // Remove new line characters at the end of the string.
159
-                $afterMarker = rtrim($afterMarker, "\r\n");
159
+                $afterMarker = rtrim( $afterMarker, "\r\n" );
160 160
 
161
-                if ($afterMarker !== '') {
162
-                    $phpcsFile->addError($trailingError, $i, $trailingErrorCode);
161
+                if ( $afterMarker !== '' ) {
162
+                    $phpcsFile->addError( $trailingError, $i, $trailingErrorCode );
163 163
                 }
164 164
 
165 165
                 break;
@@ -177,38 +177,38 @@  discard block
 block discarded – undo
177 177
      *
178 178
      * @return void
179 179
      */
180
-    protected function detectClosingMarkerInBody(File $phpcsFile, $stackPtr)
180
+    protected function detectClosingMarkerInBody( File $phpcsFile, $stackPtr )
181 181
     {
182 182
         $tokens    = $phpcsFile->getTokens();
183 183
         $error     = 'The body of a heredoc/nowdoc can not contain the heredoc/nowdoc closing marker as text at the start of a line since PHP 7.3.';
184 184
         $errorCode = 'ClosingMarkerNoNewLine';
185 185
 
186
-        if (version_compare(\PHP_VERSION_ID, '70299', '>') === true) {
187
-            $nextNonWhitespace = $phpcsFile->findNext(\T_WHITESPACE, ($stackPtr + 1), null, true, null, true);
188
-            if ($nextNonWhitespace === false
189
-                || $tokens[$nextNonWhitespace]['code'] === \T_SEMICOLON
190
-                || (($tokens[$nextNonWhitespace]['code'] === \T_COMMA
191
-                    || $tokens[$nextNonWhitespace]['code'] === \T_STRING_CONCAT)
192
-                    && $tokens[$nextNonWhitespace]['line'] !== $tokens[$stackPtr]['line'])
186
+        if ( version_compare( \PHP_VERSION_ID, '70299', '>' ) === true ) {
187
+            $nextNonWhitespace = $phpcsFile->findNext( \T_WHITESPACE, ( $stackPtr + 1 ), null, true, null, true );
188
+            if ( $nextNonWhitespace === false
189
+                || $tokens[ $nextNonWhitespace ][ 'code' ] === \T_SEMICOLON
190
+                || ( ( $tokens[ $nextNonWhitespace ][ 'code' ] === \T_COMMA
191
+                    || $tokens[ $nextNonWhitespace ][ 'code' ] === \T_STRING_CONCAT )
192
+                    && $tokens[ $nextNonWhitespace ][ 'line' ] !== $tokens[ $stackPtr ][ 'line' ] )
193 193
             ) {
194 194
                 // This is most likely a correctly identified closing marker.
195 195
                 return;
196 196
             }
197 197
 
198 198
             // The real closing tag has to be before the next heredoc/nowdoc.
199
-            $nextHereNowDoc = $phpcsFile->findNext(array(\T_START_HEREDOC, \T_START_NOWDOC), ($stackPtr + 1));
200
-            if ($nextHereNowDoc === false) {
199
+            $nextHereNowDoc = $phpcsFile->findNext( array( \T_START_HEREDOC, \T_START_NOWDOC ), ( $stackPtr + 1 ) );
200
+            if ( $nextHereNowDoc === false ) {
201 201
                 $nextHereNowDoc = null;
202 202
             }
203 203
 
204
-            $identifier        = trim($tokens[$stackPtr]['content']);
204
+            $identifier        = trim( $tokens[ $stackPtr ][ 'content' ] );
205 205
             $realClosingMarker = $stackPtr;
206 206
 
207
-            while (($realClosingMarker = $phpcsFile->findNext(\T_STRING, ($realClosingMarker + 1), $nextHereNowDoc, false, $identifier)) !== false) {
207
+            while ( ( $realClosingMarker = $phpcsFile->findNext( \T_STRING, ( $realClosingMarker + 1 ), $nextHereNowDoc, false, $identifier ) ) !== false ) {
208 208
 
209
-                $prevNonWhitespace = $phpcsFile->findPrevious(\T_WHITESPACE, ($realClosingMarker - 1), null, true);
210
-                if ($prevNonWhitespace === false
211
-                    || $tokens[$prevNonWhitespace]['line'] === $tokens[$realClosingMarker]['line']
209
+                $prevNonWhitespace = $phpcsFile->findPrevious( \T_WHITESPACE, ( $realClosingMarker - 1 ), null, true );
210
+                if ( $prevNonWhitespace === false
211
+                    || $tokens[ $prevNonWhitespace ][ 'line' ] === $tokens[ $realClosingMarker ][ 'line' ]
212 212
                 ) {
213 213
                     // Marker text found, but not at the start of the line.
214 214
                     continue;
@@ -216,30 +216,30 @@  discard block
 block discarded – undo
216 216
 
217 217
                 // The original T_END_HEREDOC/T_END_NOWDOC was most likely incorrect as we've found
218 218
                 // a possible alternative closing marker.
219
-                $phpcsFile->addError($error, $stackPtr, $errorCode);
219
+                $phpcsFile->addError( $error, $stackPtr, $errorCode );
220 220
 
221 221
                 break;
222 222
             }
223 223
 
224 224
         } else {
225
-            if (isset($tokens[$stackPtr]['scope_closer'], $tokens[$stackPtr]['scope_opener']) === true
226
-                && $tokens[$stackPtr]['scope_closer'] === $stackPtr
225
+            if ( isset( $tokens[ $stackPtr ][ 'scope_closer' ], $tokens[ $stackPtr ][ 'scope_opener' ] ) === true
226
+                && $tokens[ $stackPtr ][ 'scope_closer' ] === $stackPtr
227 227
             ) {
228
-                $opener = $tokens[$stackPtr]['scope_opener'];
228
+                $opener = $tokens[ $stackPtr ][ 'scope_opener' ];
229 229
             } else {
230 230
                 // PHPCS < 3.0.2 did not add scope_* values for Nowdocs.
231
-                $opener = $phpcsFile->findPrevious(\T_START_NOWDOC, ($stackPtr - 1));
232
-                if ($opener === false) {
231
+                $opener = $phpcsFile->findPrevious( \T_START_NOWDOC, ( $stackPtr - 1 ) );
232
+                if ( $opener === false ) {
233 233
                     return;
234 234
                 }
235 235
             }
236 236
 
237
-            $quotedIdentifier = preg_quote($tokens[$stackPtr]['content'], '`');
237
+            $quotedIdentifier = preg_quote( $tokens[ $stackPtr ][ 'content' ], '`' );
238 238
 
239 239
             // Throw an error for each line in the body which starts with the identifier.
240
-            for ($i = ($opener + 1); $i < $stackPtr; $i++) {
241
-                if (preg_match('`^[ \t]*' . $quotedIdentifier . '\b`', $tokens[$i]['content']) === 1) {
242
-                    $phpcsFile->addError($error, $i, $errorCode);
240
+            for ( $i = ( $opener + 1 ); $i < $stackPtr; $i++ ) {
241
+                if ( preg_match( '`^[ \t]*' . $quotedIdentifier . '\b`', $tokens[ $i ][ 'content' ] ) === 1 ) {
242
+                    $phpcsFile->addError( $error, $i, $errorCode );
243 243
                 }
244 244
             }
245 245
         }
Please login to merge, or discard this patch.
Braces   +5 added lines, -10 removed lines patch added patch discarded remove patch
@@ -30,16 +30,14 @@  discard block
 block discarded – undo
30 30
  * @package  PHPCompatibility
31 31
  * @author   Juliette Reinders Folmer <[email protected]>
32 32
  */
33
-class NewFlexibleHeredocNowdocSniff extends Sniff
34
-{
33
+class NewFlexibleHeredocNowdocSniff extends Sniff {
35 34
 
36 35
     /**
37 36
      * Returns an array of tokens this test wants to listen for.
38 37
      *
39 38
      * @return array
40 39
      */
41
-    public function register()
42
-    {
40
+    public function register() {
43 41
         $targets = array(
44 42
             \T_END_HEREDOC,
45 43
             \T_END_NOWDOC,
@@ -63,8 +61,7 @@  discard block
 block discarded – undo
63 61
      *
64 62
      * @return void
65 63
      */
66
-    public function process(File $phpcsFile, $stackPtr)
67
-    {
64
+    public function process(File $phpcsFile, $stackPtr) {
68 65
         /*
69 66
          * Due to a tokenizer bug which gets hit when the PHP 7.3 heredoc/nowdoc syntax
70 67
          * is used, this part of the sniff cannot possibly work on PHPCS < 2.6.0.
@@ -90,8 +87,7 @@  discard block
 block discarded – undo
90 87
      *
91 88
      * @return void
92 89
      */
93
-    protected function detectIndentedNonStandAloneClosingMarker(File $phpcsFile, $stackPtr)
94
-    {
90
+    protected function detectIndentedNonStandAloneClosingMarker(File $phpcsFile, $stackPtr) {
95 91
         $tokens            = $phpcsFile->getTokens();
96 92
         $indentError       = 'Heredoc/nowdoc with an indented closing marker is not supported in PHP 7.2 or earlier.';
97 93
         $indentErrorCode   = 'IndentedClosingMarker';
@@ -177,8 +173,7 @@  discard block
 block discarded – undo
177 173
      *
178 174
      * @return void
179 175
      */
180
-    protected function detectClosingMarkerInBody(File $phpcsFile, $stackPtr)
181
-    {
176
+    protected function detectClosingMarkerInBody(File $phpcsFile, $stackPtr) {
182 177
         $tokens    = $phpcsFile->getTokens();
183 178
         $error     = 'The body of a heredoc/nowdoc can not contain the heredoc/nowdoc closing marker as text at the start of a line since PHP 7.3.';
184 179
         $errorCode = 'ClosingMarkerNoNewLine';
Please login to merge, or discard this patch.
PHPCompatibility/Sniffs/Syntax/ForbiddenCallTimePassByReferenceSniff.php 4 patches
Indentation   +217 added lines, -217 removed lines patch added patch discarded remove patch
@@ -33,221 +33,221 @@
 block discarded – undo
33 33
 class ForbiddenCallTimePassByReferenceSniff extends Sniff
34 34
 {
35 35
 
36
-    /**
37
-     * Tokens that represent assignments or equality comparisons.
38
-     *
39
-     * Near duplicate of Tokens::$assignmentTokens + Tokens::$equalityTokens.
40
-     * Copied in for PHPCS cross-version compatibility.
41
-     *
42
-     * @var array
43
-     */
44
-    private $assignOrCompare = array(
45
-        // Equality tokens.
46
-        'T_IS_EQUAL'            => true,
47
-        'T_IS_NOT_EQUAL'        => true,
48
-        'T_IS_IDENTICAL'        => true,
49
-        'T_IS_NOT_IDENTICAL'    => true,
50
-        'T_IS_SMALLER_OR_EQUAL' => true,
51
-        'T_IS_GREATER_OR_EQUAL' => true,
52
-
53
-        // Assignment tokens.
54
-        'T_EQUAL'          => true,
55
-        'T_AND_EQUAL'      => true,
56
-        'T_OR_EQUAL'       => true,
57
-        'T_CONCAT_EQUAL'   => true,
58
-        'T_DIV_EQUAL'      => true,
59
-        'T_MINUS_EQUAL'    => true,
60
-        'T_POW_EQUAL'      => true,
61
-        'T_MOD_EQUAL'      => true,
62
-        'T_MUL_EQUAL'      => true,
63
-        'T_PLUS_EQUAL'     => true,
64
-        'T_XOR_EQUAL'      => true,
65
-        'T_DOUBLE_ARROW'   => true,
66
-        'T_SL_EQUAL'       => true,
67
-        'T_SR_EQUAL'       => true,
68
-        'T_COALESCE_EQUAL' => true,
69
-        'T_ZSR_EQUAL'      => true,
70
-    );
71
-
72
-    /**
73
-     * Returns an array of tokens this test wants to listen for.
74
-     *
75
-     * @return array
76
-     */
77
-    public function register()
78
-    {
79
-        return array(
80
-            \T_STRING,
81
-            \T_VARIABLE,
82
-        );
83
-    }
84
-
85
-    /**
86
-     * Processes this test, when one of its tokens is encountered.
87
-     *
88
-     * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned.
89
-     * @param int                   $stackPtr  The position of the current token
90
-     *                                         in the stack passed in $tokens.
91
-     *
92
-     * @return void
93
-     */
94
-    public function process(File $phpcsFile, $stackPtr)
95
-    {
96
-        if ($this->supportsAbove('5.3') === false) {
97
-            return;
98
-        }
99
-
100
-        $tokens = $phpcsFile->getTokens();
101
-
102
-        // Skip tokens that are the names of functions or classes
103
-        // within their definitions. For example: function myFunction...
104
-        // "myFunction" is T_STRING but we should skip because it is not a
105
-        // function or method *call*.
106
-        $findTokens   = Tokens::$emptyTokens;
107
-        $findTokens[] = \T_BITWISE_AND;
108
-
109
-        $prevNonEmpty = $phpcsFile->findPrevious(
110
-            $findTokens,
111
-            ($stackPtr - 1),
112
-            null,
113
-            true
114
-        );
115
-
116
-        if ($prevNonEmpty !== false && \in_array($tokens[$prevNonEmpty]['type'], array('T_FUNCTION', 'T_CLASS', 'T_INTERFACE', 'T_TRAIT'), true)) {
117
-            return;
118
-        }
119
-
120
-        // If the next non-whitespace token after the function or method call
121
-        // is not an opening parenthesis then it can't really be a *call*.
122
-        $openBracket = $phpcsFile->findNext(Tokens::$emptyTokens, ($stackPtr + 1), null, true);
123
-
124
-        if ($openBracket === false || $tokens[$openBracket]['code'] !== \T_OPEN_PARENTHESIS
125
-            || isset($tokens[$openBracket]['parenthesis_closer']) === false
126
-        ) {
127
-            return;
128
-        }
129
-
130
-        // Get the function call parameters.
131
-        $parameters = $this->getFunctionCallParameters($phpcsFile, $stackPtr);
132
-        if (\count($parameters) === 0) {
133
-            return;
134
-        }
135
-
136
-        // Which nesting level is the one we are interested in ?
137
-        $nestedParenthesisCount = 1;
138
-        if (isset($tokens[$openBracket]['nested_parenthesis'])) {
139
-            $nestedParenthesisCount = \count($tokens[$openBracket]['nested_parenthesis']) + 1;
140
-        }
141
-
142
-        foreach ($parameters as $parameter) {
143
-            if ($this->isCallTimePassByReferenceParam($phpcsFile, $parameter, $nestedParenthesisCount) === true) {
144
-                // T_BITWISE_AND represents a pass-by-reference.
145
-                $error     = 'Using a call-time pass-by-reference is deprecated since PHP 5.3';
146
-                $isError   = false;
147
-                $errorCode = 'Deprecated';
148
-
149
-                if ($this->supportsAbove('5.4')) {
150
-                    $error    .= ' and prohibited since PHP 5.4';
151
-                    $isError   = true;
152
-                    $errorCode = 'NotAllowed';
153
-                }
154
-
155
-                $this->addMessage($phpcsFile, $error, $parameter['start'], $isError, $errorCode);
156
-            }
157
-        }
158
-    }
159
-
160
-
161
-    /**
162
-     * Determine whether a parameter is passed by reference.
163
-     *
164
-     * @param \PHP_CodeSniffer_File $phpcsFile    The file being scanned.
165
-     * @param array                 $parameter    Information on the current parameter
166
-     *                                            to be examined.
167
-     * @param int                   $nestingLevel Target nesting level.
168
-     *
169
-     * @return bool
170
-     */
171
-    protected function isCallTimePassByReferenceParam(File $phpcsFile, $parameter, $nestingLevel)
172
-    {
173
-        $tokens = $phpcsFile->getTokens();
174
-
175
-        $searchStartToken = $parameter['start'] - 1;
176
-        $searchEndToken   = $parameter['end'] + 1;
177
-        $nextVariable     = $searchStartToken;
178
-        do {
179
-            $nextVariable = $phpcsFile->findNext(array(\T_VARIABLE, \T_OPEN_SHORT_ARRAY, \T_CLOSURE), ($nextVariable + 1), $searchEndToken);
180
-            if ($nextVariable === false) {
181
-                return false;
182
-            }
183
-
184
-            // Ignore anything within short array definition brackets.
185
-            if ($tokens[$nextVariable]['type'] === 'T_OPEN_SHORT_ARRAY'
186
-                && (isset($tokens[$nextVariable]['bracket_opener'])
187
-                    && $tokens[$nextVariable]['bracket_opener'] === $nextVariable)
188
-                && isset($tokens[$nextVariable]['bracket_closer'])
189
-            ) {
190
-                // Skip forward to the end of the short array definition.
191
-                $nextVariable = $tokens[$nextVariable]['bracket_closer'];
192
-                continue;
193
-            }
194
-
195
-            // Skip past closures passed as function parameters.
196
-            if ($tokens[$nextVariable]['type'] === 'T_CLOSURE'
197
-                && (isset($tokens[$nextVariable]['scope_condition'])
198
-                    && $tokens[$nextVariable]['scope_condition'] === $nextVariable)
199
-                && isset($tokens[$nextVariable]['scope_closer'])
200
-            ) {
201
-                // Skip forward to the end of the closure declaration.
202
-                $nextVariable = $tokens[$nextVariable]['scope_closer'];
203
-                continue;
204
-            }
205
-
206
-            // Make sure the variable belongs directly to this function call
207
-            // and is not inside a nested function call or array.
208
-            if (isset($tokens[$nextVariable]['nested_parenthesis']) === false
209
-                || (\count($tokens[$nextVariable]['nested_parenthesis']) !== $nestingLevel)
210
-            ) {
211
-                continue;
212
-            }
213
-
214
-            // Checking this: $value = my_function(...[*]$arg...).
215
-            $tokenBefore = $phpcsFile->findPrevious(
216
-                Tokens::$emptyTokens,
217
-                ($nextVariable - 1),
218
-                $searchStartToken,
219
-                true
220
-            );
221
-
222
-            if ($tokenBefore === false || $tokens[$tokenBefore]['code'] !== \T_BITWISE_AND) {
223
-                // Nothing before the token or no &.
224
-                continue;
225
-            }
226
-
227
-            if ($phpcsFile->isReference($tokenBefore) === false) {
228
-                continue;
229
-            }
230
-
231
-            // Checking this: $value = my_function(...[*]&$arg...).
232
-            $tokenBefore = $phpcsFile->findPrevious(
233
-                Tokens::$emptyTokens,
234
-                ($tokenBefore - 1),
235
-                $searchStartToken,
236
-                true
237
-            );
238
-
239
-            // Prevent false positive on assign by reference and compare with reference
240
-            // within function call parameters.
241
-            if (isset($this->assignOrCompare[$tokens[$tokenBefore]['type']])) {
242
-                continue;
243
-            }
244
-
245
-            // The found T_BITWISE_AND represents a pass-by-reference.
246
-            return true;
247
-
248
-        } while ($nextVariable < $searchEndToken);
249
-
250
-        // This code should never be reached, but here in case of weird bugs.
251
-        return false;
252
-    }
36
+	/**
37
+	 * Tokens that represent assignments or equality comparisons.
38
+	 *
39
+	 * Near duplicate of Tokens::$assignmentTokens + Tokens::$equalityTokens.
40
+	 * Copied in for PHPCS cross-version compatibility.
41
+	 *
42
+	 * @var array
43
+	 */
44
+	private $assignOrCompare = array(
45
+		// Equality tokens.
46
+		'T_IS_EQUAL'            => true,
47
+		'T_IS_NOT_EQUAL'        => true,
48
+		'T_IS_IDENTICAL'        => true,
49
+		'T_IS_NOT_IDENTICAL'    => true,
50
+		'T_IS_SMALLER_OR_EQUAL' => true,
51
+		'T_IS_GREATER_OR_EQUAL' => true,
52
+
53
+		// Assignment tokens.
54
+		'T_EQUAL'          => true,
55
+		'T_AND_EQUAL'      => true,
56
+		'T_OR_EQUAL'       => true,
57
+		'T_CONCAT_EQUAL'   => true,
58
+		'T_DIV_EQUAL'      => true,
59
+		'T_MINUS_EQUAL'    => true,
60
+		'T_POW_EQUAL'      => true,
61
+		'T_MOD_EQUAL'      => true,
62
+		'T_MUL_EQUAL'      => true,
63
+		'T_PLUS_EQUAL'     => true,
64
+		'T_XOR_EQUAL'      => true,
65
+		'T_DOUBLE_ARROW'   => true,
66
+		'T_SL_EQUAL'       => true,
67
+		'T_SR_EQUAL'       => true,
68
+		'T_COALESCE_EQUAL' => true,
69
+		'T_ZSR_EQUAL'      => true,
70
+	);
71
+
72
+	/**
73
+	 * Returns an array of tokens this test wants to listen for.
74
+	 *
75
+	 * @return array
76
+	 */
77
+	public function register()
78
+	{
79
+		return array(
80
+			\T_STRING,
81
+			\T_VARIABLE,
82
+		);
83
+	}
84
+
85
+	/**
86
+	 * Processes this test, when one of its tokens is encountered.
87
+	 *
88
+	 * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned.
89
+	 * @param int                   $stackPtr  The position of the current token
90
+	 *                                         in the stack passed in $tokens.
91
+	 *
92
+	 * @return void
93
+	 */
94
+	public function process(File $phpcsFile, $stackPtr)
95
+	{
96
+		if ($this->supportsAbove('5.3') === false) {
97
+			return;
98
+		}
99
+
100
+		$tokens = $phpcsFile->getTokens();
101
+
102
+		// Skip tokens that are the names of functions or classes
103
+		// within their definitions. For example: function myFunction...
104
+		// "myFunction" is T_STRING but we should skip because it is not a
105
+		// function or method *call*.
106
+		$findTokens   = Tokens::$emptyTokens;
107
+		$findTokens[] = \T_BITWISE_AND;
108
+
109
+		$prevNonEmpty = $phpcsFile->findPrevious(
110
+			$findTokens,
111
+			($stackPtr - 1),
112
+			null,
113
+			true
114
+		);
115
+
116
+		if ($prevNonEmpty !== false && \in_array($tokens[$prevNonEmpty]['type'], array('T_FUNCTION', 'T_CLASS', 'T_INTERFACE', 'T_TRAIT'), true)) {
117
+			return;
118
+		}
119
+
120
+		// If the next non-whitespace token after the function or method call
121
+		// is not an opening parenthesis then it can't really be a *call*.
122
+		$openBracket = $phpcsFile->findNext(Tokens::$emptyTokens, ($stackPtr + 1), null, true);
123
+
124
+		if ($openBracket === false || $tokens[$openBracket]['code'] !== \T_OPEN_PARENTHESIS
125
+			|| isset($tokens[$openBracket]['parenthesis_closer']) === false
126
+		) {
127
+			return;
128
+		}
129
+
130
+		// Get the function call parameters.
131
+		$parameters = $this->getFunctionCallParameters($phpcsFile, $stackPtr);
132
+		if (\count($parameters) === 0) {
133
+			return;
134
+		}
135
+
136
+		// Which nesting level is the one we are interested in ?
137
+		$nestedParenthesisCount = 1;
138
+		if (isset($tokens[$openBracket]['nested_parenthesis'])) {
139
+			$nestedParenthesisCount = \count($tokens[$openBracket]['nested_parenthesis']) + 1;
140
+		}
141
+
142
+		foreach ($parameters as $parameter) {
143
+			if ($this->isCallTimePassByReferenceParam($phpcsFile, $parameter, $nestedParenthesisCount) === true) {
144
+				// T_BITWISE_AND represents a pass-by-reference.
145
+				$error     = 'Using a call-time pass-by-reference is deprecated since PHP 5.3';
146
+				$isError   = false;
147
+				$errorCode = 'Deprecated';
148
+
149
+				if ($this->supportsAbove('5.4')) {
150
+					$error    .= ' and prohibited since PHP 5.4';
151
+					$isError   = true;
152
+					$errorCode = 'NotAllowed';
153
+				}
154
+
155
+				$this->addMessage($phpcsFile, $error, $parameter['start'], $isError, $errorCode);
156
+			}
157
+		}
158
+	}
159
+
160
+
161
+	/**
162
+	 * Determine whether a parameter is passed by reference.
163
+	 *
164
+	 * @param \PHP_CodeSniffer_File $phpcsFile    The file being scanned.
165
+	 * @param array                 $parameter    Information on the current parameter
166
+	 *                                            to be examined.
167
+	 * @param int                   $nestingLevel Target nesting level.
168
+	 *
169
+	 * @return bool
170
+	 */
171
+	protected function isCallTimePassByReferenceParam(File $phpcsFile, $parameter, $nestingLevel)
172
+	{
173
+		$tokens = $phpcsFile->getTokens();
174
+
175
+		$searchStartToken = $parameter['start'] - 1;
176
+		$searchEndToken   = $parameter['end'] + 1;
177
+		$nextVariable     = $searchStartToken;
178
+		do {
179
+			$nextVariable = $phpcsFile->findNext(array(\T_VARIABLE, \T_OPEN_SHORT_ARRAY, \T_CLOSURE), ($nextVariable + 1), $searchEndToken);
180
+			if ($nextVariable === false) {
181
+				return false;
182
+			}
183
+
184
+			// Ignore anything within short array definition brackets.
185
+			if ($tokens[$nextVariable]['type'] === 'T_OPEN_SHORT_ARRAY'
186
+				&& (isset($tokens[$nextVariable]['bracket_opener'])
187
+					&& $tokens[$nextVariable]['bracket_opener'] === $nextVariable)
188
+				&& isset($tokens[$nextVariable]['bracket_closer'])
189
+			) {
190
+				// Skip forward to the end of the short array definition.
191
+				$nextVariable = $tokens[$nextVariable]['bracket_closer'];
192
+				continue;
193
+			}
194
+
195
+			// Skip past closures passed as function parameters.
196
+			if ($tokens[$nextVariable]['type'] === 'T_CLOSURE'
197
+				&& (isset($tokens[$nextVariable]['scope_condition'])
198
+					&& $tokens[$nextVariable]['scope_condition'] === $nextVariable)
199
+				&& isset($tokens[$nextVariable]['scope_closer'])
200
+			) {
201
+				// Skip forward to the end of the closure declaration.
202
+				$nextVariable = $tokens[$nextVariable]['scope_closer'];
203
+				continue;
204
+			}
205
+
206
+			// Make sure the variable belongs directly to this function call
207
+			// and is not inside a nested function call or array.
208
+			if (isset($tokens[$nextVariable]['nested_parenthesis']) === false
209
+				|| (\count($tokens[$nextVariable]['nested_parenthesis']) !== $nestingLevel)
210
+			) {
211
+				continue;
212
+			}
213
+
214
+			// Checking this: $value = my_function(...[*]$arg...).
215
+			$tokenBefore = $phpcsFile->findPrevious(
216
+				Tokens::$emptyTokens,
217
+				($nextVariable - 1),
218
+				$searchStartToken,
219
+				true
220
+			);
221
+
222
+			if ($tokenBefore === false || $tokens[$tokenBefore]['code'] !== \T_BITWISE_AND) {
223
+				// Nothing before the token or no &.
224
+				continue;
225
+			}
226
+
227
+			if ($phpcsFile->isReference($tokenBefore) === false) {
228
+				continue;
229
+			}
230
+
231
+			// Checking this: $value = my_function(...[*]&$arg...).
232
+			$tokenBefore = $phpcsFile->findPrevious(
233
+				Tokens::$emptyTokens,
234
+				($tokenBefore - 1),
235
+				$searchStartToken,
236
+				true
237
+			);
238
+
239
+			// Prevent false positive on assign by reference and compare with reference
240
+			// within function call parameters.
241
+			if (isset($this->assignOrCompare[$tokens[$tokenBefore]['type']])) {
242
+				continue;
243
+			}
244
+
245
+			// The found T_BITWISE_AND represents a pass-by-reference.
246
+			return true;
247
+
248
+		} while ($nextVariable < $searchEndToken);
249
+
250
+		// This code should never be reached, but here in case of weird bugs.
251
+		return false;
252
+	}
253 253
 }
Please login to merge, or discard this patch.
Spacing   +39 added lines, -39 removed lines patch added patch discarded remove patch
@@ -91,9 +91,9 @@  discard block
 block discarded – undo
91 91
      *
92 92
      * @return void
93 93
      */
94
-    public function process(File $phpcsFile, $stackPtr)
94
+    public function process( File $phpcsFile, $stackPtr )
95 95
     {
96
-        if ($this->supportsAbove('5.3') === false) {
96
+        if ( $this->supportsAbove( '5.3' ) === false ) {
97 97
             return;
98 98
         }
99 99
 
@@ -104,55 +104,55 @@  discard block
 block discarded – undo
104 104
         // "myFunction" is T_STRING but we should skip because it is not a
105 105
         // function or method *call*.
106 106
         $findTokens   = Tokens::$emptyTokens;
107
-        $findTokens[] = \T_BITWISE_AND;
107
+        $findTokens[ ] = \T_BITWISE_AND;
108 108
 
109 109
         $prevNonEmpty = $phpcsFile->findPrevious(
110 110
             $findTokens,
111
-            ($stackPtr - 1),
111
+            ( $stackPtr - 1 ),
112 112
             null,
113 113
             true
114 114
         );
115 115
 
116
-        if ($prevNonEmpty !== false && \in_array($tokens[$prevNonEmpty]['type'], array('T_FUNCTION', 'T_CLASS', 'T_INTERFACE', 'T_TRAIT'), true)) {
116
+        if ( $prevNonEmpty !== false && \in_array( $tokens[ $prevNonEmpty ][ 'type' ], array( 'T_FUNCTION', 'T_CLASS', 'T_INTERFACE', 'T_TRAIT' ), true ) ) {
117 117
             return;
118 118
         }
119 119
 
120 120
         // If the next non-whitespace token after the function or method call
121 121
         // is not an opening parenthesis then it can't really be a *call*.
122
-        $openBracket = $phpcsFile->findNext(Tokens::$emptyTokens, ($stackPtr + 1), null, true);
122
+        $openBracket = $phpcsFile->findNext( Tokens::$emptyTokens, ( $stackPtr + 1 ), null, true );
123 123
 
124
-        if ($openBracket === false || $tokens[$openBracket]['code'] !== \T_OPEN_PARENTHESIS
125
-            || isset($tokens[$openBracket]['parenthesis_closer']) === false
124
+        if ( $openBracket === false || $tokens[ $openBracket ][ 'code' ] !== \T_OPEN_PARENTHESIS
125
+            || isset( $tokens[ $openBracket ][ 'parenthesis_closer' ] ) === false
126 126
         ) {
127 127
             return;
128 128
         }
129 129
 
130 130
         // Get the function call parameters.
131
-        $parameters = $this->getFunctionCallParameters($phpcsFile, $stackPtr);
132
-        if (\count($parameters) === 0) {
131
+        $parameters = $this->getFunctionCallParameters( $phpcsFile, $stackPtr );
132
+        if ( \count( $parameters ) === 0 ) {
133 133
             return;
134 134
         }
135 135
 
136 136
         // Which nesting level is the one we are interested in ?
137 137
         $nestedParenthesisCount = 1;
138
-        if (isset($tokens[$openBracket]['nested_parenthesis'])) {
139
-            $nestedParenthesisCount = \count($tokens[$openBracket]['nested_parenthesis']) + 1;
138
+        if ( isset( $tokens[ $openBracket ][ 'nested_parenthesis' ] ) ) {
139
+            $nestedParenthesisCount = \count( $tokens[ $openBracket ][ 'nested_parenthesis' ] ) + 1;
140 140
         }
141 141
 
142
-        foreach ($parameters as $parameter) {
143
-            if ($this->isCallTimePassByReferenceParam($phpcsFile, $parameter, $nestedParenthesisCount) === true) {
142
+        foreach ( $parameters as $parameter ) {
143
+            if ( $this->isCallTimePassByReferenceParam( $phpcsFile, $parameter, $nestedParenthesisCount ) === true ) {
144 144
                 // T_BITWISE_AND represents a pass-by-reference.
145 145
                 $error     = 'Using a call-time pass-by-reference is deprecated since PHP 5.3';
146 146
                 $isError   = false;
147 147
                 $errorCode = 'Deprecated';
148 148
 
149
-                if ($this->supportsAbove('5.4')) {
149
+                if ( $this->supportsAbove( '5.4' ) ) {
150 150
                     $error    .= ' and prohibited since PHP 5.4';
151 151
                     $isError   = true;
152 152
                     $errorCode = 'NotAllowed';
153 153
                 }
154 154
 
155
-                $this->addMessage($phpcsFile, $error, $parameter['start'], $isError, $errorCode);
155
+                $this->addMessage( $phpcsFile, $error, $parameter[ 'start' ], $isError, $errorCode );
156 156
             }
157 157
         }
158 158
     }
@@ -168,45 +168,45 @@  discard block
 block discarded – undo
168 168
      *
169 169
      * @return bool
170 170
      */
171
-    protected function isCallTimePassByReferenceParam(File $phpcsFile, $parameter, $nestingLevel)
171
+    protected function isCallTimePassByReferenceParam( File $phpcsFile, $parameter, $nestingLevel )
172 172
     {
173 173
         $tokens = $phpcsFile->getTokens();
174 174
 
175
-        $searchStartToken = $parameter['start'] - 1;
176
-        $searchEndToken   = $parameter['end'] + 1;
175
+        $searchStartToken = $parameter[ 'start' ] - 1;
176
+        $searchEndToken   = $parameter[ 'end' ] + 1;
177 177
         $nextVariable     = $searchStartToken;
178 178
         do {
179
-            $nextVariable = $phpcsFile->findNext(array(\T_VARIABLE, \T_OPEN_SHORT_ARRAY, \T_CLOSURE), ($nextVariable + 1), $searchEndToken);
180
-            if ($nextVariable === false) {
179
+            $nextVariable = $phpcsFile->findNext( array( \T_VARIABLE, \T_OPEN_SHORT_ARRAY, \T_CLOSURE ), ( $nextVariable + 1 ), $searchEndToken );
180
+            if ( $nextVariable === false ) {
181 181
                 return false;
182 182
             }
183 183
 
184 184
             // Ignore anything within short array definition brackets.
185
-            if ($tokens[$nextVariable]['type'] === 'T_OPEN_SHORT_ARRAY'
186
-                && (isset($tokens[$nextVariable]['bracket_opener'])
187
-                    && $tokens[$nextVariable]['bracket_opener'] === $nextVariable)
188
-                && isset($tokens[$nextVariable]['bracket_closer'])
185
+            if ( $tokens[ $nextVariable ][ 'type' ] === 'T_OPEN_SHORT_ARRAY'
186
+                && ( isset( $tokens[ $nextVariable ][ 'bracket_opener' ] )
187
+                    && $tokens[ $nextVariable ][ 'bracket_opener' ] === $nextVariable )
188
+                && isset( $tokens[ $nextVariable ][ 'bracket_closer' ] )
189 189
             ) {
190 190
                 // Skip forward to the end of the short array definition.
191
-                $nextVariable = $tokens[$nextVariable]['bracket_closer'];
191
+                $nextVariable = $tokens[ $nextVariable ][ 'bracket_closer' ];
192 192
                 continue;
193 193
             }
194 194
 
195 195
             // Skip past closures passed as function parameters.
196
-            if ($tokens[$nextVariable]['type'] === 'T_CLOSURE'
197
-                && (isset($tokens[$nextVariable]['scope_condition'])
198
-                    && $tokens[$nextVariable]['scope_condition'] === $nextVariable)
199
-                && isset($tokens[$nextVariable]['scope_closer'])
196
+            if ( $tokens[ $nextVariable ][ 'type' ] === 'T_CLOSURE'
197
+                && ( isset( $tokens[ $nextVariable ][ 'scope_condition' ] )
198
+                    && $tokens[ $nextVariable ][ 'scope_condition' ] === $nextVariable )
199
+                && isset( $tokens[ $nextVariable ][ 'scope_closer' ] )
200 200
             ) {
201 201
                 // Skip forward to the end of the closure declaration.
202
-                $nextVariable = $tokens[$nextVariable]['scope_closer'];
202
+                $nextVariable = $tokens[ $nextVariable ][ 'scope_closer' ];
203 203
                 continue;
204 204
             }
205 205
 
206 206
             // Make sure the variable belongs directly to this function call
207 207
             // and is not inside a nested function call or array.
208
-            if (isset($tokens[$nextVariable]['nested_parenthesis']) === false
209
-                || (\count($tokens[$nextVariable]['nested_parenthesis']) !== $nestingLevel)
208
+            if ( isset( $tokens[ $nextVariable ][ 'nested_parenthesis' ] ) === false
209
+                || ( \count( $tokens[ $nextVariable ][ 'nested_parenthesis' ] ) !== $nestingLevel )
210 210
             ) {
211 211
                 continue;
212 212
             }
@@ -214,38 +214,38 @@  discard block
 block discarded – undo
214 214
             // Checking this: $value = my_function(...[*]$arg...).
215 215
             $tokenBefore = $phpcsFile->findPrevious(
216 216
                 Tokens::$emptyTokens,
217
-                ($nextVariable - 1),
217
+                ( $nextVariable - 1 ),
218 218
                 $searchStartToken,
219 219
                 true
220 220
             );
221 221
 
222
-            if ($tokenBefore === false || $tokens[$tokenBefore]['code'] !== \T_BITWISE_AND) {
222
+            if ( $tokenBefore === false || $tokens[ $tokenBefore ][ 'code' ] !== \T_BITWISE_AND ) {
223 223
                 // Nothing before the token or no &.
224 224
                 continue;
225 225
             }
226 226
 
227
-            if ($phpcsFile->isReference($tokenBefore) === false) {
227
+            if ( $phpcsFile->isReference( $tokenBefore ) === false ) {
228 228
                 continue;
229 229
             }
230 230
 
231 231
             // Checking this: $value = my_function(...[*]&$arg...).
232 232
             $tokenBefore = $phpcsFile->findPrevious(
233 233
                 Tokens::$emptyTokens,
234
-                ($tokenBefore - 1),
234
+                ( $tokenBefore - 1 ),
235 235
                 $searchStartToken,
236 236
                 true
237 237
             );
238 238
 
239 239
             // Prevent false positive on assign by reference and compare with reference
240 240
             // within function call parameters.
241
-            if (isset($this->assignOrCompare[$tokens[$tokenBefore]['type']])) {
241
+            if ( isset( $this->assignOrCompare[ $tokens[ $tokenBefore ][ 'type' ] ] ) ) {
242 242
                 continue;
243 243
             }
244 244
 
245 245
             // The found T_BITWISE_AND represents a pass-by-reference.
246 246
             return true;
247 247
 
248
-        } while ($nextVariable < $searchEndToken);
248
+        } while ( $nextVariable < $searchEndToken );
249 249
 
250 250
         // This code should never be reached, but here in case of weird bugs.
251 251
         return false;
Please login to merge, or discard this patch.
Braces   +4 added lines, -8 removed lines patch added patch discarded remove patch
@@ -30,8 +30,7 @@  discard block
 block discarded – undo
30 30
  * @author    Florian Grandel <[email protected]>
31 31
  * @copyright 2009 Florian Grandel
32 32
  */
33
-class ForbiddenCallTimePassByReferenceSniff extends Sniff
34
-{
33
+class ForbiddenCallTimePassByReferenceSniff extends Sniff {
35 34
 
36 35
     /**
37 36
      * Tokens that represent assignments or equality comparisons.
@@ -74,8 +73,7 @@  discard block
 block discarded – undo
74 73
      *
75 74
      * @return array
76 75
      */
77
-    public function register()
78
-    {
76
+    public function register() {
79 77
         return array(
80 78
             \T_STRING,
81 79
             \T_VARIABLE,
@@ -91,8 +89,7 @@  discard block
 block discarded – undo
91 89
      *
92 90
      * @return void
93 91
      */
94
-    public function process(File $phpcsFile, $stackPtr)
95
-    {
92
+    public function process(File $phpcsFile, $stackPtr) {
96 93
         if ($this->supportsAbove('5.3') === false) {
97 94
             return;
98 95
         }
@@ -168,8 +165,7 @@  discard block
 block discarded – undo
168 165
      *
169 166
      * @return bool
170 167
      */
171
-    protected function isCallTimePassByReferenceParam(File $phpcsFile, $parameter, $nestingLevel)
172
-    {
168
+    protected function isCallTimePassByReferenceParam(File $phpcsFile, $parameter, $nestingLevel) {
173 169
         $tokens = $phpcsFile->getTokens();
174 170
 
175 171
         $searchStartToken = $parameter['start'] - 1;
Please login to merge, or discard this patch.
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -65,7 +65,7 @@
 block discarded – undo
65 65
     /**
66 66
      * Returns an array of tokens this test wants to listen for.
67 67
      *
68
-     * @return array
68
+     * @return integer[]
69 69
      */
70 70
     public function register()
71 71
     {
Please login to merge, or discard this patch.
PHPCompatibility/Sniffs/Syntax/NewClassMemberAccessSniff.php 4 patches
Indentation   +67 added lines, -67 removed lines patch added patch discarded remove patch
@@ -32,82 +32,82 @@
 block discarded – undo
32 32
 class NewClassMemberAccessSniff extends Sniff
33 33
 {
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(
43
-            \T_NEW,
44
-            \T_CLONE,
45
-        );
46
-    }
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(
43
+			\T_NEW,
44
+			\T_CLONE,
45
+		);
46
+	}
47 47
 
48
-    /**
49
-     * Processes this test, when one of its tokens is encountered.
50
-     *
51
-     * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned.
52
-     * @param int                   $stackPtr  The position of the current token in the
53
-     *                                         stack passed in $tokens.
54
-     *
55
-     * @return void
56
-     */
57
-    public function process(File $phpcsFile, $stackPtr)
58
-    {
59
-        $tokens = $phpcsFile->getTokens();
48
+	/**
49
+	 * Processes this test, when one of its tokens is encountered.
50
+	 *
51
+	 * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned.
52
+	 * @param int                   $stackPtr  The position of the current token in the
53
+	 *                                         stack passed in $tokens.
54
+	 *
55
+	 * @return void
56
+	 */
57
+	public function process(File $phpcsFile, $stackPtr)
58
+	{
59
+		$tokens = $phpcsFile->getTokens();
60 60
 
61
-        if ($tokens[$stackPtr]['code'] === \T_NEW && $this->supportsBelow('5.3') !== true) {
62
-            return;
63
-        } elseif ($tokens[$stackPtr]['code'] === \T_CLONE && $this->supportsBelow('5.6') !== true) {
64
-            return;
65
-        }
61
+		if ($tokens[$stackPtr]['code'] === \T_NEW && $this->supportsBelow('5.3') !== true) {
62
+			return;
63
+		} elseif ($tokens[$stackPtr]['code'] === \T_CLONE && $this->supportsBelow('5.6') !== true) {
64
+			return;
65
+		}
66 66
 
67
-        if (isset($tokens[$stackPtr]['nested_parenthesis']) === false) {
68
-            // The `new className/clone $a` has to be in parentheses, without is not supported.
69
-            return;
70
-        }
67
+		if (isset($tokens[$stackPtr]['nested_parenthesis']) === false) {
68
+			// The `new className/clone $a` has to be in parentheses, without is not supported.
69
+			return;
70
+		}
71 71
 
72
-        $parenthesisCloser = end($tokens[$stackPtr]['nested_parenthesis']);
73
-        $parenthesisOpener = key($tokens[$stackPtr]['nested_parenthesis']);
72
+		$parenthesisCloser = end($tokens[$stackPtr]['nested_parenthesis']);
73
+		$parenthesisOpener = key($tokens[$stackPtr]['nested_parenthesis']);
74 74
 
75
-        if (isset($tokens[$parenthesisOpener]['parenthesis_owner']) === true) {
76
-            // If there is an owner, these parentheses are for a different purpose.
77
-            return;
78
-        }
75
+		if (isset($tokens[$parenthesisOpener]['parenthesis_owner']) === true) {
76
+			// If there is an owner, these parentheses are for a different purpose.
77
+			return;
78
+		}
79 79
 
80
-        $prevBeforeParenthesis = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($parenthesisOpener - 1), null, true);
81
-        if ($prevBeforeParenthesis !== false && $tokens[$prevBeforeParenthesis]['code'] === \T_STRING) {
82
-            // This is most likely a function call with the new/cloned object as a parameter.
83
-            return;
84
-        }
80
+		$prevBeforeParenthesis = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($parenthesisOpener - 1), null, true);
81
+		if ($prevBeforeParenthesis !== false && $tokens[$prevBeforeParenthesis]['code'] === \T_STRING) {
82
+			// This is most likely a function call with the new/cloned object as a parameter.
83
+			return;
84
+		}
85 85
 
86
-        $nextAfterParenthesis = $phpcsFile->findNext(Tokens::$emptyTokens, ($parenthesisCloser + 1), null, true);
87
-        if ($nextAfterParenthesis === false) {
88
-            // Live coding.
89
-            return;
90
-        }
86
+		$nextAfterParenthesis = $phpcsFile->findNext(Tokens::$emptyTokens, ($parenthesisCloser + 1), null, true);
87
+		if ($nextAfterParenthesis === false) {
88
+			// Live coding.
89
+			return;
90
+		}
91 91
 
92
-        if ($tokens[$nextAfterParenthesis]['code'] !== \T_OBJECT_OPERATOR
93
-            && $tokens[$nextAfterParenthesis]['code'] !== \T_OPEN_SQUARE_BRACKET
94
-        ) {
95
-            return;
96
-        }
92
+		if ($tokens[$nextAfterParenthesis]['code'] !== \T_OBJECT_OPERATOR
93
+			&& $tokens[$nextAfterParenthesis]['code'] !== \T_OPEN_SQUARE_BRACKET
94
+		) {
95
+			return;
96
+		}
97 97
 
98
-        $data      = array('instantiation', '5.3');
99
-        $errorCode = 'OnNewFound';
98
+		$data      = array('instantiation', '5.3');
99
+		$errorCode = 'OnNewFound';
100 100
 
101
-        if ($tokens[$stackPtr]['code'] === \T_CLONE) {
102
-            $data      = array('cloning', '5.6');
103
-            $errorCode = 'OnCloneFound';
104
-        }
101
+		if ($tokens[$stackPtr]['code'] === \T_CLONE) {
102
+			$data      = array('cloning', '5.6');
103
+			$errorCode = 'OnCloneFound';
104
+		}
105 105
 
106
-        $phpcsFile->addError(
107
-            'Class member access on object %s was not supported in PHP %s or earlier',
108
-            $parenthesisCloser,
109
-            $errorCode,
110
-            $data
111
-        );
112
-    }
106
+		$phpcsFile->addError(
107
+			'Class member access on object %s was not supported in PHP %s or earlier',
108
+			$parenthesisCloser,
109
+			$errorCode,
110
+			$data
111
+		);
112
+	}
113 113
 }
Please login to merge, or discard this patch.
Spacing   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -54,52 +54,52 @@
 block discarded – undo
54 54
      *
55 55
      * @return void
56 56
      */
57
-    public function process(File $phpcsFile, $stackPtr)
57
+    public function process( File $phpcsFile, $stackPtr )
58 58
     {
59 59
         $tokens = $phpcsFile->getTokens();
60 60
 
61
-        if ($tokens[$stackPtr]['code'] === \T_NEW && $this->supportsBelow('5.3') !== true) {
61
+        if ( $tokens[ $stackPtr ][ 'code' ] === \T_NEW && $this->supportsBelow( '5.3' ) !== true ) {
62 62
             return;
63
-        } elseif ($tokens[$stackPtr]['code'] === \T_CLONE && $this->supportsBelow('5.6') !== true) {
63
+        } elseif ( $tokens[ $stackPtr ][ 'code' ] === \T_CLONE && $this->supportsBelow( '5.6' ) !== true ) {
64 64
             return;
65 65
         }
66 66
 
67
-        if (isset($tokens[$stackPtr]['nested_parenthesis']) === false) {
67
+        if ( isset( $tokens[ $stackPtr ][ 'nested_parenthesis' ] ) === false ) {
68 68
             // The `new className/clone $a` has to be in parentheses, without is not supported.
69 69
             return;
70 70
         }
71 71
 
72
-        $parenthesisCloser = end($tokens[$stackPtr]['nested_parenthesis']);
73
-        $parenthesisOpener = key($tokens[$stackPtr]['nested_parenthesis']);
72
+        $parenthesisCloser = end( $tokens[ $stackPtr ][ 'nested_parenthesis' ] );
73
+        $parenthesisOpener = key( $tokens[ $stackPtr ][ 'nested_parenthesis' ] );
74 74
 
75
-        if (isset($tokens[$parenthesisOpener]['parenthesis_owner']) === true) {
75
+        if ( isset( $tokens[ $parenthesisOpener ][ 'parenthesis_owner' ] ) === true ) {
76 76
             // If there is an owner, these parentheses are for a different purpose.
77 77
             return;
78 78
         }
79 79
 
80
-        $prevBeforeParenthesis = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($parenthesisOpener - 1), null, true);
81
-        if ($prevBeforeParenthesis !== false && $tokens[$prevBeforeParenthesis]['code'] === \T_STRING) {
80
+        $prevBeforeParenthesis = $phpcsFile->findPrevious( Tokens::$emptyTokens, ( $parenthesisOpener - 1 ), null, true );
81
+        if ( $prevBeforeParenthesis !== false && $tokens[ $prevBeforeParenthesis ][ 'code' ] === \T_STRING ) {
82 82
             // This is most likely a function call with the new/cloned object as a parameter.
83 83
             return;
84 84
         }
85 85
 
86
-        $nextAfterParenthesis = $phpcsFile->findNext(Tokens::$emptyTokens, ($parenthesisCloser + 1), null, true);
87
-        if ($nextAfterParenthesis === false) {
86
+        $nextAfterParenthesis = $phpcsFile->findNext( Tokens::$emptyTokens, ( $parenthesisCloser + 1 ), null, true );
87
+        if ( $nextAfterParenthesis === false ) {
88 88
             // Live coding.
89 89
             return;
90 90
         }
91 91
 
92
-        if ($tokens[$nextAfterParenthesis]['code'] !== \T_OBJECT_OPERATOR
93
-            && $tokens[$nextAfterParenthesis]['code'] !== \T_OPEN_SQUARE_BRACKET
92
+        if ( $tokens[ $nextAfterParenthesis ][ 'code' ] !== \T_OBJECT_OPERATOR
93
+            && $tokens[ $nextAfterParenthesis ][ 'code' ] !== \T_OPEN_SQUARE_BRACKET
94 94
         ) {
95 95
             return;
96 96
         }
97 97
 
98
-        $data      = array('instantiation', '5.3');
98
+        $data      = array( 'instantiation', '5.3' );
99 99
         $errorCode = 'OnNewFound';
100 100
 
101
-        if ($tokens[$stackPtr]['code'] === \T_CLONE) {
102
-            $data      = array('cloning', '5.6');
101
+        if ( $tokens[ $stackPtr ][ 'code' ] === \T_CLONE ) {
102
+            $data      = array( 'cloning', '5.6' );
103 103
             $errorCode = 'OnCloneFound';
104 104
         }
105 105
 
Please login to merge, or discard this patch.
Braces   +3 added lines, -6 removed lines patch added patch discarded remove patch
@@ -29,16 +29,14 @@  discard block
 block discarded – undo
29 29
  * @package  PHPCompatibility
30 30
  * @author   Juliette Reinders Folmer <[email protected]>
31 31
  */
32
-class NewClassMemberAccessSniff extends Sniff
33
-{
32
+class NewClassMemberAccessSniff extends Sniff {
34 33
 
35 34
     /**
36 35
      * Returns an array of tokens this test wants to listen for.
37 36
      *
38 37
      * @return array
39 38
      */
40
-    public function register()
41
-    {
39
+    public function register() {
42 40
         return array(
43 41
             \T_NEW,
44 42
             \T_CLONE,
@@ -54,8 +52,7 @@  discard block
 block discarded – undo
54 52
      *
55 53
      * @return void
56 54
      */
57
-    public function process(File $phpcsFile, $stackPtr)
58
-    {
55
+    public function process(File $phpcsFile, $stackPtr) {
59 56
         $tokens = $phpcsFile->getTokens();
60 57
 
61 58
         if ($tokens[$stackPtr]['code'] === \T_NEW && $this->supportsBelow('5.3') !== true) {
Please login to merge, or discard this patch.
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -65,7 +65,7 @@
 block discarded – undo
65 65
     /**
66 66
      * Returns an array of tokens this test wants to listen for.
67 67
      *
68
-     * @return array
68
+     * @return integer[]
69 69
      */
70 70
     public function register()
71 71
     {
Please login to merge, or discard this patch.