Completed
Push — develop ( 572bc7...60d03e )
by Zack
25:22 queued 04:21
created
PHPCompatibility/Sniffs/Classes/ForbiddenAbstractPrivateMethodsSniff.php 4 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -47,7 +47,7 @@
 block discarded – undo
47 47
      *
48 48
      * @since 9.2.0
49 49
      *
50
-     * @return array
50
+     * @return integer[]
51 51
      */
52 52
     public function register()
53 53
     {
Please login to merge, or discard this patch.
Indentation   +53 added lines, -53 removed lines patch added patch discarded remove patch
@@ -29,62 +29,62 @@
 block discarded – undo
29 29
 class ForbiddenAbstractPrivateMethodsSniff extends Sniff
30 30
 {
31 31
 
32
-    /**
33
-     * Valid scopes to check for abstract private methods.
34
-     *
35
-     * @since 9.2.0
36
-     *
37
-     * @var array
38
-     */
39
-    public $ooScopeTokens = array(
40
-        'T_CLASS'      => true,
41
-        'T_TRAIT'      => true,
42
-        'T_ANON_CLASS' => true,
43
-    );
32
+	/**
33
+	 * Valid scopes to check for abstract private methods.
34
+	 *
35
+	 * @since 9.2.0
36
+	 *
37
+	 * @var array
38
+	 */
39
+	public $ooScopeTokens = array(
40
+		'T_CLASS'      => true,
41
+		'T_TRAIT'      => true,
42
+		'T_ANON_CLASS' => true,
43
+	);
44 44
 
45
-    /**
46
-     * Returns an array of tokens this test wants to listen for.
47
-     *
48
-     * @since 9.2.0
49
-     *
50
-     * @return array
51
-     */
52
-    public function register()
53
-    {
54
-        return array(\T_FUNCTION);
55
-    }
45
+	/**
46
+	 * Returns an array of tokens this test wants to listen for.
47
+	 *
48
+	 * @since 9.2.0
49
+	 *
50
+	 * @return array
51
+	 */
52
+	public function register()
53
+	{
54
+		return array(\T_FUNCTION);
55
+	}
56 56
 
57
-    /**
58
-     * Processes this test, when one of its tokens is encountered.
59
-     *
60
-     * @since 9.2.0
61
-     *
62
-     * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned.
63
-     * @param int                   $stackPtr  The position of the current token
64
-     *                                         in the stack passed in $tokens.
65
-     *
66
-     * @return void
67
-     */
68
-    public function process(File $phpcsFile, $stackPtr)
69
-    {
70
-        if ($this->supportsAbove('5.1') === false) {
71
-            return;
72
-        }
57
+	/**
58
+	 * Processes this test, when one of its tokens is encountered.
59
+	 *
60
+	 * @since 9.2.0
61
+	 *
62
+	 * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned.
63
+	 * @param int                   $stackPtr  The position of the current token
64
+	 *                                         in the stack passed in $tokens.
65
+	 *
66
+	 * @return void
67
+	 */
68
+	public function process(File $phpcsFile, $stackPtr)
69
+	{
70
+		if ($this->supportsAbove('5.1') === false) {
71
+			return;
72
+		}
73 73
 
74
-        if ($this->validDirectScope($phpcsFile, $stackPtr, $this->ooScopeTokens) === false) {
75
-            // Function, not method.
76
-            return;
77
-        }
74
+		if ($this->validDirectScope($phpcsFile, $stackPtr, $this->ooScopeTokens) === false) {
75
+			// Function, not method.
76
+			return;
77
+		}
78 78
 
79
-        $properties = $phpcsFile->getMethodProperties($stackPtr);
80
-        if ($properties['scope'] !== 'private' || $properties['is_abstract'] !== true) {
81
-            return;
82
-        }
79
+		$properties = $phpcsFile->getMethodProperties($stackPtr);
80
+		if ($properties['scope'] !== 'private' || $properties['is_abstract'] !== true) {
81
+			return;
82
+		}
83 83
 
84
-        $phpcsFile->addError(
85
-            'Abstract methods cannot be declared as private since PHP 5.1',
86
-            $stackPtr,
87
-            'Found'
88
-        );
89
-    }
84
+		$phpcsFile->addError(
85
+			'Abstract methods cannot be declared as private since PHP 5.1',
86
+			$stackPtr,
87
+			'Found'
88
+		);
89
+	}
90 90
 }
Please login to merge, or discard this patch.
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -51,7 +51,7 @@  discard block
 block discarded – undo
51 51
      */
52 52
     public function register()
53 53
     {
54
-        return array(\T_FUNCTION);
54
+        return array( \T_FUNCTION );
55 55
     }
56 56
 
57 57
     /**
@@ -65,19 +65,19 @@  discard block
 block discarded – undo
65 65
      *
66 66
      * @return void
67 67
      */
68
-    public function process(File $phpcsFile, $stackPtr)
68
+    public function process( File $phpcsFile, $stackPtr )
69 69
     {
70
-        if ($this->supportsAbove('5.1') === false) {
70
+        if ( $this->supportsAbove( '5.1' ) === false ) {
71 71
             return;
72 72
         }
73 73
 
74
-        if ($this->validDirectScope($phpcsFile, $stackPtr, $this->ooScopeTokens) === false) {
74
+        if ( $this->validDirectScope( $phpcsFile, $stackPtr, $this->ooScopeTokens ) === false ) {
75 75
             // Function, not method.
76 76
             return;
77 77
         }
78 78
 
79
-        $properties = $phpcsFile->getMethodProperties($stackPtr);
80
-        if ($properties['scope'] !== 'private' || $properties['is_abstract'] !== true) {
79
+        $properties = $phpcsFile->getMethodProperties( $stackPtr );
80
+        if ( $properties[ 'scope' ] !== 'private' || $properties[ 'is_abstract' ] !== true ) {
81 81
             return;
82 82
         }
83 83
 
Please login to merge, or discard this patch.
Braces   +3 added lines, -6 removed lines patch added patch discarded remove patch
@@ -26,8 +26,7 @@  discard block
 block discarded – undo
26 26
  *
27 27
  * @since 9.2.0
28 28
  */
29
-class ForbiddenAbstractPrivateMethodsSniff extends Sniff
30
-{
29
+class ForbiddenAbstractPrivateMethodsSniff extends Sniff {
31 30
 
32 31
     /**
33 32
      * Valid scopes to check for abstract private methods.
@@ -49,8 +48,7 @@  discard block
 block discarded – undo
49 48
      *
50 49
      * @return array
51 50
      */
52
-    public function register()
53
-    {
51
+    public function register() {
54 52
         return array(\T_FUNCTION);
55 53
     }
56 54
 
@@ -65,8 +63,7 @@  discard block
 block discarded – undo
65 63
      *
66 64
      * @return void
67 65
      */
68
-    public function process(File $phpcsFile, $stackPtr)
69
-    {
66
+    public function process(File $phpcsFile, $stackPtr) {
70 67
         if ($this->supportsAbove('5.1') === false) {
71 68
             return;
72 69
         }
Please login to merge, or discard this patch.
PHPCompatibility/Sniffs/Classes/RemovedOrphanedParentSniff.php 4 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -45,7 +45,7 @@
 block discarded – undo
45 45
      *
46 46
      * @since 9.2.0
47 47
      *
48
-     * @return array
48
+     * @return string[]
49 49
      */
50 50
     public function register()
51 51
     {
Please login to merge, or discard this patch.
Indentation   +72 added lines, -72 removed lines patch added patch discarded remove patch
@@ -28,88 +28,88 @@
 block discarded – undo
28 28
 class RemovedOrphanedParentSniff extends Sniff
29 29
 {
30 30
 
31
-    /**
32
-     * Class scopes to check the class declaration.
33
-     *
34
-     * @since 9.2.0
35
-     *
36
-     * @var array
37
-     */
38
-    public $classScopeTokens = array(
39
-        'T_CLASS'      => true,
40
-        'T_ANON_CLASS' => true,
41
-    );
31
+	/**
32
+	 * Class scopes to check the class declaration.
33
+	 *
34
+	 * @since 9.2.0
35
+	 *
36
+	 * @var array
37
+	 */
38
+	public $classScopeTokens = array(
39
+		'T_CLASS'      => true,
40
+		'T_ANON_CLASS' => true,
41
+	);
42 42
 
43
-    /**
44
-     * Returns an array of tokens this test wants to listen for.
45
-     *
46
-     * @since 9.2.0
47
-     *
48
-     * @return array
49
-     */
50
-    public function register()
51
-    {
52
-        return array(\T_PARENT);
53
-    }
43
+	/**
44
+	 * Returns an array of tokens this test wants to listen for.
45
+	 *
46
+	 * @since 9.2.0
47
+	 *
48
+	 * @return array
49
+	 */
50
+	public function register()
51
+	{
52
+		return array(\T_PARENT);
53
+	}
54 54
 
55
-    /**
56
-     * Processes this test, when one of its tokens is encountered.
57
-     *
58
-     * @since 9.2.0
59
-     *
60
-     * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned.
61
-     * @param int                   $stackPtr  The position of the current token
62
-     *                                         in the stack passed in $tokens.
63
-     *
64
-     * @return void
65
-     */
66
-    public function process(File $phpcsFile, $stackPtr)
67
-    {
68
-        if ($this->supportsAbove('7.4') === false) {
69
-            return;
70
-        }
55
+	/**
56
+	 * Processes this test, when one of its tokens is encountered.
57
+	 *
58
+	 * @since 9.2.0
59
+	 *
60
+	 * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned.
61
+	 * @param int                   $stackPtr  The position of the current token
62
+	 *                                         in the stack passed in $tokens.
63
+	 *
64
+	 * @return void
65
+	 */
66
+	public function process(File $phpcsFile, $stackPtr)
67
+	{
68
+		if ($this->supportsAbove('7.4') === false) {
69
+			return;
70
+		}
71 71
 
72
-        $tokens = $phpcsFile->getTokens();
72
+		$tokens = $phpcsFile->getTokens();
73 73
 
74
-        if (empty($tokens[$stackPtr]['conditions']) === true) {
75
-            // Use within the global namespace. Not our concern.
76
-            return;
77
-        }
74
+		if (empty($tokens[$stackPtr]['conditions']) === true) {
75
+			// Use within the global namespace. Not our concern.
76
+			return;
77
+		}
78 78
 
79
-        /*
79
+		/*
80 80
          * Find the class within which this parent keyword is used.
81 81
          */
82
-        $conditions = $tokens[$stackPtr]['conditions'];
83
-        $conditions = array_reverse($conditions, true);
84
-        $classPtr   = false;
82
+		$conditions = $tokens[$stackPtr]['conditions'];
83
+		$conditions = array_reverse($conditions, true);
84
+		$classPtr   = false;
85 85
 
86
-        foreach ($conditions as $ptr => $type) {
87
-            if (isset($this->classScopeTokens[$tokens[$ptr]['type']])) {
88
-                $classPtr = $ptr;
89
-                break;
90
-            }
91
-        }
86
+		foreach ($conditions as $ptr => $type) {
87
+			if (isset($this->classScopeTokens[$tokens[$ptr]['type']])) {
88
+				$classPtr = $ptr;
89
+				break;
90
+			}
91
+		}
92 92
 
93
-        if ($classPtr === false) {
94
-            // Use outside of a class scope. Not our concern.
95
-            return;
96
-        }
93
+		if ($classPtr === false) {
94
+			// Use outside of a class scope. Not our concern.
95
+			return;
96
+		}
97 97
 
98
-        if (isset($tokens[$classPtr]['scope_opener']) === false) {
99
-            // No scope opener known. Probably a parse error.
100
-            return;
101
-        }
98
+		if (isset($tokens[$classPtr]['scope_opener']) === false) {
99
+			// No scope opener known. Probably a parse error.
100
+			return;
101
+		}
102 102
 
103
-        $extends = $phpcsFile->findNext(\T_EXTENDS, ($classPtr + 1), $tokens[$classPtr]['scope_opener']);
104
-        if ($extends !== false) {
105
-            // Class has a parent.
106
-            return;
107
-        }
103
+		$extends = $phpcsFile->findNext(\T_EXTENDS, ($classPtr + 1), $tokens[$classPtr]['scope_opener']);
104
+		if ($extends !== false) {
105
+			// Class has a parent.
106
+			return;
107
+		}
108 108
 
109
-        $phpcsFile->addError(
110
-            'Using "parent" inside a class without parent is deprecated since PHP 7.4',
111
-            $stackPtr,
112
-            'Deprecated'
113
-        );
114
-    }
109
+		$phpcsFile->addError(
110
+			'Using "parent" inside a class without parent is deprecated since PHP 7.4',
111
+			$stackPtr,
112
+			'Deprecated'
113
+		);
114
+	}
115 115
 }
Please login to merge, or discard this patch.
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -49,7 +49,7 @@  discard block
 block discarded – undo
49 49
      */
50 50
     public function register()
51 51
     {
52
-        return array(\T_PARENT);
52
+        return array( \T_PARENT );
53 53
     }
54 54
 
55 55
     /**
@@ -63,15 +63,15 @@  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
-        if ($this->supportsAbove('7.4') === false) {
68
+        if ( $this->supportsAbove( '7.4' ) === false ) {
69 69
             return;
70 70
         }
71 71
 
72 72
         $tokens = $phpcsFile->getTokens();
73 73
 
74
-        if (empty($tokens[$stackPtr]['conditions']) === true) {
74
+        if ( empty( $tokens[ $stackPtr ][ 'conditions' ] ) === true ) {
75 75
             // Use within the global namespace. Not our concern.
76 76
             return;
77 77
         }
@@ -79,29 +79,29 @@  discard block
 block discarded – undo
79 79
         /*
80 80
          * Find the class within which this parent keyword is used.
81 81
          */
82
-        $conditions = $tokens[$stackPtr]['conditions'];
83
-        $conditions = array_reverse($conditions, true);
82
+        $conditions = $tokens[ $stackPtr ][ 'conditions' ];
83
+        $conditions = array_reverse( $conditions, true );
84 84
         $classPtr   = false;
85 85
 
86
-        foreach ($conditions as $ptr => $type) {
87
-            if (isset($this->classScopeTokens[$tokens[$ptr]['type']])) {
86
+        foreach ( $conditions as $ptr => $type ) {
87
+            if ( isset( $this->classScopeTokens[ $tokens[ $ptr ][ 'type' ] ] ) ) {
88 88
                 $classPtr = $ptr;
89 89
                 break;
90 90
             }
91 91
         }
92 92
 
93
-        if ($classPtr === false) {
93
+        if ( $classPtr === false ) {
94 94
             // Use outside of a class scope. Not our concern.
95 95
             return;
96 96
         }
97 97
 
98
-        if (isset($tokens[$classPtr]['scope_opener']) === false) {
98
+        if ( isset( $tokens[ $classPtr ][ 'scope_opener' ] ) === false ) {
99 99
             // No scope opener known. Probably a parse error.
100 100
             return;
101 101
         }
102 102
 
103
-        $extends = $phpcsFile->findNext(\T_EXTENDS, ($classPtr + 1), $tokens[$classPtr]['scope_opener']);
104
-        if ($extends !== false) {
103
+        $extends = $phpcsFile->findNext( \T_EXTENDS, ( $classPtr + 1 ), $tokens[ $classPtr ][ 'scope_opener' ] );
104
+        if ( $extends !== false ) {
105 105
             // Class has a parent.
106 106
             return;
107 107
         }
Please login to merge, or discard this patch.
Braces   +3 added lines, -6 removed lines patch added patch discarded remove patch
@@ -25,8 +25,7 @@  discard block
 block discarded – undo
25 25
  *
26 26
  * @since 9.2.0
27 27
  */
28
-class RemovedOrphanedParentSniff extends Sniff
29
-{
28
+class RemovedOrphanedParentSniff extends Sniff {
30 29
 
31 30
     /**
32 31
      * Class scopes to check the class declaration.
@@ -47,8 +46,7 @@  discard block
 block discarded – undo
47 46
      *
48 47
      * @return array
49 48
      */
50
-    public function register()
51
-    {
49
+    public function register() {
52 50
         return array(\T_PARENT);
53 51
     }
54 52
 
@@ -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
         if ($this->supportsAbove('7.4') === false) {
69 66
             return;
70 67
         }
Please login to merge, or discard this patch.
PHPCompatibility/Sniffs/ControlStructures/NewExecutionDirectivesSniff.php 4 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -64,7 +64,7 @@  discard block
 block discarded – undo
64 64
     /**
65 65
      * Returns an array of tokens this test wants to listen for.
66 66
      *
67
-     * @return array
67
+     * @return integer[]
68 68
      */
69 69
     public function register()
70 70
     {
@@ -167,7 +167,7 @@  discard block
 block discarded – undo
167 167
     /**
168 168
      * Get an array of the non-PHP-version array keys used in a sub-array.
169 169
      *
170
-     * @return array
170
+     * @return string[]
171 171
      */
172 172
     protected function getNonVersionArrayKeys()
173 173
     {
Please login to merge, or discard this patch.
Indentation   +307 added lines, -307 removed lines patch added patch discarded remove patch
@@ -24,311 +24,311 @@
 block discarded – undo
24 24
 class NewExecutionDirectivesSniff extends AbstractNewFeatureSniff
25 25
 {
26 26
 
27
-    /**
28
-     * A list of new execution directives
29
-     *
30
-     * The array lists : version number with false (not present) or true (present).
31
-     * If the execution order is conditional, add the condition as a string to the version nr.
32
-     * If's sufficient to list the first version where the execution directive appears.
33
-     *
34
-     * @var array(string => array(string => int|string|null))
35
-     */
36
-    protected $newDirectives = array(
37
-        'ticks' => array(
38
-            '3.1' => false,
39
-            '4.0' => true,
40
-            'valid_value_callback' => 'isNumeric',
41
-        ),
42
-        'encoding' => array(
43
-            '5.2' => false,
44
-            '5.3' => '--enable-zend-multibyte', // Directive ignored unless.
45
-            '5.4' => true,
46
-            'valid_value_callback' => 'validEncoding',
47
-        ),
48
-        'strict_types' => array(
49
-            '5.6' => false,
50
-            '7.0' => true,
51
-            'valid_values' => array(1),
52
-        ),
53
-    );
54
-
55
-
56
-    /**
57
-     * Tokens to ignore when trying to find the value for the directive.
58
-     *
59
-     * @var array
60
-     */
61
-    protected $ignoreTokens = array();
62
-
63
-
64
-    /**
65
-     * Returns an array of tokens this test wants to listen for.
66
-     *
67
-     * @return array
68
-     */
69
-    public function register()
70
-    {
71
-        $this->ignoreTokens           = Tokens::$emptyTokens;
72
-        $this->ignoreTokens[\T_EQUAL] = \T_EQUAL;
73
-
74
-        return array(\T_DECLARE);
75
-    }
76
-
77
-
78
-    /**
79
-     * Processes this test, when one of its tokens is encountered.
80
-     *
81
-     * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned.
82
-     * @param int                   $stackPtr  The position of the current token in
83
-     *                                         the stack passed in $tokens.
84
-     *
85
-     * @return void
86
-     */
87
-    public function process(File $phpcsFile, $stackPtr)
88
-    {
89
-        $tokens = $phpcsFile->getTokens();
90
-
91
-        if (isset($tokens[$stackPtr]['parenthesis_opener'], $tokens[$stackPtr]['parenthesis_closer']) === true) {
92
-            $openParenthesis  = $tokens[$stackPtr]['parenthesis_opener'];
93
-            $closeParenthesis = $tokens[$stackPtr]['parenthesis_closer'];
94
-        } else {
95
-            if (version_compare(PHPCSHelper::getVersion(), '2.3.4', '>=')) {
96
-                return;
97
-            }
98
-
99
-            // Deal with PHPCS 2.3.0-2.3.3 which do not yet set the parenthesis properly for declare statements.
100
-            $openParenthesis = $phpcsFile->findNext(\T_OPEN_PARENTHESIS, ($stackPtr + 1), null, false, null, true);
101
-            if ($openParenthesis === false || isset($tokens[$openParenthesis]['parenthesis_closer']) === false) {
102
-                return;
103
-            }
104
-            $closeParenthesis = $tokens[$openParenthesis]['parenthesis_closer'];
105
-        }
106
-
107
-        $directivePtr = $phpcsFile->findNext(\T_STRING, ($openParenthesis + 1), $closeParenthesis, false);
108
-        if ($directivePtr === false) {
109
-            return;
110
-        }
111
-
112
-        $directiveContent = $tokens[$directivePtr]['content'];
113
-
114
-        if (isset($this->newDirectives[$directiveContent]) === false) {
115
-            $error = 'Declare can only be used with the directives %s. Found: %s';
116
-            $data  = array(
117
-                implode(', ', array_keys($this->newDirectives)),
118
-                $directiveContent,
119
-            );
120
-
121
-            $phpcsFile->addError($error, $stackPtr, 'InvalidDirectiveFound', $data);
122
-
123
-        } else {
124
-            // Check for valid directive for version.
125
-            $itemInfo = array(
126
-                'name'   => $directiveContent,
127
-            );
128
-            $this->handleFeature($phpcsFile, $stackPtr, $itemInfo);
129
-
130
-            // Check for valid directive value.
131
-            $valuePtr = $phpcsFile->findNext($this->ignoreTokens, $directivePtr + 1, $closeParenthesis, true);
132
-            if ($valuePtr === false) {
133
-                return;
134
-            }
135
-
136
-            $this->addWarningOnInvalidValue($phpcsFile, $valuePtr, $directiveContent);
137
-        }
138
-    }
139
-
140
-
141
-    /**
142
-     * Determine whether an error/warning should be thrown for an item based on collected information.
143
-     *
144
-     * @param array $errorInfo Detail information about an item.
145
-     *
146
-     * @return bool
147
-     */
148
-    protected function shouldThrowError(array $errorInfo)
149
-    {
150
-        return ($errorInfo['not_in_version'] !== '' || $errorInfo['conditional_version'] !== '');
151
-    }
152
-
153
-
154
-    /**
155
-     * Get the relevant sub-array for a specific item from a multi-dimensional array.
156
-     *
157
-     * @param array $itemInfo Base information about the item.
158
-     *
159
-     * @return array Version and other information about the item.
160
-     */
161
-    public function getItemArray(array $itemInfo)
162
-    {
163
-        return $this->newDirectives[$itemInfo['name']];
164
-    }
165
-
166
-
167
-    /**
168
-     * Get an array of the non-PHP-version array keys used in a sub-array.
169
-     *
170
-     * @return array
171
-     */
172
-    protected function getNonVersionArrayKeys()
173
-    {
174
-        return array(
175
-            'valid_value_callback',
176
-            'valid_values',
177
-        );
178
-    }
179
-
180
-
181
-    /**
182
-     * Retrieve the relevant detail (version) information for use in an error message.
183
-     *
184
-     * @param array $itemArray Version and other information about the item.
185
-     * @param array $itemInfo  Base information about the item.
186
-     *
187
-     * @return array
188
-     */
189
-    public function getErrorInfo(array $itemArray, array $itemInfo)
190
-    {
191
-        $errorInfo                        = parent::getErrorInfo($itemArray, $itemInfo);
192
-        $errorInfo['conditional_version'] = '';
193
-        $errorInfo['condition']           = '';
194
-
195
-        $versionArray = $this->getVersionArray($itemArray);
196
-
197
-        if (empty($versionArray) === false) {
198
-            foreach ($versionArray as $version => $present) {
199
-                if (\is_string($present) === true && $this->supportsBelow($version) === true) {
200
-                    // We cannot test for compilation option (ok, except by scraping the output of phpinfo...).
201
-                    $errorInfo['conditional_version'] = $version;
202
-                    $errorInfo['condition']           = $present;
203
-                }
204
-            }
205
-        }
206
-
207
-        return $errorInfo;
208
-    }
209
-
210
-
211
-    /**
212
-     * Get the error message template for this sniff.
213
-     *
214
-     * @return string
215
-     */
216
-    protected function getErrorMsgTemplate()
217
-    {
218
-        return 'Directive ' . parent::getErrorMsgTemplate();
219
-    }
220
-
221
-
222
-    /**
223
-     * Generates the error or warning for this item.
224
-     *
225
-     * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned.
226
-     * @param int                   $stackPtr  The position of the relevant token in
227
-     *                                         the stack.
228
-     * @param array                 $itemInfo  Base information about the item.
229
-     * @param array                 $errorInfo Array with detail (version) information
230
-     *                                         relevant to the item.
231
-     *
232
-     * @return void
233
-     */
234
-    public function addError(File $phpcsFile, $stackPtr, array $itemInfo, array $errorInfo)
235
-    {
236
-        if ($errorInfo['not_in_version'] !== '') {
237
-            parent::addError($phpcsFile, $stackPtr, $itemInfo, $errorInfo);
238
-        } elseif ($errorInfo['conditional_version'] !== '') {
239
-            $error     = 'Directive %s is present in PHP version %s but will be disregarded unless PHP is compiled with %s';
240
-            $errorCode = $this->stringToErrorCode($itemInfo['name']) . 'WithConditionFound';
241
-            $data      = array(
242
-                $itemInfo['name'],
243
-                $errorInfo['conditional_version'],
244
-                $errorInfo['condition'],
245
-            );
246
-
247
-            $phpcsFile->addWarning($error, $stackPtr, $errorCode, $data);
248
-        }
249
-    }
250
-
251
-
252
-    /**
253
-     * Generates a error or warning for this sniff.
254
-     *
255
-     * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned.
256
-     * @param int                   $stackPtr  The position of the execution directive value
257
-     *                                         in the token array.
258
-     * @param string                $directive The directive.
259
-     *
260
-     * @return void
261
-     */
262
-    protected function addWarningOnInvalidValue(File $phpcsFile, $stackPtr, $directive)
263
-    {
264
-        $tokens = $phpcsFile->getTokens();
265
-
266
-        $value = $tokens[$stackPtr]['content'];
267
-        if (isset(Tokens::$stringTokens[$tokens[$stackPtr]['code']]) === true) {
268
-            $value = $this->stripQuotes($value);
269
-        }
270
-
271
-        $isError = false;
272
-        if (isset($this->newDirectives[$directive]['valid_values'])) {
273
-            if (\in_array($value, $this->newDirectives[$directive]['valid_values']) === false) {
274
-                $isError = true;
275
-            }
276
-        } elseif (isset($this->newDirectives[$directive]['valid_value_callback'])) {
277
-            $valid = \call_user_func(array($this, $this->newDirectives[$directive]['valid_value_callback']), $value);
278
-            if ($valid === false) {
279
-                $isError = true;
280
-            }
281
-        }
282
-
283
-        if ($isError === true) {
284
-            $error     = 'The execution directive %s does not seem to have a valid value. Please review. Found: %s';
285
-            $errorCode = $this->stringToErrorCode($directive) . 'InvalidValueFound';
286
-            $data      = array(
287
-                $directive,
288
-                $value,
289
-            );
290
-
291
-            $phpcsFile->addWarning($error, $stackPtr, $errorCode, $data);
292
-        }
293
-    }
294
-
295
-
296
-    /**
297
-     * Check whether a value is numeric.
298
-     *
299
-     * Callback function to test whether the value for an execution directive is valid.
300
-     *
301
-     * @param mixed $value The value to test.
302
-     *
303
-     * @return bool
304
-     */
305
-    protected function isNumeric($value)
306
-    {
307
-        return is_numeric($value);
308
-    }
309
-
310
-
311
-    /**
312
-     * Check whether a value is a valid encoding.
313
-     *
314
-     * Callback function to test whether the value for an execution directive is valid.
315
-     *
316
-     * @param mixed $value The value to test.
317
-     *
318
-     * @return bool
319
-     */
320
-    protected function validEncoding($value)
321
-    {
322
-        static $encodings;
323
-        if (isset($encodings) === false && function_exists('mb_list_encodings')) {
324
-            $encodings = mb_list_encodings();
325
-        }
326
-
327
-        if (empty($encodings) || \is_array($encodings) === false) {
328
-            // If we can't test the encoding, let it pass through.
329
-            return true;
330
-        }
331
-
332
-        return \in_array($value, $encodings, true);
333
-    }
27
+	/**
28
+	 * A list of new execution directives
29
+	 *
30
+	 * The array lists : version number with false (not present) or true (present).
31
+	 * If the execution order is conditional, add the condition as a string to the version nr.
32
+	 * If's sufficient to list the first version where the execution directive appears.
33
+	 *
34
+	 * @var array(string => array(string => int|string|null))
35
+	 */
36
+	protected $newDirectives = array(
37
+		'ticks' => array(
38
+			'3.1' => false,
39
+			'4.0' => true,
40
+			'valid_value_callback' => 'isNumeric',
41
+		),
42
+		'encoding' => array(
43
+			'5.2' => false,
44
+			'5.3' => '--enable-zend-multibyte', // Directive ignored unless.
45
+			'5.4' => true,
46
+			'valid_value_callback' => 'validEncoding',
47
+		),
48
+		'strict_types' => array(
49
+			'5.6' => false,
50
+			'7.0' => true,
51
+			'valid_values' => array(1),
52
+		),
53
+	);
54
+
55
+
56
+	/**
57
+	 * Tokens to ignore when trying to find the value for the directive.
58
+	 *
59
+	 * @var array
60
+	 */
61
+	protected $ignoreTokens = array();
62
+
63
+
64
+	/**
65
+	 * Returns an array of tokens this test wants to listen for.
66
+	 *
67
+	 * @return array
68
+	 */
69
+	public function register()
70
+	{
71
+		$this->ignoreTokens           = Tokens::$emptyTokens;
72
+		$this->ignoreTokens[\T_EQUAL] = \T_EQUAL;
73
+
74
+		return array(\T_DECLARE);
75
+	}
76
+
77
+
78
+	/**
79
+	 * Processes this test, when one of its tokens is encountered.
80
+	 *
81
+	 * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned.
82
+	 * @param int                   $stackPtr  The position of the current token in
83
+	 *                                         the stack passed in $tokens.
84
+	 *
85
+	 * @return void
86
+	 */
87
+	public function process(File $phpcsFile, $stackPtr)
88
+	{
89
+		$tokens = $phpcsFile->getTokens();
90
+
91
+		if (isset($tokens[$stackPtr]['parenthesis_opener'], $tokens[$stackPtr]['parenthesis_closer']) === true) {
92
+			$openParenthesis  = $tokens[$stackPtr]['parenthesis_opener'];
93
+			$closeParenthesis = $tokens[$stackPtr]['parenthesis_closer'];
94
+		} else {
95
+			if (version_compare(PHPCSHelper::getVersion(), '2.3.4', '>=')) {
96
+				return;
97
+			}
98
+
99
+			// Deal with PHPCS 2.3.0-2.3.3 which do not yet set the parenthesis properly for declare statements.
100
+			$openParenthesis = $phpcsFile->findNext(\T_OPEN_PARENTHESIS, ($stackPtr + 1), null, false, null, true);
101
+			if ($openParenthesis === false || isset($tokens[$openParenthesis]['parenthesis_closer']) === false) {
102
+				return;
103
+			}
104
+			$closeParenthesis = $tokens[$openParenthesis]['parenthesis_closer'];
105
+		}
106
+
107
+		$directivePtr = $phpcsFile->findNext(\T_STRING, ($openParenthesis + 1), $closeParenthesis, false);
108
+		if ($directivePtr === false) {
109
+			return;
110
+		}
111
+
112
+		$directiveContent = $tokens[$directivePtr]['content'];
113
+
114
+		if (isset($this->newDirectives[$directiveContent]) === false) {
115
+			$error = 'Declare can only be used with the directives %s. Found: %s';
116
+			$data  = array(
117
+				implode(', ', array_keys($this->newDirectives)),
118
+				$directiveContent,
119
+			);
120
+
121
+			$phpcsFile->addError($error, $stackPtr, 'InvalidDirectiveFound', $data);
122
+
123
+		} else {
124
+			// Check for valid directive for version.
125
+			$itemInfo = array(
126
+				'name'   => $directiveContent,
127
+			);
128
+			$this->handleFeature($phpcsFile, $stackPtr, $itemInfo);
129
+
130
+			// Check for valid directive value.
131
+			$valuePtr = $phpcsFile->findNext($this->ignoreTokens, $directivePtr + 1, $closeParenthesis, true);
132
+			if ($valuePtr === false) {
133
+				return;
134
+			}
135
+
136
+			$this->addWarningOnInvalidValue($phpcsFile, $valuePtr, $directiveContent);
137
+		}
138
+	}
139
+
140
+
141
+	/**
142
+	 * Determine whether an error/warning should be thrown for an item based on collected information.
143
+	 *
144
+	 * @param array $errorInfo Detail information about an item.
145
+	 *
146
+	 * @return bool
147
+	 */
148
+	protected function shouldThrowError(array $errorInfo)
149
+	{
150
+		return ($errorInfo['not_in_version'] !== '' || $errorInfo['conditional_version'] !== '');
151
+	}
152
+
153
+
154
+	/**
155
+	 * Get the relevant sub-array for a specific item from a multi-dimensional array.
156
+	 *
157
+	 * @param array $itemInfo Base information about the item.
158
+	 *
159
+	 * @return array Version and other information about the item.
160
+	 */
161
+	public function getItemArray(array $itemInfo)
162
+	{
163
+		return $this->newDirectives[$itemInfo['name']];
164
+	}
165
+
166
+
167
+	/**
168
+	 * Get an array of the non-PHP-version array keys used in a sub-array.
169
+	 *
170
+	 * @return array
171
+	 */
172
+	protected function getNonVersionArrayKeys()
173
+	{
174
+		return array(
175
+			'valid_value_callback',
176
+			'valid_values',
177
+		);
178
+	}
179
+
180
+
181
+	/**
182
+	 * Retrieve the relevant detail (version) information for use in an error message.
183
+	 *
184
+	 * @param array $itemArray Version and other information about the item.
185
+	 * @param array $itemInfo  Base information about the item.
186
+	 *
187
+	 * @return array
188
+	 */
189
+	public function getErrorInfo(array $itemArray, array $itemInfo)
190
+	{
191
+		$errorInfo                        = parent::getErrorInfo($itemArray, $itemInfo);
192
+		$errorInfo['conditional_version'] = '';
193
+		$errorInfo['condition']           = '';
194
+
195
+		$versionArray = $this->getVersionArray($itemArray);
196
+
197
+		if (empty($versionArray) === false) {
198
+			foreach ($versionArray as $version => $present) {
199
+				if (\is_string($present) === true && $this->supportsBelow($version) === true) {
200
+					// We cannot test for compilation option (ok, except by scraping the output of phpinfo...).
201
+					$errorInfo['conditional_version'] = $version;
202
+					$errorInfo['condition']           = $present;
203
+				}
204
+			}
205
+		}
206
+
207
+		return $errorInfo;
208
+	}
209
+
210
+
211
+	/**
212
+	 * Get the error message template for this sniff.
213
+	 *
214
+	 * @return string
215
+	 */
216
+	protected function getErrorMsgTemplate()
217
+	{
218
+		return 'Directive ' . parent::getErrorMsgTemplate();
219
+	}
220
+
221
+
222
+	/**
223
+	 * Generates the error or warning for this item.
224
+	 *
225
+	 * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned.
226
+	 * @param int                   $stackPtr  The position of the relevant token in
227
+	 *                                         the stack.
228
+	 * @param array                 $itemInfo  Base information about the item.
229
+	 * @param array                 $errorInfo Array with detail (version) information
230
+	 *                                         relevant to the item.
231
+	 *
232
+	 * @return void
233
+	 */
234
+	public function addError(File $phpcsFile, $stackPtr, array $itemInfo, array $errorInfo)
235
+	{
236
+		if ($errorInfo['not_in_version'] !== '') {
237
+			parent::addError($phpcsFile, $stackPtr, $itemInfo, $errorInfo);
238
+		} elseif ($errorInfo['conditional_version'] !== '') {
239
+			$error     = 'Directive %s is present in PHP version %s but will be disregarded unless PHP is compiled with %s';
240
+			$errorCode = $this->stringToErrorCode($itemInfo['name']) . 'WithConditionFound';
241
+			$data      = array(
242
+				$itemInfo['name'],
243
+				$errorInfo['conditional_version'],
244
+				$errorInfo['condition'],
245
+			);
246
+
247
+			$phpcsFile->addWarning($error, $stackPtr, $errorCode, $data);
248
+		}
249
+	}
250
+
251
+
252
+	/**
253
+	 * Generates a error or warning for this sniff.
254
+	 *
255
+	 * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned.
256
+	 * @param int                   $stackPtr  The position of the execution directive value
257
+	 *                                         in the token array.
258
+	 * @param string                $directive The directive.
259
+	 *
260
+	 * @return void
261
+	 */
262
+	protected function addWarningOnInvalidValue(File $phpcsFile, $stackPtr, $directive)
263
+	{
264
+		$tokens = $phpcsFile->getTokens();
265
+
266
+		$value = $tokens[$stackPtr]['content'];
267
+		if (isset(Tokens::$stringTokens[$tokens[$stackPtr]['code']]) === true) {
268
+			$value = $this->stripQuotes($value);
269
+		}
270
+
271
+		$isError = false;
272
+		if (isset($this->newDirectives[$directive]['valid_values'])) {
273
+			if (\in_array($value, $this->newDirectives[$directive]['valid_values']) === false) {
274
+				$isError = true;
275
+			}
276
+		} elseif (isset($this->newDirectives[$directive]['valid_value_callback'])) {
277
+			$valid = \call_user_func(array($this, $this->newDirectives[$directive]['valid_value_callback']), $value);
278
+			if ($valid === false) {
279
+				$isError = true;
280
+			}
281
+		}
282
+
283
+		if ($isError === true) {
284
+			$error     = 'The execution directive %s does not seem to have a valid value. Please review. Found: %s';
285
+			$errorCode = $this->stringToErrorCode($directive) . 'InvalidValueFound';
286
+			$data      = array(
287
+				$directive,
288
+				$value,
289
+			);
290
+
291
+			$phpcsFile->addWarning($error, $stackPtr, $errorCode, $data);
292
+		}
293
+	}
294
+
295
+
296
+	/**
297
+	 * Check whether a value is numeric.
298
+	 *
299
+	 * Callback function to test whether the value for an execution directive is valid.
300
+	 *
301
+	 * @param mixed $value The value to test.
302
+	 *
303
+	 * @return bool
304
+	 */
305
+	protected function isNumeric($value)
306
+	{
307
+		return is_numeric($value);
308
+	}
309
+
310
+
311
+	/**
312
+	 * Check whether a value is a valid encoding.
313
+	 *
314
+	 * Callback function to test whether the value for an execution directive is valid.
315
+	 *
316
+	 * @param mixed $value The value to test.
317
+	 *
318
+	 * @return bool
319
+	 */
320
+	protected function validEncoding($value)
321
+	{
322
+		static $encodings;
323
+		if (isset($encodings) === false && function_exists('mb_list_encodings')) {
324
+			$encodings = mb_list_encodings();
325
+		}
326
+
327
+		if (empty($encodings) || \is_array($encodings) === false) {
328
+			// If we can't test the encoding, let it pass through.
329
+			return true;
330
+		}
331
+
332
+		return \in_array($value, $encodings, true);
333
+	}
334 334
 }
Please login to merge, or discard this patch.
Spacing   +62 added lines, -62 removed lines patch added patch discarded remove patch
@@ -48,7 +48,7 @@  discard block
 block discarded – undo
48 48
         'strict_types' => array(
49 49
             '5.6' => false,
50 50
             '7.0' => true,
51
-            'valid_values' => array(1),
51
+            'valid_values' => array( 1 ),
52 52
         ),
53 53
     );
54 54
 
@@ -69,9 +69,9 @@  discard block
 block discarded – undo
69 69
     public function register()
70 70
     {
71 71
         $this->ignoreTokens           = Tokens::$emptyTokens;
72
-        $this->ignoreTokens[\T_EQUAL] = \T_EQUAL;
72
+        $this->ignoreTokens[ \T_EQUAL ] = \T_EQUAL;
73 73
 
74
-        return array(\T_DECLARE);
74
+        return array( \T_DECLARE );
75 75
     }
76 76
 
77 77
 
@@ -84,56 +84,56 @@  discard block
 block discarded – undo
84 84
      *
85 85
      * @return void
86 86
      */
87
-    public function process(File $phpcsFile, $stackPtr)
87
+    public function process( File $phpcsFile, $stackPtr )
88 88
     {
89 89
         $tokens = $phpcsFile->getTokens();
90 90
 
91
-        if (isset($tokens[$stackPtr]['parenthesis_opener'], $tokens[$stackPtr]['parenthesis_closer']) === true) {
92
-            $openParenthesis  = $tokens[$stackPtr]['parenthesis_opener'];
93
-            $closeParenthesis = $tokens[$stackPtr]['parenthesis_closer'];
91
+        if ( isset( $tokens[ $stackPtr ][ 'parenthesis_opener' ], $tokens[ $stackPtr ][ 'parenthesis_closer' ] ) === true ) {
92
+            $openParenthesis  = $tokens[ $stackPtr ][ 'parenthesis_opener' ];
93
+            $closeParenthesis = $tokens[ $stackPtr ][ 'parenthesis_closer' ];
94 94
         } else {
95
-            if (version_compare(PHPCSHelper::getVersion(), '2.3.4', '>=')) {
95
+            if ( version_compare( PHPCSHelper::getVersion(), '2.3.4', '>=' ) ) {
96 96
                 return;
97 97
             }
98 98
 
99 99
             // Deal with PHPCS 2.3.0-2.3.3 which do not yet set the parenthesis properly for declare statements.
100
-            $openParenthesis = $phpcsFile->findNext(\T_OPEN_PARENTHESIS, ($stackPtr + 1), null, false, null, true);
101
-            if ($openParenthesis === false || isset($tokens[$openParenthesis]['parenthesis_closer']) === false) {
100
+            $openParenthesis = $phpcsFile->findNext( \T_OPEN_PARENTHESIS, ( $stackPtr + 1 ), null, false, null, true );
101
+            if ( $openParenthesis === false || isset( $tokens[ $openParenthesis ][ 'parenthesis_closer' ] ) === false ) {
102 102
                 return;
103 103
             }
104
-            $closeParenthesis = $tokens[$openParenthesis]['parenthesis_closer'];
104
+            $closeParenthesis = $tokens[ $openParenthesis ][ 'parenthesis_closer' ];
105 105
         }
106 106
 
107
-        $directivePtr = $phpcsFile->findNext(\T_STRING, ($openParenthesis + 1), $closeParenthesis, false);
108
-        if ($directivePtr === false) {
107
+        $directivePtr = $phpcsFile->findNext( \T_STRING, ( $openParenthesis + 1 ), $closeParenthesis, false );
108
+        if ( $directivePtr === false ) {
109 109
             return;
110 110
         }
111 111
 
112
-        $directiveContent = $tokens[$directivePtr]['content'];
112
+        $directiveContent = $tokens[ $directivePtr ][ 'content' ];
113 113
 
114
-        if (isset($this->newDirectives[$directiveContent]) === false) {
114
+        if ( isset( $this->newDirectives[ $directiveContent ] ) === false ) {
115 115
             $error = 'Declare can only be used with the directives %s. Found: %s';
116 116
             $data  = array(
117
-                implode(', ', array_keys($this->newDirectives)),
117
+                implode( ', ', array_keys( $this->newDirectives ) ),
118 118
                 $directiveContent,
119 119
             );
120 120
 
121
-            $phpcsFile->addError($error, $stackPtr, 'InvalidDirectiveFound', $data);
121
+            $phpcsFile->addError( $error, $stackPtr, 'InvalidDirectiveFound', $data );
122 122
 
123 123
         } else {
124 124
             // Check for valid directive for version.
125 125
             $itemInfo = array(
126 126
                 'name'   => $directiveContent,
127 127
             );
128
-            $this->handleFeature($phpcsFile, $stackPtr, $itemInfo);
128
+            $this->handleFeature( $phpcsFile, $stackPtr, $itemInfo );
129 129
 
130 130
             // Check for valid directive value.
131
-            $valuePtr = $phpcsFile->findNext($this->ignoreTokens, $directivePtr + 1, $closeParenthesis, true);
132
-            if ($valuePtr === false) {
131
+            $valuePtr = $phpcsFile->findNext( $this->ignoreTokens, $directivePtr + 1, $closeParenthesis, true );
132
+            if ( $valuePtr === false ) {
133 133
                 return;
134 134
             }
135 135
 
136
-            $this->addWarningOnInvalidValue($phpcsFile, $valuePtr, $directiveContent);
136
+            $this->addWarningOnInvalidValue( $phpcsFile, $valuePtr, $directiveContent );
137 137
         }
138 138
     }
139 139
 
@@ -145,9 +145,9 @@  discard block
 block discarded – undo
145 145
      *
146 146
      * @return bool
147 147
      */
148
-    protected function shouldThrowError(array $errorInfo)
148
+    protected function shouldThrowError( array $errorInfo )
149 149
     {
150
-        return ($errorInfo['not_in_version'] !== '' || $errorInfo['conditional_version'] !== '');
150
+        return ( $errorInfo[ 'not_in_version' ] !== '' || $errorInfo[ 'conditional_version' ] !== '' );
151 151
     }
152 152
 
153 153
 
@@ -158,9 +158,9 @@  discard block
 block discarded – undo
158 158
      *
159 159
      * @return array Version and other information about the item.
160 160
      */
161
-    public function getItemArray(array $itemInfo)
161
+    public function getItemArray( array $itemInfo )
162 162
     {
163
-        return $this->newDirectives[$itemInfo['name']];
163
+        return $this->newDirectives[ $itemInfo[ 'name' ] ];
164 164
     }
165 165
 
166 166
 
@@ -186,20 +186,20 @@  discard block
 block discarded – undo
186 186
      *
187 187
      * @return array
188 188
      */
189
-    public function getErrorInfo(array $itemArray, array $itemInfo)
189
+    public function getErrorInfo( array $itemArray, array $itemInfo )
190 190
     {
191
-        $errorInfo                        = parent::getErrorInfo($itemArray, $itemInfo);
192
-        $errorInfo['conditional_version'] = '';
193
-        $errorInfo['condition']           = '';
191
+        $errorInfo                        = parent::getErrorInfo( $itemArray, $itemInfo );
192
+        $errorInfo[ 'conditional_version' ] = '';
193
+        $errorInfo[ 'condition' ]           = '';
194 194
 
195
-        $versionArray = $this->getVersionArray($itemArray);
195
+        $versionArray = $this->getVersionArray( $itemArray );
196 196
 
197
-        if (empty($versionArray) === false) {
198
-            foreach ($versionArray as $version => $present) {
199
-                if (\is_string($present) === true && $this->supportsBelow($version) === true) {
197
+        if ( empty( $versionArray ) === false ) {
198
+            foreach ( $versionArray as $version => $present ) {
199
+                if ( \is_string( $present ) === true && $this->supportsBelow( $version ) === true ) {
200 200
                     // We cannot test for compilation option (ok, except by scraping the output of phpinfo...).
201
-                    $errorInfo['conditional_version'] = $version;
202
-                    $errorInfo['condition']           = $present;
201
+                    $errorInfo[ 'conditional_version' ] = $version;
202
+                    $errorInfo[ 'condition' ]           = $present;
203 203
                 }
204 204
             }
205 205
         }
@@ -231,20 +231,20 @@  discard block
 block discarded – undo
231 231
      *
232 232
      * @return void
233 233
      */
234
-    public function addError(File $phpcsFile, $stackPtr, array $itemInfo, array $errorInfo)
234
+    public function addError( File $phpcsFile, $stackPtr, array $itemInfo, array $errorInfo )
235 235
     {
236
-        if ($errorInfo['not_in_version'] !== '') {
237
-            parent::addError($phpcsFile, $stackPtr, $itemInfo, $errorInfo);
238
-        } elseif ($errorInfo['conditional_version'] !== '') {
236
+        if ( $errorInfo[ 'not_in_version' ] !== '' ) {
237
+            parent::addError( $phpcsFile, $stackPtr, $itemInfo, $errorInfo );
238
+        } elseif ( $errorInfo[ 'conditional_version' ] !== '' ) {
239 239
             $error     = 'Directive %s is present in PHP version %s but will be disregarded unless PHP is compiled with %s';
240
-            $errorCode = $this->stringToErrorCode($itemInfo['name']) . 'WithConditionFound';
240
+            $errorCode = $this->stringToErrorCode( $itemInfo[ 'name' ] ) . 'WithConditionFound';
241 241
             $data      = array(
242
-                $itemInfo['name'],
243
-                $errorInfo['conditional_version'],
244
-                $errorInfo['condition'],
242
+                $itemInfo[ 'name' ],
243
+                $errorInfo[ 'conditional_version' ],
244
+                $errorInfo[ 'condition' ],
245 245
             );
246 246
 
247
-            $phpcsFile->addWarning($error, $stackPtr, $errorCode, $data);
247
+            $phpcsFile->addWarning( $error, $stackPtr, $errorCode, $data );
248 248
         }
249 249
     }
250 250
 
@@ -259,36 +259,36 @@  discard block
 block discarded – undo
259 259
      *
260 260
      * @return void
261 261
      */
262
-    protected function addWarningOnInvalidValue(File $phpcsFile, $stackPtr, $directive)
262
+    protected function addWarningOnInvalidValue( File $phpcsFile, $stackPtr, $directive )
263 263
     {
264 264
         $tokens = $phpcsFile->getTokens();
265 265
 
266
-        $value = $tokens[$stackPtr]['content'];
267
-        if (isset(Tokens::$stringTokens[$tokens[$stackPtr]['code']]) === true) {
268
-            $value = $this->stripQuotes($value);
266
+        $value = $tokens[ $stackPtr ][ 'content' ];
267
+        if ( isset( Tokens::$stringTokens[ $tokens[ $stackPtr ][ 'code' ] ] ) === true ) {
268
+            $value = $this->stripQuotes( $value );
269 269
         }
270 270
 
271 271
         $isError = false;
272
-        if (isset($this->newDirectives[$directive]['valid_values'])) {
273
-            if (\in_array($value, $this->newDirectives[$directive]['valid_values']) === false) {
272
+        if ( isset( $this->newDirectives[ $directive ][ 'valid_values' ] ) ) {
273
+            if ( \in_array( $value, $this->newDirectives[ $directive ][ 'valid_values' ] ) === false ) {
274 274
                 $isError = true;
275 275
             }
276
-        } elseif (isset($this->newDirectives[$directive]['valid_value_callback'])) {
277
-            $valid = \call_user_func(array($this, $this->newDirectives[$directive]['valid_value_callback']), $value);
278
-            if ($valid === false) {
276
+        } elseif ( isset( $this->newDirectives[ $directive ][ 'valid_value_callback' ] ) ) {
277
+            $valid = \call_user_func( array( $this, $this->newDirectives[ $directive ][ 'valid_value_callback' ] ), $value );
278
+            if ( $valid === false ) {
279 279
                 $isError = true;
280 280
             }
281 281
         }
282 282
 
283
-        if ($isError === true) {
283
+        if ( $isError === true ) {
284 284
             $error     = 'The execution directive %s does not seem to have a valid value. Please review. Found: %s';
285
-            $errorCode = $this->stringToErrorCode($directive) . 'InvalidValueFound';
285
+            $errorCode = $this->stringToErrorCode( $directive ) . 'InvalidValueFound';
286 286
             $data      = array(
287 287
                 $directive,
288 288
                 $value,
289 289
             );
290 290
 
291
-            $phpcsFile->addWarning($error, $stackPtr, $errorCode, $data);
291
+            $phpcsFile->addWarning( $error, $stackPtr, $errorCode, $data );
292 292
         }
293 293
     }
294 294
 
@@ -302,9 +302,9 @@  discard block
 block discarded – undo
302 302
      *
303 303
      * @return bool
304 304
      */
305
-    protected function isNumeric($value)
305
+    protected function isNumeric( $value )
306 306
     {
307
-        return is_numeric($value);
307
+        return is_numeric( $value );
308 308
     }
309 309
 
310 310
 
@@ -317,18 +317,18 @@  discard block
 block discarded – undo
317 317
      *
318 318
      * @return bool
319 319
      */
320
-    protected function validEncoding($value)
320
+    protected function validEncoding( $value )
321 321
     {
322 322
         static $encodings;
323
-        if (isset($encodings) === false && function_exists('mb_list_encodings')) {
323
+        if ( isset( $encodings ) === false && function_exists( 'mb_list_encodings' ) ) {
324 324
             $encodings = mb_list_encodings();
325 325
         }
326 326
 
327
-        if (empty($encodings) || \is_array($encodings) === false) {
327
+        if ( empty( $encodings ) || \is_array( $encodings ) === false ) {
328 328
             // If we can't test the encoding, let it pass through.
329 329
             return true;
330 330
         }
331 331
 
332
-        return \in_array($value, $encodings, true);
332
+        return \in_array( $value, $encodings, true );
333 333
     }
334 334
 }
Please login to merge, or discard this patch.
Braces   +12 added lines, -24 removed lines patch added patch discarded remove patch
@@ -21,8 +21,7 @@  discard block
 block discarded – undo
21 21
  * @package  PHPCompatibility
22 22
  * @author   Juliette Reinders Folmer <[email protected]>
23 23
  */
24
-class NewExecutionDirectivesSniff extends AbstractNewFeatureSniff
25
-{
24
+class NewExecutionDirectivesSniff extends AbstractNewFeatureSniff {
26 25
 
27 26
     /**
28 27
      * A list of new execution directives
@@ -66,8 +65,7 @@  discard block
 block discarded – undo
66 65
      *
67 66
      * @return array
68 67
      */
69
-    public function register()
70
-    {
68
+    public function register() {
71 69
         $this->ignoreTokens           = Tokens::$emptyTokens;
72 70
         $this->ignoreTokens[\T_EQUAL] = \T_EQUAL;
73 71
 
@@ -84,8 +82,7 @@  discard block
 block discarded – undo
84 82
      *
85 83
      * @return void
86 84
      */
87
-    public function process(File $phpcsFile, $stackPtr)
88
-    {
85
+    public function process(File $phpcsFile, $stackPtr) {
89 86
         $tokens = $phpcsFile->getTokens();
90 87
 
91 88
         if (isset($tokens[$stackPtr]['parenthesis_opener'], $tokens[$stackPtr]['parenthesis_closer']) === true) {
@@ -145,8 +142,7 @@  discard block
 block discarded – undo
145 142
      *
146 143
      * @return bool
147 144
      */
148
-    protected function shouldThrowError(array $errorInfo)
149
-    {
145
+    protected function shouldThrowError(array $errorInfo) {
150 146
         return ($errorInfo['not_in_version'] !== '' || $errorInfo['conditional_version'] !== '');
151 147
     }
152 148
 
@@ -158,8 +154,7 @@  discard block
 block discarded – undo
158 154
      *
159 155
      * @return array Version and other information about the item.
160 156
      */
161
-    public function getItemArray(array $itemInfo)
162
-    {
157
+    public function getItemArray(array $itemInfo) {
163 158
         return $this->newDirectives[$itemInfo['name']];
164 159
     }
165 160
 
@@ -169,8 +164,7 @@  discard block
 block discarded – undo
169 164
      *
170 165
      * @return array
171 166
      */
172
-    protected function getNonVersionArrayKeys()
173
-    {
167
+    protected function getNonVersionArrayKeys() {
174 168
         return array(
175 169
             'valid_value_callback',
176 170
             'valid_values',
@@ -186,8 +180,7 @@  discard block
 block discarded – undo
186 180
      *
187 181
      * @return array
188 182
      */
189
-    public function getErrorInfo(array $itemArray, array $itemInfo)
190
-    {
183
+    public function getErrorInfo(array $itemArray, array $itemInfo) {
191 184
         $errorInfo                        = parent::getErrorInfo($itemArray, $itemInfo);
192 185
         $errorInfo['conditional_version'] = '';
193 186
         $errorInfo['condition']           = '';
@@ -213,8 +206,7 @@  discard block
 block discarded – undo
213 206
      *
214 207
      * @return string
215 208
      */
216
-    protected function getErrorMsgTemplate()
217
-    {
209
+    protected function getErrorMsgTemplate() {
218 210
         return 'Directive ' . parent::getErrorMsgTemplate();
219 211
     }
220 212
 
@@ -231,8 +223,7 @@  discard block
 block discarded – undo
231 223
      *
232 224
      * @return void
233 225
      */
234
-    public function addError(File $phpcsFile, $stackPtr, array $itemInfo, array $errorInfo)
235
-    {
226
+    public function addError(File $phpcsFile, $stackPtr, array $itemInfo, array $errorInfo) {
236 227
         if ($errorInfo['not_in_version'] !== '') {
237 228
             parent::addError($phpcsFile, $stackPtr, $itemInfo, $errorInfo);
238 229
         } elseif ($errorInfo['conditional_version'] !== '') {
@@ -259,8 +250,7 @@  discard block
 block discarded – undo
259 250
      *
260 251
      * @return void
261 252
      */
262
-    protected function addWarningOnInvalidValue(File $phpcsFile, $stackPtr, $directive)
263
-    {
253
+    protected function addWarningOnInvalidValue(File $phpcsFile, $stackPtr, $directive) {
264 254
         $tokens = $phpcsFile->getTokens();
265 255
 
266 256
         $value = $tokens[$stackPtr]['content'];
@@ -302,8 +292,7 @@  discard block
 block discarded – undo
302 292
      *
303 293
      * @return bool
304 294
      */
305
-    protected function isNumeric($value)
306
-    {
295
+    protected function isNumeric($value) {
307 296
         return is_numeric($value);
308 297
     }
309 298
 
@@ -317,8 +306,7 @@  discard block
 block discarded – undo
317 306
      *
318 307
      * @return bool
319 308
      */
320
-    protected function validEncoding($value)
321
-    {
309
+    protected function validEncoding($value) {
322 310
         static $encodings;
323 311
         if (isset($encodings) === false && function_exists('mb_list_encodings')) {
324 312
             $encodings = mb_list_encodings();
Please login to merge, or discard this patch.
PHPCompatibility/Sniffs/FunctionDeclarations/NewClosureSniff.php 4 patches
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.
Indentation   +185 added lines, -185 removed lines patch added patch discarded remove patch
@@ -28,210 +28,210 @@
 block discarded – undo
28 28
  */
29 29
 class NewClosureSniff extends Sniff
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(\T_CLOSURE);
39
-    }
40
-
41
-    /**
42
-     * Processes this test, when one of its tokens is encountered.
43
-     *
44
-     * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned.
45
-     * @param int                   $stackPtr  The position of the current token
46
-     *                                         in the stack passed in $tokens.
47
-     *
48
-     * @return void
49
-     */
50
-    public function process(File $phpcsFile, $stackPtr)
51
-    {
52
-        if ($this->supportsBelow('5.2')) {
53
-            $phpcsFile->addError(
54
-                'Closures / anonymous functions are not available in PHP 5.2 or earlier',
55
-                $stackPtr,
56
-                'Found'
57
-            );
58
-        }
59
-
60
-        /*
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(\T_CLOSURE);
39
+	}
40
+
41
+	/**
42
+	 * Processes this test, when one of its tokens is encountered.
43
+	 *
44
+	 * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned.
45
+	 * @param int                   $stackPtr  The position of the current token
46
+	 *                                         in the stack passed in $tokens.
47
+	 *
48
+	 * @return void
49
+	 */
50
+	public function process(File $phpcsFile, $stackPtr)
51
+	{
52
+		if ($this->supportsBelow('5.2')) {
53
+			$phpcsFile->addError(
54
+				'Closures / anonymous functions are not available in PHP 5.2 or earlier',
55
+				$stackPtr,
56
+				'Found'
57
+			);
58
+		}
59
+
60
+		/*
61 61
          * Closures can only be declared as static since PHP 5.4.
62 62
          */
63
-        $isStatic = $this->isClosureStatic($phpcsFile, $stackPtr);
64
-        if ($this->supportsBelow('5.3') && $isStatic === true) {
65
-            $phpcsFile->addError(
66
-                'Closures / anonymous functions could not be declared as static in PHP 5.3 or earlier',
67
-                $stackPtr,
68
-                'StaticFound'
69
-            );
70
-        }
71
-
72
-        $tokens = $phpcsFile->getTokens();
73
-
74
-        if (isset($tokens[$stackPtr]['scope_opener'], $tokens[$stackPtr]['scope_closer']) === false) {
75
-            // Live coding or parse error.
76
-            return;
77
-        }
78
-
79
-        $scopeStart = ($tokens[$stackPtr]['scope_opener'] + 1);
80
-        $scopeEnd   = $tokens[$stackPtr]['scope_closer'];
81
-        $usesThis   = $this->findThisUsageInClosure($phpcsFile, $scopeStart, $scopeEnd);
82
-
83
-        if ($this->supportsBelow('5.3')) {
84
-            /*
63
+		$isStatic = $this->isClosureStatic($phpcsFile, $stackPtr);
64
+		if ($this->supportsBelow('5.3') && $isStatic === true) {
65
+			$phpcsFile->addError(
66
+				'Closures / anonymous functions could not be declared as static in PHP 5.3 or earlier',
67
+				$stackPtr,
68
+				'StaticFound'
69
+			);
70
+		}
71
+
72
+		$tokens = $phpcsFile->getTokens();
73
+
74
+		if (isset($tokens[$stackPtr]['scope_opener'], $tokens[$stackPtr]['scope_closer']) === false) {
75
+			// Live coding or parse error.
76
+			return;
77
+		}
78
+
79
+		$scopeStart = ($tokens[$stackPtr]['scope_opener'] + 1);
80
+		$scopeEnd   = $tokens[$stackPtr]['scope_closer'];
81
+		$usesThis   = $this->findThisUsageInClosure($phpcsFile, $scopeStart, $scopeEnd);
82
+
83
+		if ($this->supportsBelow('5.3')) {
84
+			/*
85 85
              * Closures declared within classes only have access to $this since PHP 5.4.
86 86
              */
87
-            if ($usesThis !== false) {
88
-                $thisFound = $usesThis;
89
-                do {
90
-                    $phpcsFile->addError(
91
-                        'Closures / anonymous functions did not have access to $this in PHP 5.3 or earlier',
92
-                        $thisFound,
93
-                        'ThisFound'
94
-                    );
87
+			if ($usesThis !== false) {
88
+				$thisFound = $usesThis;
89
+				do {
90
+					$phpcsFile->addError(
91
+						'Closures / anonymous functions did not have access to $this in PHP 5.3 or earlier',
92
+						$thisFound,
93
+						'ThisFound'
94
+					);
95 95
 
96
-                    $thisFound = $this->findThisUsageInClosure($phpcsFile, ($thisFound + 1), $scopeEnd);
96
+					$thisFound = $this->findThisUsageInClosure($phpcsFile, ($thisFound + 1), $scopeEnd);
97 97
 
98
-                } while ($thisFound !== false);
99
-            }
98
+				} while ($thisFound !== false);
99
+			}
100 100
 
101
-            /*
101
+			/*
102 102
              * Closures declared within classes only have access to self/parent/static since PHP 5.4.
103 103
              */
104
-            $usesClassRef = $this->findClassRefUsageInClosure($phpcsFile, $scopeStart, $scopeEnd);
104
+			$usesClassRef = $this->findClassRefUsageInClosure($phpcsFile, $scopeStart, $scopeEnd);
105 105
 
106
-            if ($usesClassRef !== false) {
107
-                do {
108
-                    $phpcsFile->addError(
109
-                        'Closures / anonymous functions could not use "%s::" in PHP 5.3 or earlier',
110
-                        $usesClassRef,
111
-                        'ClassRefFound',
112
-                        array(strtolower($tokens[$usesClassRef]['content']))
113
-                    );
106
+			if ($usesClassRef !== false) {
107
+				do {
108
+					$phpcsFile->addError(
109
+						'Closures / anonymous functions could not use "%s::" in PHP 5.3 or earlier',
110
+						$usesClassRef,
111
+						'ClassRefFound',
112
+						array(strtolower($tokens[$usesClassRef]['content']))
113
+					);
114 114
 
115
-                    $usesClassRef = $this->findClassRefUsageInClosure($phpcsFile, ($usesClassRef + 1), $scopeEnd);
115
+					$usesClassRef = $this->findClassRefUsageInClosure($phpcsFile, ($usesClassRef + 1), $scopeEnd);
116 116
 
117
-                } while ($usesClassRef !== false);
118
-            }
119
-        }
117
+				} while ($usesClassRef !== false);
118
+			}
119
+		}
120 120
 
121
-        /*
121
+		/*
122 122
          * Check for correct usage.
123 123
          */
124
-        if ($this->supportsAbove('5.4') && $usesThis !== false) {
124
+		if ($this->supportsAbove('5.4') && $usesThis !== false) {
125 125
 
126
-            $thisFound = $usesThis;
126
+			$thisFound = $usesThis;
127 127
 
128
-            do {
129
-                /*
128
+			do {
129
+				/*
130 130
                  * Closures only have access to $this if not declared as static.
131 131
                  */
132
-                if ($isStatic === true) {
133
-                    $phpcsFile->addError(
134
-                        'Closures / anonymous functions declared as static do not have access to $this',
135
-                        $thisFound,
136
-                        'ThisFoundInStatic'
137
-                    );
138
-                }
139
-
140
-                /*
132
+				if ($isStatic === true) {
133
+					$phpcsFile->addError(
134
+						'Closures / anonymous functions declared as static do not have access to $this',
135
+						$thisFound,
136
+						'ThisFoundInStatic'
137
+					);
138
+				}
139
+
140
+				/*
141 141
                  * Closures only have access to $this if used within a class context.
142 142
                  */
143
-                elseif ($this->inClassScope($phpcsFile, $stackPtr, false) === false) {
144
-                    $phpcsFile->addWarning(
145
-                        'Closures / anonymous functions only have access to $this if used within a class or when bound to an object using bindTo(). Please verify.',
146
-                        $thisFound,
147
-                        'ThisFoundOutsideClass'
148
-                    );
149
-                }
150
-
151
-                $thisFound = $this->findThisUsageInClosure($phpcsFile, ($thisFound + 1), $scopeEnd);
152
-
153
-            } while ($thisFound !== false);
154
-        }
155
-
156
-        // Prevent double reporting for nested closures.
157
-        return $scopeEnd;
158
-    }
159
-
160
-
161
-    /**
162
-     * Check whether the closure is declared as static.
163
-     *
164
-     * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned.
165
-     * @param int                   $stackPtr  The position of the current token
166
-     *                                         in the stack passed in $tokens.
167
-     *
168
-     * @return bool
169
-     */
170
-    protected function isClosureStatic(File $phpcsFile, $stackPtr)
171
-    {
172
-        $tokens    = $phpcsFile->getTokens();
173
-        $prevToken = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($stackPtr - 1), null, true, null, true);
174
-
175
-        return ($prevToken !== false && $tokens[$prevToken]['code'] === \T_STATIC);
176
-    }
177
-
178
-
179
-    /**
180
-     * Check if the code within a closure uses the $this variable.
181
-     *
182
-     * @param \PHP_CodeSniffer_File $phpcsFile  The file being scanned.
183
-     * @param int                   $startToken The position within the closure to continue searching from.
184
-     * @param int                   $endToken   The closure scope closer to stop searching at.
185
-     *
186
-     * @return int|false The stackPtr to the first $this usage if found or false if
187
-     *                   $this is not used.
188
-     */
189
-    protected function findThisUsageInClosure(File $phpcsFile, $startToken, $endToken)
190
-    {
191
-        // Make sure the $startToken is valid.
192
-        if ($startToken >= $endToken) {
193
-            return false;
194
-        }
195
-
196
-        return $phpcsFile->findNext(
197
-            \T_VARIABLE,
198
-            $startToken,
199
-            $endToken,
200
-            false,
201
-            '$this'
202
-        );
203
-    }
204
-
205
-    /**
206
-     * Check if the code within a closure uses "self/parent/static".
207
-     *
208
-     * @param \PHP_CodeSniffer_File $phpcsFile  The file being scanned.
209
-     * @param int                   $startToken The position within the closure to continue searching from.
210
-     * @param int                   $endToken   The closure scope closer to stop searching at.
211
-     *
212
-     * @return int|false The stackPtr to the first classRef usage if found or false if
213
-     *                   they are not used.
214
-     */
215
-    protected function findClassRefUsageInClosure(File $phpcsFile, $startToken, $endToken)
216
-    {
217
-        // Make sure the $startToken is valid.
218
-        if ($startToken >= $endToken) {
219
-            return false;
220
-        }
221
-
222
-        $tokens   = $phpcsFile->getTokens();
223
-        $classRef = $phpcsFile->findNext(array(\T_SELF, \T_PARENT, \T_STATIC), $startToken, $endToken);
224
-
225
-        if ($classRef === false || $tokens[$classRef]['code'] !== \T_STATIC) {
226
-            return $classRef;
227
-        }
228
-
229
-        // T_STATIC, make sure it is used as a class reference.
230
-        $next = $phpcsFile->findNext(Tokens::$emptyTokens, ($classRef + 1), $endToken, true);
231
-        if ($next === false || $tokens[$next]['code'] !== \T_DOUBLE_COLON) {
232
-            return false;
233
-        }
234
-
235
-        return $classRef;
236
-    }
143
+				elseif ($this->inClassScope($phpcsFile, $stackPtr, false) === false) {
144
+					$phpcsFile->addWarning(
145
+						'Closures / anonymous functions only have access to $this if used within a class or when bound to an object using bindTo(). Please verify.',
146
+						$thisFound,
147
+						'ThisFoundOutsideClass'
148
+					);
149
+				}
150
+
151
+				$thisFound = $this->findThisUsageInClosure($phpcsFile, ($thisFound + 1), $scopeEnd);
152
+
153
+			} while ($thisFound !== false);
154
+		}
155
+
156
+		// Prevent double reporting for nested closures.
157
+		return $scopeEnd;
158
+	}
159
+
160
+
161
+	/**
162
+	 * Check whether the closure is declared as static.
163
+	 *
164
+	 * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned.
165
+	 * @param int                   $stackPtr  The position of the current token
166
+	 *                                         in the stack passed in $tokens.
167
+	 *
168
+	 * @return bool
169
+	 */
170
+	protected function isClosureStatic(File $phpcsFile, $stackPtr)
171
+	{
172
+		$tokens    = $phpcsFile->getTokens();
173
+		$prevToken = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($stackPtr - 1), null, true, null, true);
174
+
175
+		return ($prevToken !== false && $tokens[$prevToken]['code'] === \T_STATIC);
176
+	}
177
+
178
+
179
+	/**
180
+	 * Check if the code within a closure uses the $this variable.
181
+	 *
182
+	 * @param \PHP_CodeSniffer_File $phpcsFile  The file being scanned.
183
+	 * @param int                   $startToken The position within the closure to continue searching from.
184
+	 * @param int                   $endToken   The closure scope closer to stop searching at.
185
+	 *
186
+	 * @return int|false The stackPtr to the first $this usage if found or false if
187
+	 *                   $this is not used.
188
+	 */
189
+	protected function findThisUsageInClosure(File $phpcsFile, $startToken, $endToken)
190
+	{
191
+		// Make sure the $startToken is valid.
192
+		if ($startToken >= $endToken) {
193
+			return false;
194
+		}
195
+
196
+		return $phpcsFile->findNext(
197
+			\T_VARIABLE,
198
+			$startToken,
199
+			$endToken,
200
+			false,
201
+			'$this'
202
+		);
203
+	}
204
+
205
+	/**
206
+	 * Check if the code within a closure uses "self/parent/static".
207
+	 *
208
+	 * @param \PHP_CodeSniffer_File $phpcsFile  The file being scanned.
209
+	 * @param int                   $startToken The position within the closure to continue searching from.
210
+	 * @param int                   $endToken   The closure scope closer to stop searching at.
211
+	 *
212
+	 * @return int|false The stackPtr to the first classRef usage if found or false if
213
+	 *                   they are not used.
214
+	 */
215
+	protected function findClassRefUsageInClosure(File $phpcsFile, $startToken, $endToken)
216
+	{
217
+		// Make sure the $startToken is valid.
218
+		if ($startToken >= $endToken) {
219
+			return false;
220
+		}
221
+
222
+		$tokens   = $phpcsFile->getTokens();
223
+		$classRef = $phpcsFile->findNext(array(\T_SELF, \T_PARENT, \T_STATIC), $startToken, $endToken);
224
+
225
+		if ($classRef === false || $tokens[$classRef]['code'] !== \T_STATIC) {
226
+			return $classRef;
227
+		}
228
+
229
+		// T_STATIC, make sure it is used as a class reference.
230
+		$next = $phpcsFile->findNext(Tokens::$emptyTokens, ($classRef + 1), $endToken, true);
231
+		if ($next === false || $tokens[$next]['code'] !== \T_DOUBLE_COLON) {
232
+			return false;
233
+		}
234
+
235
+		return $classRef;
236
+	}
237 237
 }
Please login to merge, or discard this patch.
Spacing   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -35,7 +35,7 @@  discard block
 block discarded – undo
35 35
      */
36 36
     public function register()
37 37
     {
38
-        return array(\T_CLOSURE);
38
+        return array( \T_CLOSURE );
39 39
     }
40 40
 
41 41
     /**
@@ -47,9 +47,9 @@  discard block
 block discarded – undo
47 47
      *
48 48
      * @return void
49 49
      */
50
-    public function process(File $phpcsFile, $stackPtr)
50
+    public function process( File $phpcsFile, $stackPtr )
51 51
     {
52
-        if ($this->supportsBelow('5.2')) {
52
+        if ( $this->supportsBelow( '5.2' ) ) {
53 53
             $phpcsFile->addError(
54 54
                 'Closures / anonymous functions are not available in PHP 5.2 or earlier',
55 55
                 $stackPtr,
@@ -60,8 +60,8 @@  discard block
 block discarded – undo
60 60
         /*
61 61
          * Closures can only be declared as static since PHP 5.4.
62 62
          */
63
-        $isStatic = $this->isClosureStatic($phpcsFile, $stackPtr);
64
-        if ($this->supportsBelow('5.3') && $isStatic === true) {
63
+        $isStatic = $this->isClosureStatic( $phpcsFile, $stackPtr );
64
+        if ( $this->supportsBelow( '5.3' ) && $isStatic === true ) {
65 65
             $phpcsFile->addError(
66 66
                 'Closures / anonymous functions could not be declared as static in PHP 5.3 or earlier',
67 67
                 $stackPtr,
@@ -71,20 +71,20 @@  discard block
 block discarded – undo
71 71
 
72 72
         $tokens = $phpcsFile->getTokens();
73 73
 
74
-        if (isset($tokens[$stackPtr]['scope_opener'], $tokens[$stackPtr]['scope_closer']) === false) {
74
+        if ( isset( $tokens[ $stackPtr ][ 'scope_opener' ], $tokens[ $stackPtr ][ 'scope_closer' ] ) === false ) {
75 75
             // Live coding or parse error.
76 76
             return;
77 77
         }
78 78
 
79
-        $scopeStart = ($tokens[$stackPtr]['scope_opener'] + 1);
80
-        $scopeEnd   = $tokens[$stackPtr]['scope_closer'];
81
-        $usesThis   = $this->findThisUsageInClosure($phpcsFile, $scopeStart, $scopeEnd);
79
+        $scopeStart = ( $tokens[ $stackPtr ][ 'scope_opener' ] + 1 );
80
+        $scopeEnd   = $tokens[ $stackPtr ][ 'scope_closer' ];
81
+        $usesThis   = $this->findThisUsageInClosure( $phpcsFile, $scopeStart, $scopeEnd );
82 82
 
83
-        if ($this->supportsBelow('5.3')) {
83
+        if ( $this->supportsBelow( '5.3' ) ) {
84 84
             /*
85 85
              * Closures declared within classes only have access to $this since PHP 5.4.
86 86
              */
87
-            if ($usesThis !== false) {
87
+            if ( $usesThis !== false ) {
88 88
                 $thisFound = $usesThis;
89 89
                 do {
90 90
                     $phpcsFile->addError(
@@ -93,35 +93,35 @@  discard block
 block discarded – undo
93 93
                         'ThisFound'
94 94
                     );
95 95
 
96
-                    $thisFound = $this->findThisUsageInClosure($phpcsFile, ($thisFound + 1), $scopeEnd);
96
+                    $thisFound = $this->findThisUsageInClosure( $phpcsFile, ( $thisFound + 1 ), $scopeEnd );
97 97
 
98
-                } while ($thisFound !== false);
98
+                } while ( $thisFound !== false );
99 99
             }
100 100
 
101 101
             /*
102 102
              * Closures declared within classes only have access to self/parent/static since PHP 5.4.
103 103
              */
104
-            $usesClassRef = $this->findClassRefUsageInClosure($phpcsFile, $scopeStart, $scopeEnd);
104
+            $usesClassRef = $this->findClassRefUsageInClosure( $phpcsFile, $scopeStart, $scopeEnd );
105 105
 
106
-            if ($usesClassRef !== false) {
106
+            if ( $usesClassRef !== false ) {
107 107
                 do {
108 108
                     $phpcsFile->addError(
109 109
                         'Closures / anonymous functions could not use "%s::" in PHP 5.3 or earlier',
110 110
                         $usesClassRef,
111 111
                         'ClassRefFound',
112
-                        array(strtolower($tokens[$usesClassRef]['content']))
112
+                        array( strtolower( $tokens[ $usesClassRef ][ 'content' ] ) )
113 113
                     );
114 114
 
115
-                    $usesClassRef = $this->findClassRefUsageInClosure($phpcsFile, ($usesClassRef + 1), $scopeEnd);
115
+                    $usesClassRef = $this->findClassRefUsageInClosure( $phpcsFile, ( $usesClassRef + 1 ), $scopeEnd );
116 116
 
117
-                } while ($usesClassRef !== false);
117
+                } while ( $usesClassRef !== false );
118 118
             }
119 119
         }
120 120
 
121 121
         /*
122 122
          * Check for correct usage.
123 123
          */
124
-        if ($this->supportsAbove('5.4') && $usesThis !== false) {
124
+        if ( $this->supportsAbove( '5.4' ) && $usesThis !== false ) {
125 125
 
126 126
             $thisFound = $usesThis;
127 127
 
@@ -129,7 +129,7 @@  discard block
 block discarded – undo
129 129
                 /*
130 130
                  * Closures only have access to $this if not declared as static.
131 131
                  */
132
-                if ($isStatic === true) {
132
+                if ( $isStatic === true ) {
133 133
                     $phpcsFile->addError(
134 134
                         'Closures / anonymous functions declared as static do not have access to $this',
135 135
                         $thisFound,
@@ -140,7 +140,7 @@  discard block
 block discarded – undo
140 140
                 /*
141 141
                  * Closures only have access to $this if used within a class context.
142 142
                  */
143
-                elseif ($this->inClassScope($phpcsFile, $stackPtr, false) === false) {
143
+                elseif ( $this->inClassScope( $phpcsFile, $stackPtr, false ) === false ) {
144 144
                     $phpcsFile->addWarning(
145 145
                         'Closures / anonymous functions only have access to $this if used within a class or when bound to an object using bindTo(). Please verify.',
146 146
                         $thisFound,
@@ -148,9 +148,9 @@  discard block
 block discarded – undo
148 148
                     );
149 149
                 }
150 150
 
151
-                $thisFound = $this->findThisUsageInClosure($phpcsFile, ($thisFound + 1), $scopeEnd);
151
+                $thisFound = $this->findThisUsageInClosure( $phpcsFile, ( $thisFound + 1 ), $scopeEnd );
152 152
 
153
-            } while ($thisFound !== false);
153
+            } while ( $thisFound !== false );
154 154
         }
155 155
 
156 156
         // Prevent double reporting for nested closures.
@@ -167,12 +167,12 @@  discard block
 block discarded – undo
167 167
      *
168 168
      * @return bool
169 169
      */
170
-    protected function isClosureStatic(File $phpcsFile, $stackPtr)
170
+    protected function isClosureStatic( File $phpcsFile, $stackPtr )
171 171
     {
172 172
         $tokens    = $phpcsFile->getTokens();
173
-        $prevToken = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($stackPtr - 1), null, true, null, true);
173
+        $prevToken = $phpcsFile->findPrevious( Tokens::$emptyTokens, ( $stackPtr - 1 ), null, true, null, true );
174 174
 
175
-        return ($prevToken !== false && $tokens[$prevToken]['code'] === \T_STATIC);
175
+        return ( $prevToken !== false && $tokens[ $prevToken ][ 'code' ] === \T_STATIC );
176 176
     }
177 177
 
178 178
 
@@ -186,10 +186,10 @@  discard block
 block discarded – undo
186 186
      * @return int|false The stackPtr to the first $this usage if found or false if
187 187
      *                   $this is not used.
188 188
      */
189
-    protected function findThisUsageInClosure(File $phpcsFile, $startToken, $endToken)
189
+    protected function findThisUsageInClosure( File $phpcsFile, $startToken, $endToken )
190 190
     {
191 191
         // Make sure the $startToken is valid.
192
-        if ($startToken >= $endToken) {
192
+        if ( $startToken >= $endToken ) {
193 193
             return false;
194 194
         }
195 195
 
@@ -212,23 +212,23 @@  discard block
 block discarded – undo
212 212
      * @return int|false The stackPtr to the first classRef usage if found or false if
213 213
      *                   they are not used.
214 214
      */
215
-    protected function findClassRefUsageInClosure(File $phpcsFile, $startToken, $endToken)
215
+    protected function findClassRefUsageInClosure( File $phpcsFile, $startToken, $endToken )
216 216
     {
217 217
         // Make sure the $startToken is valid.
218
-        if ($startToken >= $endToken) {
218
+        if ( $startToken >= $endToken ) {
219 219
             return false;
220 220
         }
221 221
 
222 222
         $tokens   = $phpcsFile->getTokens();
223
-        $classRef = $phpcsFile->findNext(array(\T_SELF, \T_PARENT, \T_STATIC), $startToken, $endToken);
223
+        $classRef = $phpcsFile->findNext( array( \T_SELF, \T_PARENT, \T_STATIC ), $startToken, $endToken );
224 224
 
225
-        if ($classRef === false || $tokens[$classRef]['code'] !== \T_STATIC) {
225
+        if ( $classRef === false || $tokens[ $classRef ][ 'code' ] !== \T_STATIC ) {
226 226
             return $classRef;
227 227
         }
228 228
 
229 229
         // T_STATIC, make sure it is used as a class reference.
230
-        $next = $phpcsFile->findNext(Tokens::$emptyTokens, ($classRef + 1), $endToken, true);
231
-        if ($next === false || $tokens[$next]['code'] !== \T_DOUBLE_COLON) {
230
+        $next = $phpcsFile->findNext( Tokens::$emptyTokens, ( $classRef + 1 ), $endToken, true );
231
+        if ( $next === false || $tokens[ $next ][ 'code' ] !== \T_DOUBLE_COLON ) {
232 232
             return false;
233 233
         }
234 234
 
Please login to merge, or discard this patch.
Braces   +6 added lines, -12 removed lines patch added patch discarded remove patch
@@ -26,15 +26,13 @@  discard block
 block discarded – undo
26 26
  * @package  PHPCompatibility
27 27
  * @author   Wim Godden <[email protected]>
28 28
  */
29
-class NewClosureSniff extends Sniff
30
-{
29
+class NewClosureSniff extends Sniff {
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(\T_CLOSURE);
39 37
     }
40 38
 
@@ -47,8 +45,7 @@  discard block
 block discarded – undo
47 45
      *
48 46
      * @return void
49 47
      */
50
-    public function process(File $phpcsFile, $stackPtr)
51
-    {
48
+    public function process(File $phpcsFile, $stackPtr) {
52 49
         if ($this->supportsBelow('5.2')) {
53 50
             $phpcsFile->addError(
54 51
                 'Closures / anonymous functions are not available in PHP 5.2 or earlier',
@@ -167,8 +164,7 @@  discard block
 block discarded – undo
167 164
      *
168 165
      * @return bool
169 166
      */
170
-    protected function isClosureStatic(File $phpcsFile, $stackPtr)
171
-    {
167
+    protected function isClosureStatic(File $phpcsFile, $stackPtr) {
172 168
         $tokens    = $phpcsFile->getTokens();
173 169
         $prevToken = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($stackPtr - 1), null, true, null, true);
174 170
 
@@ -186,8 +182,7 @@  discard block
 block discarded – undo
186 182
      * @return int|false The stackPtr to the first $this usage if found or false if
187 183
      *                   $this is not used.
188 184
      */
189
-    protected function findThisUsageInClosure(File $phpcsFile, $startToken, $endToken)
190
-    {
185
+    protected function findThisUsageInClosure(File $phpcsFile, $startToken, $endToken) {
191 186
         // Make sure the $startToken is valid.
192 187
         if ($startToken >= $endToken) {
193 188
             return false;
@@ -212,8 +207,7 @@  discard block
 block discarded – undo
212 207
      * @return int|false The stackPtr to the first classRef usage if found or false if
213 208
      *                   they are not used.
214 209
      */
215
-    protected function findClassRefUsageInClosure(File $phpcsFile, $startToken, $endToken)
216
-    {
210
+    protected function findClassRefUsageInClosure(File $phpcsFile, $startToken, $endToken) {
217 211
         // Make sure the $startToken is valid.
218 212
         if ($startToken >= $endToken) {
219 213
             return false;
Please login to merge, or discard this patch.
PHPCompatibility/Sniffs/InitialValue/NewConstantScalarExpressionsSniff.php 4 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -326,7 +326,7 @@
 block discarded – undo
326 326
      * @param int                   $end          The end of the value definition (inclusive),
327 327
      *                                            i.e. this token will be examined as part of
328 328
      *                                            the snippet.
329
-     * @param bool                  $nestedArrays Optional. Array nesting level when examining
329
+     * @param integer                  $nestedArrays Optional. Array nesting level when examining
330 330
      *                                            the content of an array.
331 331
      *
332 332
      * @return bool
Please login to merge, or discard this patch.
Indentation   +486 added lines, -486 removed lines patch added patch discarded remove patch
@@ -33,502 +33,502 @@
 block discarded – undo
33 33
 class NewConstantScalarExpressionsSniff extends Sniff
34 34
 {
35 35
 
36
-    /**
37
-     * Error message.
38
-     *
39
-     * @var string
40
-     */
41
-    const ERROR_PHRASE = 'Constant scalar expressions are not allowed %s in PHP 5.5 or earlier.';
42
-
43
-    /**
44
-     * Partial error phrases to be used in combination with the error message constant.
45
-     *
46
-     * @var array
47
-     */
48
-    protected $errorPhrases = array(
49
-        'const'     => 'when defining constants using the const keyword',
50
-        'property'  => 'in property declarations',
51
-        'staticvar' => 'in static variable declarations',
52
-        'default'   => 'in default function arguments',
53
-    );
54
-
55
-    /**
56
-     * Tokens which were allowed to be used in these declarations prior to PHP 5.6.
57
-     *
58
-     * This list will be enriched in the setProperties() method.
59
-     *
60
-     * @var array
61
-     */
62
-    protected $safeOperands = array(
63
-        \T_LNUMBER                  => \T_LNUMBER,
64
-        \T_DNUMBER                  => \T_DNUMBER,
65
-        \T_CONSTANT_ENCAPSED_STRING => \T_CONSTANT_ENCAPSED_STRING,
66
-        \T_TRUE                     => \T_TRUE,
67
-        \T_FALSE                    => \T_FALSE,
68
-        \T_NULL                     => \T_NULL,
69
-
70
-        \T_LINE                     => \T_LINE,
71
-        \T_FILE                     => \T_FILE,
72
-        \T_DIR                      => \T_DIR,
73
-        \T_FUNC_C                   => \T_FUNC_C,
74
-        \T_CLASS_C                  => \T_CLASS_C,
75
-        \T_TRAIT_C                  => \T_TRAIT_C,
76
-        \T_METHOD_C                 => \T_METHOD_C,
77
-        \T_NS_C                     => \T_NS_C,
78
-
79
-        // Special cases:
80
-        \T_NS_SEPARATOR             => \T_NS_SEPARATOR,
81
-        /*
36
+	/**
37
+	 * Error message.
38
+	 *
39
+	 * @var string
40
+	 */
41
+	const ERROR_PHRASE = 'Constant scalar expressions are not allowed %s in PHP 5.5 or earlier.';
42
+
43
+	/**
44
+	 * Partial error phrases to be used in combination with the error message constant.
45
+	 *
46
+	 * @var array
47
+	 */
48
+	protected $errorPhrases = array(
49
+		'const'     => 'when defining constants using the const keyword',
50
+		'property'  => 'in property declarations',
51
+		'staticvar' => 'in static variable declarations',
52
+		'default'   => 'in default function arguments',
53
+	);
54
+
55
+	/**
56
+	 * Tokens which were allowed to be used in these declarations prior to PHP 5.6.
57
+	 *
58
+	 * This list will be enriched in the setProperties() method.
59
+	 *
60
+	 * @var array
61
+	 */
62
+	protected $safeOperands = array(
63
+		\T_LNUMBER                  => \T_LNUMBER,
64
+		\T_DNUMBER                  => \T_DNUMBER,
65
+		\T_CONSTANT_ENCAPSED_STRING => \T_CONSTANT_ENCAPSED_STRING,
66
+		\T_TRUE                     => \T_TRUE,
67
+		\T_FALSE                    => \T_FALSE,
68
+		\T_NULL                     => \T_NULL,
69
+
70
+		\T_LINE                     => \T_LINE,
71
+		\T_FILE                     => \T_FILE,
72
+		\T_DIR                      => \T_DIR,
73
+		\T_FUNC_C                   => \T_FUNC_C,
74
+		\T_CLASS_C                  => \T_CLASS_C,
75
+		\T_TRAIT_C                  => \T_TRAIT_C,
76
+		\T_METHOD_C                 => \T_METHOD_C,
77
+		\T_NS_C                     => \T_NS_C,
78
+
79
+		// Special cases:
80
+		\T_NS_SEPARATOR             => \T_NS_SEPARATOR,
81
+		/*
82 82
          * This can be neigh anything, but for any usage except constants,
83 83
          * the T_STRING will be combined with non-allowed tokens, so we should be good.
84 84
          */
85
-        \T_STRING                   => \T_STRING,
86
-    );
87
-
88
-
89
-    /**
90
-     * Returns an array of tokens this test wants to listen for.
91
-     *
92
-     * @return array
93
-     */
94
-    public function register()
95
-    {
96
-        // Set the properties up only once.
97
-        $this->setProperties();
98
-
99
-        return array(
100
-            \T_CONST,
101
-            \T_VARIABLE,
102
-            \T_FUNCTION,
103
-            \T_CLOSURE,
104
-            \T_STATIC,
105
-        );
106
-    }
107
-
108
-
109
-    /**
110
-     * Make some adjustments to the $safeOperands property.
111
-     *
112
-     * @return void
113
-     */
114
-    public function setProperties()
115
-    {
116
-        $this->safeOperands += Tokens::$heredocTokens;
117
-        $this->safeOperands += Tokens::$emptyTokens;
118
-    }
119
-
120
-
121
-    /**
122
-     * Do a version check to determine if this sniff needs to run at all.
123
-     *
124
-     * @return bool
125
-     */
126
-    protected function bowOutEarly()
127
-    {
128
-        return ($this->supportsBelow('5.5') !== true);
129
-    }
130
-
131
-
132
-    /**
133
-     * Processes this test, when one of its tokens is encountered.
134
-     *
135
-     * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned.
136
-     * @param int                   $stackPtr  The position of the current token in the
137
-     *                                         stack passed in $tokens.
138
-     *
139
-     * @return void|int Null or integer stack pointer to skip forward.
140
-     */
141
-    public function process(File $phpcsFile, $stackPtr)
142
-    {
143
-        if ($this->bowOutEarly() === true) {
144
-            return;
145
-        }
146
-
147
-        $tokens = $phpcsFile->getTokens();
148
-
149
-        switch ($tokens[$stackPtr]['type']) {
150
-            case 'T_FUNCTION':
151
-            case 'T_CLOSURE':
152
-                $params = PHPCSHelper::getMethodParameters($phpcsFile, $stackPtr);
153
-                if (empty($params)) {
154
-                    // No parameters.
155
-                    return;
156
-                }
157
-
158
-                $funcToken = $tokens[$stackPtr];
159
-
160
-                if (isset($funcToken['parenthesis_owner'], $funcToken['parenthesis_opener'], $funcToken['parenthesis_closer']) === false
161
-                    || $funcToken['parenthesis_owner'] !== $stackPtr
162
-                    || isset($tokens[$funcToken['parenthesis_opener']], $tokens[$funcToken['parenthesis_closer']]) === false
163
-                ) {
164
-                    // Hmm.. something is going wrong as these should all be available & valid.
165
-                    return;
166
-                }
167
-
168
-                $opener = $funcToken['parenthesis_opener'];
169
-                $closer = $funcToken['parenthesis_closer'];
170
-
171
-                // Which nesting level is the one we are interested in ?
172
-                $nestedParenthesisCount = 1;
173
-                if (isset($tokens[$opener]['nested_parenthesis'])) {
174
-                    $nestedParenthesisCount += \count($tokens[$opener]['nested_parenthesis']);
175
-                }
176
-
177
-                foreach ($params as $param) {
178
-                    if (isset($param['default']) === false) {
179
-                        continue;
180
-                    }
181
-
182
-                    $end = $param['token'];
183
-                    while (($end = $phpcsFile->findNext(array(\T_COMMA, \T_CLOSE_PARENTHESIS), ($end + 1), ($closer + 1))) !== false) {
184
-                        $maybeSkipTo = $this->isRealEndOfDeclaration($tokens, $end, $nestedParenthesisCount);
185
-                        if ($maybeSkipTo !== true) {
186
-                            $end = $maybeSkipTo;
187
-                            continue;
188
-                        }
189
-
190
-                        // Ignore closing parenthesis/bracket if not 'ours'.
191
-                        if ($tokens[$end]['code'] === \T_CLOSE_PARENTHESIS && $end !== $closer) {
192
-                            continue;
193
-                        }
194
-
195
-                        // Ok, we've found the end of the param default value declaration.
196
-                        break;
197
-                    }
198
-
199
-                    if ($this->isValidAssignment($phpcsFile, $param['token'], $end) === false) {
200
-                        $this->throwError($phpcsFile, $param['token'], 'default', $param['content']);
201
-                    }
202
-                }
203
-
204
-                /*
85
+		\T_STRING                   => \T_STRING,
86
+	);
87
+
88
+
89
+	/**
90
+	 * Returns an array of tokens this test wants to listen for.
91
+	 *
92
+	 * @return array
93
+	 */
94
+	public function register()
95
+	{
96
+		// Set the properties up only once.
97
+		$this->setProperties();
98
+
99
+		return array(
100
+			\T_CONST,
101
+			\T_VARIABLE,
102
+			\T_FUNCTION,
103
+			\T_CLOSURE,
104
+			\T_STATIC,
105
+		);
106
+	}
107
+
108
+
109
+	/**
110
+	 * Make some adjustments to the $safeOperands property.
111
+	 *
112
+	 * @return void
113
+	 */
114
+	public function setProperties()
115
+	{
116
+		$this->safeOperands += Tokens::$heredocTokens;
117
+		$this->safeOperands += Tokens::$emptyTokens;
118
+	}
119
+
120
+
121
+	/**
122
+	 * Do a version check to determine if this sniff needs to run at all.
123
+	 *
124
+	 * @return bool
125
+	 */
126
+	protected function bowOutEarly()
127
+	{
128
+		return ($this->supportsBelow('5.5') !== true);
129
+	}
130
+
131
+
132
+	/**
133
+	 * Processes this test, when one of its tokens is encountered.
134
+	 *
135
+	 * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned.
136
+	 * @param int                   $stackPtr  The position of the current token in the
137
+	 *                                         stack passed in $tokens.
138
+	 *
139
+	 * @return void|int Null or integer stack pointer to skip forward.
140
+	 */
141
+	public function process(File $phpcsFile, $stackPtr)
142
+	{
143
+		if ($this->bowOutEarly() === true) {
144
+			return;
145
+		}
146
+
147
+		$tokens = $phpcsFile->getTokens();
148
+
149
+		switch ($tokens[$stackPtr]['type']) {
150
+			case 'T_FUNCTION':
151
+			case 'T_CLOSURE':
152
+				$params = PHPCSHelper::getMethodParameters($phpcsFile, $stackPtr);
153
+				if (empty($params)) {
154
+					// No parameters.
155
+					return;
156
+				}
157
+
158
+				$funcToken = $tokens[$stackPtr];
159
+
160
+				if (isset($funcToken['parenthesis_owner'], $funcToken['parenthesis_opener'], $funcToken['parenthesis_closer']) === false
161
+					|| $funcToken['parenthesis_owner'] !== $stackPtr
162
+					|| isset($tokens[$funcToken['parenthesis_opener']], $tokens[$funcToken['parenthesis_closer']]) === false
163
+				) {
164
+					// Hmm.. something is going wrong as these should all be available & valid.
165
+					return;
166
+				}
167
+
168
+				$opener = $funcToken['parenthesis_opener'];
169
+				$closer = $funcToken['parenthesis_closer'];
170
+
171
+				// Which nesting level is the one we are interested in ?
172
+				$nestedParenthesisCount = 1;
173
+				if (isset($tokens[$opener]['nested_parenthesis'])) {
174
+					$nestedParenthesisCount += \count($tokens[$opener]['nested_parenthesis']);
175
+				}
176
+
177
+				foreach ($params as $param) {
178
+					if (isset($param['default']) === false) {
179
+						continue;
180
+					}
181
+
182
+					$end = $param['token'];
183
+					while (($end = $phpcsFile->findNext(array(\T_COMMA, \T_CLOSE_PARENTHESIS), ($end + 1), ($closer + 1))) !== false) {
184
+						$maybeSkipTo = $this->isRealEndOfDeclaration($tokens, $end, $nestedParenthesisCount);
185
+						if ($maybeSkipTo !== true) {
186
+							$end = $maybeSkipTo;
187
+							continue;
188
+						}
189
+
190
+						// Ignore closing parenthesis/bracket if not 'ours'.
191
+						if ($tokens[$end]['code'] === \T_CLOSE_PARENTHESIS && $end !== $closer) {
192
+							continue;
193
+						}
194
+
195
+						// Ok, we've found the end of the param default value declaration.
196
+						break;
197
+					}
198
+
199
+					if ($this->isValidAssignment($phpcsFile, $param['token'], $end) === false) {
200
+						$this->throwError($phpcsFile, $param['token'], 'default', $param['content']);
201
+					}
202
+				}
203
+
204
+				/*
205 205
                  * No need for the sniff to be triggered by the T_VARIABLEs in the function
206 206
                  * definition as we've already examined them above, so let's skip over them.
207 207
                  */
208
-                return $closer;
209
-
210
-            case 'T_VARIABLE':
211
-            case 'T_STATIC':
212
-            case 'T_CONST':
213
-                $type = 'const';
214
-
215
-                // Filter out non-property declarations.
216
-                if ($tokens[$stackPtr]['code'] === \T_VARIABLE) {
217
-                    if ($this->isClassProperty($phpcsFile, $stackPtr) === false) {
218
-                        return;
219
-                    }
220
-
221
-                    $type = 'property';
222
-
223
-                    // Move back one token to have the same starting point as the others.
224
-                    $stackPtr = ($stackPtr - 1);
225
-                }
226
-
227
-                // Filter out late static binding and class properties.
228
-                if ($tokens[$stackPtr]['code'] === \T_STATIC) {
229
-                    $next = $phpcsFile->findNext(Tokens::$emptyTokens, ($stackPtr + 1), null, true, null, true);
230
-                    if ($next === false || $tokens[$next]['code'] !== \T_VARIABLE) {
231
-                        // Late static binding.
232
-                        return;
233
-                    }
234
-
235
-                    if ($this->isClassProperty($phpcsFile, $next) === true) {
236
-                        // Class properties are examined based on the T_VARIABLE token.
237
-                        return;
238
-                    }
239
-                    unset($next);
240
-
241
-                    $type = 'staticvar';
242
-                }
243
-
244
-                $endOfStatement = $phpcsFile->findNext(array(\T_SEMICOLON, \T_CLOSE_TAG), ($stackPtr + 1));
245
-                if ($endOfStatement === false) {
246
-                    // No semi-colon - live coding.
247
-                    return;
248
-                }
249
-
250
-                $targetNestingLevel = 0;
251
-                if (isset($tokens[$stackPtr]['nested_parenthesis']) === true) {
252
-                    $targetNestingLevel = \count($tokens[$stackPtr]['nested_parenthesis']);
253
-                }
254
-
255
-                // Examine each variable/constant in multi-declarations.
256
-                $start = $stackPtr;
257
-                $end   = $stackPtr;
258
-                while (($end = $phpcsFile->findNext(array(\T_COMMA, \T_SEMICOLON, \T_OPEN_SHORT_ARRAY, \T_CLOSE_TAG), ($end + 1), ($endOfStatement + 1))) !== false) {
259
-
260
-                    $maybeSkipTo = $this->isRealEndOfDeclaration($tokens, $end, $targetNestingLevel);
261
-                    if ($maybeSkipTo !== true) {
262
-                        $end = $maybeSkipTo;
263
-                        continue;
264
-                    }
265
-
266
-                    $start = $phpcsFile->findNext(Tokens::$emptyTokens, ($start + 1), $end, true);
267
-                    if ($start === false
268
-                        || ($tokens[$stackPtr]['code'] === \T_CONST && $tokens[$start]['code'] !== \T_STRING)
269
-                        || ($tokens[$stackPtr]['code'] !== \T_CONST && $tokens[$start]['code'] !== \T_VARIABLE)
270
-                    ) {
271
-                        // Shouldn't be possible.
272
-                        continue;
273
-                    }
274
-
275
-                    if ($this->isValidAssignment($phpcsFile, $start, $end) === false) {
276
-                        // Create the "found" snippet.
277
-                        $content    = '';
278
-                        $tokenCount = ($end - $start);
279
-                        if ($tokenCount < 20) {
280
-                            // Prevent large arrays from being added to the error message.
281
-                            $content = $phpcsFile->getTokensAsString($start, ($tokenCount + 1));
282
-                        }
283
-
284
-                        $this->throwError($phpcsFile, $start, $type, $content);
285
-                    }
286
-
287
-                    $start = $end;
288
-                }
289
-
290
-                // Skip to the end of the statement to prevent duplicate messages for multi-declarations.
291
-                return $endOfStatement;
292
-        }
293
-    }
294
-
295
-
296
-    /**
297
-     * Is a value declared and is the value declared valid pre-PHP 5.6 ?
298
-     *
299
-     * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned.
300
-     * @param int                   $stackPtr  The position of the current token in the
301
-     *                                         stack passed in $tokens.
302
-     * @param int                   $end       The end of the value definition.
303
-     *                                         This will normally be a comma or semi-colon.
304
-     *
305
-     * @return bool
306
-     */
307
-    protected function isValidAssignment(File $phpcsFile, $stackPtr, $end)
308
-    {
309
-        $tokens = $phpcsFile->getTokens();
310
-        $next   = $phpcsFile->findNext(Tokens::$emptyTokens, ($stackPtr + 1), $end, true);
311
-        if ($next === false || $tokens[$next]['code'] !== \T_EQUAL) {
312
-            // No value assigned.
313
-            return true;
314
-        }
315
-
316
-        return $this->isStaticValue($phpcsFile, $tokens, ($next + 1), ($end - 1));
317
-    }
318
-
319
-
320
-    /**
321
-     * Is a value declared and is the value declared constant as accepted in PHP 5.5 and lower ?
322
-     *
323
-     * @param \PHP_CodeSniffer_File $phpcsFile    The file being scanned.
324
-     * @param array                 $tokens       The token stack of the current file.
325
-     * @param int                   $start        The stackPtr from which to start examining.
326
-     * @param int                   $end          The end of the value definition (inclusive),
327
-     *                                            i.e. this token will be examined as part of
328
-     *                                            the snippet.
329
-     * @param bool                  $nestedArrays Optional. Array nesting level when examining
330
-     *                                            the content of an array.
331
-     *
332
-     * @return bool
333
-     */
334
-    protected function isStaticValue(File $phpcsFile, $tokens, $start, $end, $nestedArrays = 0)
335
-    {
336
-        $nextNonSimple = $phpcsFile->findNext($this->safeOperands, $start, ($end + 1), true);
337
-        if ($nextNonSimple === false) {
338
-            return true;
339
-        }
340
-
341
-        /*
208
+				return $closer;
209
+
210
+			case 'T_VARIABLE':
211
+			case 'T_STATIC':
212
+			case 'T_CONST':
213
+				$type = 'const';
214
+
215
+				// Filter out non-property declarations.
216
+				if ($tokens[$stackPtr]['code'] === \T_VARIABLE) {
217
+					if ($this->isClassProperty($phpcsFile, $stackPtr) === false) {
218
+						return;
219
+					}
220
+
221
+					$type = 'property';
222
+
223
+					// Move back one token to have the same starting point as the others.
224
+					$stackPtr = ($stackPtr - 1);
225
+				}
226
+
227
+				// Filter out late static binding and class properties.
228
+				if ($tokens[$stackPtr]['code'] === \T_STATIC) {
229
+					$next = $phpcsFile->findNext(Tokens::$emptyTokens, ($stackPtr + 1), null, true, null, true);
230
+					if ($next === false || $tokens[$next]['code'] !== \T_VARIABLE) {
231
+						// Late static binding.
232
+						return;
233
+					}
234
+
235
+					if ($this->isClassProperty($phpcsFile, $next) === true) {
236
+						// Class properties are examined based on the T_VARIABLE token.
237
+						return;
238
+					}
239
+					unset($next);
240
+
241
+					$type = 'staticvar';
242
+				}
243
+
244
+				$endOfStatement = $phpcsFile->findNext(array(\T_SEMICOLON, \T_CLOSE_TAG), ($stackPtr + 1));
245
+				if ($endOfStatement === false) {
246
+					// No semi-colon - live coding.
247
+					return;
248
+				}
249
+
250
+				$targetNestingLevel = 0;
251
+				if (isset($tokens[$stackPtr]['nested_parenthesis']) === true) {
252
+					$targetNestingLevel = \count($tokens[$stackPtr]['nested_parenthesis']);
253
+				}
254
+
255
+				// Examine each variable/constant in multi-declarations.
256
+				$start = $stackPtr;
257
+				$end   = $stackPtr;
258
+				while (($end = $phpcsFile->findNext(array(\T_COMMA, \T_SEMICOLON, \T_OPEN_SHORT_ARRAY, \T_CLOSE_TAG), ($end + 1), ($endOfStatement + 1))) !== false) {
259
+
260
+					$maybeSkipTo = $this->isRealEndOfDeclaration($tokens, $end, $targetNestingLevel);
261
+					if ($maybeSkipTo !== true) {
262
+						$end = $maybeSkipTo;
263
+						continue;
264
+					}
265
+
266
+					$start = $phpcsFile->findNext(Tokens::$emptyTokens, ($start + 1), $end, true);
267
+					if ($start === false
268
+						|| ($tokens[$stackPtr]['code'] === \T_CONST && $tokens[$start]['code'] !== \T_STRING)
269
+						|| ($tokens[$stackPtr]['code'] !== \T_CONST && $tokens[$start]['code'] !== \T_VARIABLE)
270
+					) {
271
+						// Shouldn't be possible.
272
+						continue;
273
+					}
274
+
275
+					if ($this->isValidAssignment($phpcsFile, $start, $end) === false) {
276
+						// Create the "found" snippet.
277
+						$content    = '';
278
+						$tokenCount = ($end - $start);
279
+						if ($tokenCount < 20) {
280
+							// Prevent large arrays from being added to the error message.
281
+							$content = $phpcsFile->getTokensAsString($start, ($tokenCount + 1));
282
+						}
283
+
284
+						$this->throwError($phpcsFile, $start, $type, $content);
285
+					}
286
+
287
+					$start = $end;
288
+				}
289
+
290
+				// Skip to the end of the statement to prevent duplicate messages for multi-declarations.
291
+				return $endOfStatement;
292
+		}
293
+	}
294
+
295
+
296
+	/**
297
+	 * Is a value declared and is the value declared valid pre-PHP 5.6 ?
298
+	 *
299
+	 * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned.
300
+	 * @param int                   $stackPtr  The position of the current token in the
301
+	 *                                         stack passed in $tokens.
302
+	 * @param int                   $end       The end of the value definition.
303
+	 *                                         This will normally be a comma or semi-colon.
304
+	 *
305
+	 * @return bool
306
+	 */
307
+	protected function isValidAssignment(File $phpcsFile, $stackPtr, $end)
308
+	{
309
+		$tokens = $phpcsFile->getTokens();
310
+		$next   = $phpcsFile->findNext(Tokens::$emptyTokens, ($stackPtr + 1), $end, true);
311
+		if ($next === false || $tokens[$next]['code'] !== \T_EQUAL) {
312
+			// No value assigned.
313
+			return true;
314
+		}
315
+
316
+		return $this->isStaticValue($phpcsFile, $tokens, ($next + 1), ($end - 1));
317
+	}
318
+
319
+
320
+	/**
321
+	 * Is a value declared and is the value declared constant as accepted in PHP 5.5 and lower ?
322
+	 *
323
+	 * @param \PHP_CodeSniffer_File $phpcsFile    The file being scanned.
324
+	 * @param array                 $tokens       The token stack of the current file.
325
+	 * @param int                   $start        The stackPtr from which to start examining.
326
+	 * @param int                   $end          The end of the value definition (inclusive),
327
+	 *                                            i.e. this token will be examined as part of
328
+	 *                                            the snippet.
329
+	 * @param bool                  $nestedArrays Optional. Array nesting level when examining
330
+	 *                                            the content of an array.
331
+	 *
332
+	 * @return bool
333
+	 */
334
+	protected function isStaticValue(File $phpcsFile, $tokens, $start, $end, $nestedArrays = 0)
335
+	{
336
+		$nextNonSimple = $phpcsFile->findNext($this->safeOperands, $start, ($end + 1), true);
337
+		if ($nextNonSimple === false) {
338
+			return true;
339
+		}
340
+
341
+		/*
342 342
          * OK, so we have at least one token which needs extra examination.
343 343
          */
344
-        switch ($tokens[$nextNonSimple]['code']) {
345
-            case \T_MINUS:
346
-            case \T_PLUS:
347
-                if ($this->isNumber($phpcsFile, $start, $end, true) !== false) {
348
-                    // Int or float with sign.
349
-                    return true;
350
-                }
351
-
352
-                return false;
353
-
354
-            case \T_NAMESPACE:
355
-            case \T_PARENT:
356
-            case \T_SELF:
357
-            case \T_DOUBLE_COLON:
358
-                $nextNonEmpty = $phpcsFile->findNext(Tokens::$emptyTokens, ($nextNonSimple + 1), ($end + 1), true);
359
-
360
-                if ($tokens[$nextNonSimple]['code'] === \T_NAMESPACE) {
361
-                    // Allow only `namespace\...`.
362
-                    if ($nextNonEmpty === false || $tokens[$nextNonEmpty]['code'] !== \T_NS_SEPARATOR) {
363
-                        return false;
364
-                    }
365
-                } elseif ($tokens[$nextNonSimple]['code'] === \T_PARENT
366
-                    || $tokens[$nextNonSimple]['code'] === \T_SELF
367
-                ) {
368
-                    // Allow only `parent::` and `self::`.
369
-                    if ($nextNonEmpty === false || $tokens[$nextNonEmpty]['code'] !== \T_DOUBLE_COLON) {
370
-                        return false;
371
-                    }
372
-                } elseif ($tokens[$nextNonSimple]['code'] === \T_DOUBLE_COLON) {
373
-                    // Allow only `T_STRING::T_STRING`.
374
-                    if ($nextNonEmpty === false || $tokens[$nextNonEmpty]['code'] !== \T_STRING) {
375
-                        return false;
376
-                    }
377
-
378
-                    $prevNonEmpty = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($nextNonSimple - 1), null, true);
379
-                    // No need to worry about parent/self, that's handled above and
380
-                    // the double colon is skipped over in that case.
381
-                    if ($prevNonEmpty === false || $tokens[$prevNonEmpty]['code'] !== \T_STRING) {
382
-                        return false;
383
-                    }
384
-                }
385
-
386
-                // Examine what comes after the namespace/parent/self/double colon, if anything.
387
-                return $this->isStaticValue($phpcsFile, $tokens, ($nextNonEmpty + 1), $end, $nestedArrays);
388
-
389
-            case \T_ARRAY:
390
-            case \T_OPEN_SHORT_ARRAY:
391
-                ++$nestedArrays;
392
-
393
-                $arrayItems = $this->getFunctionCallParameters($phpcsFile, $nextNonSimple);
394
-                if (empty($arrayItems) === false) {
395
-                    foreach ($arrayItems as $item) {
396
-                        // Check for a double arrow, but only if it's for this array item, not for a nested array.
397
-                        $doubleArrow = false;
398
-
399
-                        $maybeDoubleArrow = $phpcsFile->findNext(
400
-                            array(\T_DOUBLE_ARROW, \T_ARRAY, \T_OPEN_SHORT_ARRAY),
401
-                            $item['start'],
402
-                            ($item['end'] + 1)
403
-                        );
404
-                        if ($maybeDoubleArrow !== false && $tokens[$maybeDoubleArrow]['code'] === \T_DOUBLE_ARROW) {
405
-                            // Double arrow is for this nesting level.
406
-                            $doubleArrow = $maybeDoubleArrow;
407
-                        }
408
-
409
-                        if ($doubleArrow === false) {
410
-                            if ($this->isStaticValue($phpcsFile, $tokens, $item['start'], $item['end'], $nestedArrays) === false) {
411
-                                return false;
412
-                            }
413
-
414
-                        } else {
415
-                            // Examine array key.
416
-                            if ($this->isStaticValue($phpcsFile, $tokens, $item['start'], ($doubleArrow - 1), $nestedArrays) === false) {
417
-                                return false;
418
-                            }
419
-
420
-                            // Examine array value.
421
-                            if ($this->isStaticValue($phpcsFile, $tokens, ($doubleArrow + 1), $item['end'], $nestedArrays) === false) {
422
-                                return false;
423
-                            }
424
-                        }
425
-                    }
426
-                }
427
-
428
-                --$nestedArrays;
429
-
430
-                /*
344
+		switch ($tokens[$nextNonSimple]['code']) {
345
+			case \T_MINUS:
346
+			case \T_PLUS:
347
+				if ($this->isNumber($phpcsFile, $start, $end, true) !== false) {
348
+					// Int or float with sign.
349
+					return true;
350
+				}
351
+
352
+				return false;
353
+
354
+			case \T_NAMESPACE:
355
+			case \T_PARENT:
356
+			case \T_SELF:
357
+			case \T_DOUBLE_COLON:
358
+				$nextNonEmpty = $phpcsFile->findNext(Tokens::$emptyTokens, ($nextNonSimple + 1), ($end + 1), true);
359
+
360
+				if ($tokens[$nextNonSimple]['code'] === \T_NAMESPACE) {
361
+					// Allow only `namespace\...`.
362
+					if ($nextNonEmpty === false || $tokens[$nextNonEmpty]['code'] !== \T_NS_SEPARATOR) {
363
+						return false;
364
+					}
365
+				} elseif ($tokens[$nextNonSimple]['code'] === \T_PARENT
366
+					|| $tokens[$nextNonSimple]['code'] === \T_SELF
367
+				) {
368
+					// Allow only `parent::` and `self::`.
369
+					if ($nextNonEmpty === false || $tokens[$nextNonEmpty]['code'] !== \T_DOUBLE_COLON) {
370
+						return false;
371
+					}
372
+				} elseif ($tokens[$nextNonSimple]['code'] === \T_DOUBLE_COLON) {
373
+					// Allow only `T_STRING::T_STRING`.
374
+					if ($nextNonEmpty === false || $tokens[$nextNonEmpty]['code'] !== \T_STRING) {
375
+						return false;
376
+					}
377
+
378
+					$prevNonEmpty = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($nextNonSimple - 1), null, true);
379
+					// No need to worry about parent/self, that's handled above and
380
+					// the double colon is skipped over in that case.
381
+					if ($prevNonEmpty === false || $tokens[$prevNonEmpty]['code'] !== \T_STRING) {
382
+						return false;
383
+					}
384
+				}
385
+
386
+				// Examine what comes after the namespace/parent/self/double colon, if anything.
387
+				return $this->isStaticValue($phpcsFile, $tokens, ($nextNonEmpty + 1), $end, $nestedArrays);
388
+
389
+			case \T_ARRAY:
390
+			case \T_OPEN_SHORT_ARRAY:
391
+				++$nestedArrays;
392
+
393
+				$arrayItems = $this->getFunctionCallParameters($phpcsFile, $nextNonSimple);
394
+				if (empty($arrayItems) === false) {
395
+					foreach ($arrayItems as $item) {
396
+						// Check for a double arrow, but only if it's for this array item, not for a nested array.
397
+						$doubleArrow = false;
398
+
399
+						$maybeDoubleArrow = $phpcsFile->findNext(
400
+							array(\T_DOUBLE_ARROW, \T_ARRAY, \T_OPEN_SHORT_ARRAY),
401
+							$item['start'],
402
+							($item['end'] + 1)
403
+						);
404
+						if ($maybeDoubleArrow !== false && $tokens[$maybeDoubleArrow]['code'] === \T_DOUBLE_ARROW) {
405
+							// Double arrow is for this nesting level.
406
+							$doubleArrow = $maybeDoubleArrow;
407
+						}
408
+
409
+						if ($doubleArrow === false) {
410
+							if ($this->isStaticValue($phpcsFile, $tokens, $item['start'], $item['end'], $nestedArrays) === false) {
411
+								return false;
412
+							}
413
+
414
+						} else {
415
+							// Examine array key.
416
+							if ($this->isStaticValue($phpcsFile, $tokens, $item['start'], ($doubleArrow - 1), $nestedArrays) === false) {
417
+								return false;
418
+							}
419
+
420
+							// Examine array value.
421
+							if ($this->isStaticValue($phpcsFile, $tokens, ($doubleArrow + 1), $item['end'], $nestedArrays) === false) {
422
+								return false;
423
+							}
424
+						}
425
+					}
426
+				}
427
+
428
+				--$nestedArrays;
429
+
430
+				/*
431 431
                  * Find the end of the array.
432 432
                  * We already know we will have a valid closer as otherwise we wouldn't have been
433 433
                  * able to get the array items.
434 434
                  */
435
-                $closer = ($nextNonSimple + 1);
436
-                if ($tokens[$nextNonSimple]['code'] === \T_OPEN_SHORT_ARRAY
437
-                    && isset($tokens[$nextNonSimple]['bracket_closer']) === true
438
-                ) {
439
-                    $closer = $tokens[$nextNonSimple]['bracket_closer'];
440
-                } else {
441
-                    $maybeOpener = $phpcsFile->findNext(Tokens::$emptyTokens, ($nextNonSimple + 1), ($end + 1), true);
442
-                    if ($tokens[$maybeOpener]['code'] === \T_OPEN_PARENTHESIS) {
443
-                        $opener = $maybeOpener;
444
-                        if (isset($tokens[$opener]['parenthesis_closer']) === true) {
445
-                            $closer = $tokens[$opener]['parenthesis_closer'];
446
-                        }
447
-                    }
448
-                }
449
-
450
-                if ($closer === $end) {
451
-                    return true;
452
-                }
453
-
454
-                // Examine what comes after the array, if anything.
455
-                return $this->isStaticValue($phpcsFile, $tokens, ($closer + 1), $end, $nestedArrays);
456
-
457
-        }
458
-
459
-        // Ok, so this unsafe token was not one of the exceptions, i.e. this is a PHP 5.6+ syntax.
460
-        return false;
461
-    }
462
-
463
-
464
-    /**
465
-     * Throw an error if a scalar expression is found.
466
-     *
467
-     * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned.
468
-     * @param int                   $stackPtr  The position of the token to link the error to.
469
-     * @param string                $type      Type of usage found.
470
-     * @param string                $content   Optional. The value for the declaration as found.
471
-     *
472
-     * @return void
473
-     */
474
-    protected function throwError(File $phpcsFile, $stackPtr, $type, $content = '')
475
-    {
476
-        $error     = static::ERROR_PHRASE;
477
-        $phrase    = '';
478
-        $errorCode = 'Found';
479
-
480
-        if (isset($this->errorPhrases[$type]) === true) {
481
-            $errorCode = $this->stringToErrorCode($type) . 'Found';
482
-            $phrase    = $this->errorPhrases[$type];
483
-        }
484
-
485
-        $data = array($phrase);
486
-
487
-        if (empty($content) === false) {
488
-            $error .= ' Found: %s';
489
-            $data[] = $content;
490
-        }
491
-
492
-        $phpcsFile->addError($error, $stackPtr, $errorCode, $data);
493
-    }
494
-
495
-
496
-    /**
497
-     * Helper function to find the end of multi variable/constant declarations.
498
-     *
499
-     * Checks whether a certain part of a declaration needs to be skipped over or
500
-     * if it is the real end of the declaration.
501
-     *
502
-     * @param array $tokens      Token stack of the current file.
503
-     * @param int   $endPtr      The token to examine as a candidate end pointer.
504
-     * @param int   $targetLevel Target nesting level.
505
-     *
506
-     * @return bool|int True if this is the real end. Int stackPtr to skip to if not.
507
-     */
508
-    private function isRealEndOfDeclaration($tokens, $endPtr, $targetLevel)
509
-    {
510
-        // Ignore anything within short array definition brackets for now.
511
-        if ($tokens[$endPtr]['code'] === \T_OPEN_SHORT_ARRAY
512
-            && (isset($tokens[$endPtr]['bracket_opener'])
513
-                && $tokens[$endPtr]['bracket_opener'] === $endPtr)
514
-            && isset($tokens[$endPtr]['bracket_closer'])
515
-        ) {
516
-            // Skip forward to the end of the short array definition.
517
-            return $tokens[$endPtr]['bracket_closer'];
518
-        }
519
-
520
-        // Skip past comma's at a lower nesting level.
521
-        if ($tokens[$endPtr]['code'] === \T_COMMA) {
522
-            // Check if a comma is at the nesting level we're targetting.
523
-            $nestingLevel = 0;
524
-            if (isset($tokens[$endPtr]['nested_parenthesis']) === true) {
525
-                $nestingLevel = \count($tokens[$endPtr]['nested_parenthesis']);
526
-            }
527
-            if ($nestingLevel > $targetLevel) {
528
-                return $endPtr;
529
-            }
530
-        }
531
-
532
-        return true;
533
-    }
435
+				$closer = ($nextNonSimple + 1);
436
+				if ($tokens[$nextNonSimple]['code'] === \T_OPEN_SHORT_ARRAY
437
+					&& isset($tokens[$nextNonSimple]['bracket_closer']) === true
438
+				) {
439
+					$closer = $tokens[$nextNonSimple]['bracket_closer'];
440
+				} else {
441
+					$maybeOpener = $phpcsFile->findNext(Tokens::$emptyTokens, ($nextNonSimple + 1), ($end + 1), true);
442
+					if ($tokens[$maybeOpener]['code'] === \T_OPEN_PARENTHESIS) {
443
+						$opener = $maybeOpener;
444
+						if (isset($tokens[$opener]['parenthesis_closer']) === true) {
445
+							$closer = $tokens[$opener]['parenthesis_closer'];
446
+						}
447
+					}
448
+				}
449
+
450
+				if ($closer === $end) {
451
+					return true;
452
+				}
453
+
454
+				// Examine what comes after the array, if anything.
455
+				return $this->isStaticValue($phpcsFile, $tokens, ($closer + 1), $end, $nestedArrays);
456
+
457
+		}
458
+
459
+		// Ok, so this unsafe token was not one of the exceptions, i.e. this is a PHP 5.6+ syntax.
460
+		return false;
461
+	}
462
+
463
+
464
+	/**
465
+	 * Throw an error if a scalar expression is found.
466
+	 *
467
+	 * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned.
468
+	 * @param int                   $stackPtr  The position of the token to link the error to.
469
+	 * @param string                $type      Type of usage found.
470
+	 * @param string                $content   Optional. The value for the declaration as found.
471
+	 *
472
+	 * @return void
473
+	 */
474
+	protected function throwError(File $phpcsFile, $stackPtr, $type, $content = '')
475
+	{
476
+		$error     = static::ERROR_PHRASE;
477
+		$phrase    = '';
478
+		$errorCode = 'Found';
479
+
480
+		if (isset($this->errorPhrases[$type]) === true) {
481
+			$errorCode = $this->stringToErrorCode($type) . 'Found';
482
+			$phrase    = $this->errorPhrases[$type];
483
+		}
484
+
485
+		$data = array($phrase);
486
+
487
+		if (empty($content) === false) {
488
+			$error .= ' Found: %s';
489
+			$data[] = $content;
490
+		}
491
+
492
+		$phpcsFile->addError($error, $stackPtr, $errorCode, $data);
493
+	}
494
+
495
+
496
+	/**
497
+	 * Helper function to find the end of multi variable/constant declarations.
498
+	 *
499
+	 * Checks whether a certain part of a declaration needs to be skipped over or
500
+	 * if it is the real end of the declaration.
501
+	 *
502
+	 * @param array $tokens      Token stack of the current file.
503
+	 * @param int   $endPtr      The token to examine as a candidate end pointer.
504
+	 * @param int   $targetLevel Target nesting level.
505
+	 *
506
+	 * @return bool|int True if this is the real end. Int stackPtr to skip to if not.
507
+	 */
508
+	private function isRealEndOfDeclaration($tokens, $endPtr, $targetLevel)
509
+	{
510
+		// Ignore anything within short array definition brackets for now.
511
+		if ($tokens[$endPtr]['code'] === \T_OPEN_SHORT_ARRAY
512
+			&& (isset($tokens[$endPtr]['bracket_opener'])
513
+				&& $tokens[$endPtr]['bracket_opener'] === $endPtr)
514
+			&& isset($tokens[$endPtr]['bracket_closer'])
515
+		) {
516
+			// Skip forward to the end of the short array definition.
517
+			return $tokens[$endPtr]['bracket_closer'];
518
+		}
519
+
520
+		// Skip past comma's at a lower nesting level.
521
+		if ($tokens[$endPtr]['code'] === \T_COMMA) {
522
+			// Check if a comma is at the nesting level we're targetting.
523
+			$nestingLevel = 0;
524
+			if (isset($tokens[$endPtr]['nested_parenthesis']) === true) {
525
+				$nestingLevel = \count($tokens[$endPtr]['nested_parenthesis']);
526
+			}
527
+			if ($nestingLevel > $targetLevel) {
528
+				return $endPtr;
529
+			}
530
+		}
531
+
532
+		return true;
533
+	}
534 534
 }
Please login to merge, or discard this patch.
Spacing   +106 added lines, -106 removed lines patch added patch discarded remove patch
@@ -125,7 +125,7 @@  discard block
 block discarded – undo
125 125
      */
126 126
     protected function bowOutEarly()
127 127
     {
128
-        return ($this->supportsBelow('5.5') !== true);
128
+        return ( $this->supportsBelow( '5.5' ) !== true );
129 129
     }
130 130
 
131 131
 
@@ -138,57 +138,57 @@  discard block
 block discarded – undo
138 138
      *
139 139
      * @return void|int Null or integer stack pointer to skip forward.
140 140
      */
141
-    public function process(File $phpcsFile, $stackPtr)
141
+    public function process( File $phpcsFile, $stackPtr )
142 142
     {
143
-        if ($this->bowOutEarly() === true) {
143
+        if ( $this->bowOutEarly() === true ) {
144 144
             return;
145 145
         }
146 146
 
147 147
         $tokens = $phpcsFile->getTokens();
148 148
 
149
-        switch ($tokens[$stackPtr]['type']) {
149
+        switch ( $tokens[ $stackPtr ][ 'type' ] ) {
150 150
             case 'T_FUNCTION':
151 151
             case 'T_CLOSURE':
152
-                $params = PHPCSHelper::getMethodParameters($phpcsFile, $stackPtr);
153
-                if (empty($params)) {
152
+                $params = PHPCSHelper::getMethodParameters( $phpcsFile, $stackPtr );
153
+                if ( empty( $params ) ) {
154 154
                     // No parameters.
155 155
                     return;
156 156
                 }
157 157
 
158
-                $funcToken = $tokens[$stackPtr];
158
+                $funcToken = $tokens[ $stackPtr ];
159 159
 
160
-                if (isset($funcToken['parenthesis_owner'], $funcToken['parenthesis_opener'], $funcToken['parenthesis_closer']) === false
161
-                    || $funcToken['parenthesis_owner'] !== $stackPtr
162
-                    || isset($tokens[$funcToken['parenthesis_opener']], $tokens[$funcToken['parenthesis_closer']]) === false
160
+                if ( isset( $funcToken[ 'parenthesis_owner' ], $funcToken[ 'parenthesis_opener' ], $funcToken[ 'parenthesis_closer' ] ) === false
161
+                    || $funcToken[ 'parenthesis_owner' ] !== $stackPtr
162
+                    || isset( $tokens[ $funcToken[ 'parenthesis_opener' ] ], $tokens[ $funcToken[ 'parenthesis_closer' ] ] ) === false
163 163
                 ) {
164 164
                     // Hmm.. something is going wrong as these should all be available & valid.
165 165
                     return;
166 166
                 }
167 167
 
168
-                $opener = $funcToken['parenthesis_opener'];
169
-                $closer = $funcToken['parenthesis_closer'];
168
+                $opener = $funcToken[ 'parenthesis_opener' ];
169
+                $closer = $funcToken[ 'parenthesis_closer' ];
170 170
 
171 171
                 // Which nesting level is the one we are interested in ?
172 172
                 $nestedParenthesisCount = 1;
173
-                if (isset($tokens[$opener]['nested_parenthesis'])) {
174
-                    $nestedParenthesisCount += \count($tokens[$opener]['nested_parenthesis']);
173
+                if ( isset( $tokens[ $opener ][ 'nested_parenthesis' ] ) ) {
174
+                    $nestedParenthesisCount += \count( $tokens[ $opener ][ 'nested_parenthesis' ] );
175 175
                 }
176 176
 
177
-                foreach ($params as $param) {
178
-                    if (isset($param['default']) === false) {
177
+                foreach ( $params as $param ) {
178
+                    if ( isset( $param[ 'default' ] ) === false ) {
179 179
                         continue;
180 180
                     }
181 181
 
182
-                    $end = $param['token'];
183
-                    while (($end = $phpcsFile->findNext(array(\T_COMMA, \T_CLOSE_PARENTHESIS), ($end + 1), ($closer + 1))) !== false) {
184
-                        $maybeSkipTo = $this->isRealEndOfDeclaration($tokens, $end, $nestedParenthesisCount);
185
-                        if ($maybeSkipTo !== true) {
182
+                    $end = $param[ 'token' ];
183
+                    while ( ( $end = $phpcsFile->findNext( array( \T_COMMA, \T_CLOSE_PARENTHESIS ), ( $end + 1 ), ( $closer + 1 ) ) ) !== false ) {
184
+                        $maybeSkipTo = $this->isRealEndOfDeclaration( $tokens, $end, $nestedParenthesisCount );
185
+                        if ( $maybeSkipTo !== true ) {
186 186
                             $end = $maybeSkipTo;
187 187
                             continue;
188 188
                         }
189 189
 
190 190
                         // Ignore closing parenthesis/bracket if not 'ours'.
191
-                        if ($tokens[$end]['code'] === \T_CLOSE_PARENTHESIS && $end !== $closer) {
191
+                        if ( $tokens[ $end ][ 'code' ] === \T_CLOSE_PARENTHESIS && $end !== $closer ) {
192 192
                             continue;
193 193
                         }
194 194
 
@@ -196,8 +196,8 @@  discard block
 block discarded – undo
196 196
                         break;
197 197
                     }
198 198
 
199
-                    if ($this->isValidAssignment($phpcsFile, $param['token'], $end) === false) {
200
-                        $this->throwError($phpcsFile, $param['token'], 'default', $param['content']);
199
+                    if ( $this->isValidAssignment( $phpcsFile, $param[ 'token' ], $end ) === false ) {
200
+                        $this->throwError( $phpcsFile, $param[ 'token' ], 'default', $param[ 'content' ] );
201 201
                     }
202 202
                 }
203 203
 
@@ -213,75 +213,75 @@  discard block
 block discarded – undo
213 213
                 $type = 'const';
214 214
 
215 215
                 // Filter out non-property declarations.
216
-                if ($tokens[$stackPtr]['code'] === \T_VARIABLE) {
217
-                    if ($this->isClassProperty($phpcsFile, $stackPtr) === false) {
216
+                if ( $tokens[ $stackPtr ][ 'code' ] === \T_VARIABLE ) {
217
+                    if ( $this->isClassProperty( $phpcsFile, $stackPtr ) === false ) {
218 218
                         return;
219 219
                     }
220 220
 
221 221
                     $type = 'property';
222 222
 
223 223
                     // Move back one token to have the same starting point as the others.
224
-                    $stackPtr = ($stackPtr - 1);
224
+                    $stackPtr = ( $stackPtr - 1 );
225 225
                 }
226 226
 
227 227
                 // Filter out late static binding and class properties.
228
-                if ($tokens[$stackPtr]['code'] === \T_STATIC) {
229
-                    $next = $phpcsFile->findNext(Tokens::$emptyTokens, ($stackPtr + 1), null, true, null, true);
230
-                    if ($next === false || $tokens[$next]['code'] !== \T_VARIABLE) {
228
+                if ( $tokens[ $stackPtr ][ 'code' ] === \T_STATIC ) {
229
+                    $next = $phpcsFile->findNext( Tokens::$emptyTokens, ( $stackPtr + 1 ), null, true, null, true );
230
+                    if ( $next === false || $tokens[ $next ][ 'code' ] !== \T_VARIABLE ) {
231 231
                         // Late static binding.
232 232
                         return;
233 233
                     }
234 234
 
235
-                    if ($this->isClassProperty($phpcsFile, $next) === true) {
235
+                    if ( $this->isClassProperty( $phpcsFile, $next ) === true ) {
236 236
                         // Class properties are examined based on the T_VARIABLE token.
237 237
                         return;
238 238
                     }
239
-                    unset($next);
239
+                    unset( $next );
240 240
 
241 241
                     $type = 'staticvar';
242 242
                 }
243 243
 
244
-                $endOfStatement = $phpcsFile->findNext(array(\T_SEMICOLON, \T_CLOSE_TAG), ($stackPtr + 1));
245
-                if ($endOfStatement === false) {
244
+                $endOfStatement = $phpcsFile->findNext( array( \T_SEMICOLON, \T_CLOSE_TAG ), ( $stackPtr + 1 ) );
245
+                if ( $endOfStatement === false ) {
246 246
                     // No semi-colon - live coding.
247 247
                     return;
248 248
                 }
249 249
 
250 250
                 $targetNestingLevel = 0;
251
-                if (isset($tokens[$stackPtr]['nested_parenthesis']) === true) {
252
-                    $targetNestingLevel = \count($tokens[$stackPtr]['nested_parenthesis']);
251
+                if ( isset( $tokens[ $stackPtr ][ 'nested_parenthesis' ] ) === true ) {
252
+                    $targetNestingLevel = \count( $tokens[ $stackPtr ][ 'nested_parenthesis' ] );
253 253
                 }
254 254
 
255 255
                 // Examine each variable/constant in multi-declarations.
256 256
                 $start = $stackPtr;
257 257
                 $end   = $stackPtr;
258
-                while (($end = $phpcsFile->findNext(array(\T_COMMA, \T_SEMICOLON, \T_OPEN_SHORT_ARRAY, \T_CLOSE_TAG), ($end + 1), ($endOfStatement + 1))) !== false) {
258
+                while ( ( $end = $phpcsFile->findNext( array( \T_COMMA, \T_SEMICOLON, \T_OPEN_SHORT_ARRAY, \T_CLOSE_TAG ), ( $end + 1 ), ( $endOfStatement + 1 ) ) ) !== false ) {
259 259
 
260
-                    $maybeSkipTo = $this->isRealEndOfDeclaration($tokens, $end, $targetNestingLevel);
261
-                    if ($maybeSkipTo !== true) {
260
+                    $maybeSkipTo = $this->isRealEndOfDeclaration( $tokens, $end, $targetNestingLevel );
261
+                    if ( $maybeSkipTo !== true ) {
262 262
                         $end = $maybeSkipTo;
263 263
                         continue;
264 264
                     }
265 265
 
266
-                    $start = $phpcsFile->findNext(Tokens::$emptyTokens, ($start + 1), $end, true);
267
-                    if ($start === false
268
-                        || ($tokens[$stackPtr]['code'] === \T_CONST && $tokens[$start]['code'] !== \T_STRING)
269
-                        || ($tokens[$stackPtr]['code'] !== \T_CONST && $tokens[$start]['code'] !== \T_VARIABLE)
266
+                    $start = $phpcsFile->findNext( Tokens::$emptyTokens, ( $start + 1 ), $end, true );
267
+                    if ( $start === false
268
+                        || ( $tokens[ $stackPtr ][ 'code' ] === \T_CONST && $tokens[ $start ][ 'code' ] !== \T_STRING )
269
+                        || ( $tokens[ $stackPtr ][ 'code' ] !== \T_CONST && $tokens[ $start ][ 'code' ] !== \T_VARIABLE )
270 270
                     ) {
271 271
                         // Shouldn't be possible.
272 272
                         continue;
273 273
                     }
274 274
 
275
-                    if ($this->isValidAssignment($phpcsFile, $start, $end) === false) {
275
+                    if ( $this->isValidAssignment( $phpcsFile, $start, $end ) === false ) {
276 276
                         // Create the "found" snippet.
277 277
                         $content    = '';
278
-                        $tokenCount = ($end - $start);
279
-                        if ($tokenCount < 20) {
278
+                        $tokenCount = ( $end - $start );
279
+                        if ( $tokenCount < 20 ) {
280 280
                             // Prevent large arrays from being added to the error message.
281
-                            $content = $phpcsFile->getTokensAsString($start, ($tokenCount + 1));
281
+                            $content = $phpcsFile->getTokensAsString( $start, ( $tokenCount + 1 ) );
282 282
                         }
283 283
 
284
-                        $this->throwError($phpcsFile, $start, $type, $content);
284
+                        $this->throwError( $phpcsFile, $start, $type, $content );
285 285
                     }
286 286
 
287 287
                     $start = $end;
@@ -304,16 +304,16 @@  discard block
 block discarded – undo
304 304
      *
305 305
      * @return bool
306 306
      */
307
-    protected function isValidAssignment(File $phpcsFile, $stackPtr, $end)
307
+    protected function isValidAssignment( File $phpcsFile, $stackPtr, $end )
308 308
     {
309 309
         $tokens = $phpcsFile->getTokens();
310
-        $next   = $phpcsFile->findNext(Tokens::$emptyTokens, ($stackPtr + 1), $end, true);
311
-        if ($next === false || $tokens[$next]['code'] !== \T_EQUAL) {
310
+        $next   = $phpcsFile->findNext( Tokens::$emptyTokens, ( $stackPtr + 1 ), $end, true );
311
+        if ( $next === false || $tokens[ $next ][ 'code' ] !== \T_EQUAL ) {
312 312
             // No value assigned.
313 313
             return true;
314 314
         }
315 315
 
316
-        return $this->isStaticValue($phpcsFile, $tokens, ($next + 1), ($end - 1));
316
+        return $this->isStaticValue( $phpcsFile, $tokens, ( $next + 1 ), ( $end - 1 ) );
317 317
     }
318 318
 
319 319
 
@@ -331,20 +331,20 @@  discard block
 block discarded – undo
331 331
      *
332 332
      * @return bool
333 333
      */
334
-    protected function isStaticValue(File $phpcsFile, $tokens, $start, $end, $nestedArrays = 0)
334
+    protected function isStaticValue( File $phpcsFile, $tokens, $start, $end, $nestedArrays = 0 )
335 335
     {
336
-        $nextNonSimple = $phpcsFile->findNext($this->safeOperands, $start, ($end + 1), true);
337
-        if ($nextNonSimple === false) {
336
+        $nextNonSimple = $phpcsFile->findNext( $this->safeOperands, $start, ( $end + 1 ), true );
337
+        if ( $nextNonSimple === false ) {
338 338
             return true;
339 339
         }
340 340
 
341 341
         /*
342 342
          * OK, so we have at least one token which needs extra examination.
343 343
          */
344
-        switch ($tokens[$nextNonSimple]['code']) {
344
+        switch ( $tokens[ $nextNonSimple ][ 'code' ] ) {
345 345
             case \T_MINUS:
346 346
             case \T_PLUS:
347
-                if ($this->isNumber($phpcsFile, $start, $end, true) !== false) {
347
+                if ( $this->isNumber( $phpcsFile, $start, $end, true ) !== false ) {
348 348
                     // Int or float with sign.
349 349
                     return true;
350 350
                 }
@@ -355,70 +355,70 @@  discard block
 block discarded – undo
355 355
             case \T_PARENT:
356 356
             case \T_SELF:
357 357
             case \T_DOUBLE_COLON:
358
-                $nextNonEmpty = $phpcsFile->findNext(Tokens::$emptyTokens, ($nextNonSimple + 1), ($end + 1), true);
358
+                $nextNonEmpty = $phpcsFile->findNext( Tokens::$emptyTokens, ( $nextNonSimple + 1 ), ( $end + 1 ), true );
359 359
 
360
-                if ($tokens[$nextNonSimple]['code'] === \T_NAMESPACE) {
360
+                if ( $tokens[ $nextNonSimple ][ 'code' ] === \T_NAMESPACE ) {
361 361
                     // Allow only `namespace\...`.
362
-                    if ($nextNonEmpty === false || $tokens[$nextNonEmpty]['code'] !== \T_NS_SEPARATOR) {
362
+                    if ( $nextNonEmpty === false || $tokens[ $nextNonEmpty ][ 'code' ] !== \T_NS_SEPARATOR ) {
363 363
                         return false;
364 364
                     }
365
-                } elseif ($tokens[$nextNonSimple]['code'] === \T_PARENT
366
-                    || $tokens[$nextNonSimple]['code'] === \T_SELF
365
+                } elseif ( $tokens[ $nextNonSimple ][ 'code' ] === \T_PARENT
366
+                    || $tokens[ $nextNonSimple ][ 'code' ] === \T_SELF
367 367
                 ) {
368 368
                     // Allow only `parent::` and `self::`.
369
-                    if ($nextNonEmpty === false || $tokens[$nextNonEmpty]['code'] !== \T_DOUBLE_COLON) {
369
+                    if ( $nextNonEmpty === false || $tokens[ $nextNonEmpty ][ 'code' ] !== \T_DOUBLE_COLON ) {
370 370
                         return false;
371 371
                     }
372
-                } elseif ($tokens[$nextNonSimple]['code'] === \T_DOUBLE_COLON) {
372
+                } elseif ( $tokens[ $nextNonSimple ][ 'code' ] === \T_DOUBLE_COLON ) {
373 373
                     // Allow only `T_STRING::T_STRING`.
374
-                    if ($nextNonEmpty === false || $tokens[$nextNonEmpty]['code'] !== \T_STRING) {
374
+                    if ( $nextNonEmpty === false || $tokens[ $nextNonEmpty ][ 'code' ] !== \T_STRING ) {
375 375
                         return false;
376 376
                     }
377 377
 
378
-                    $prevNonEmpty = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($nextNonSimple - 1), null, true);
378
+                    $prevNonEmpty = $phpcsFile->findPrevious( Tokens::$emptyTokens, ( $nextNonSimple - 1 ), null, true );
379 379
                     // No need to worry about parent/self, that's handled above and
380 380
                     // the double colon is skipped over in that case.
381
-                    if ($prevNonEmpty === false || $tokens[$prevNonEmpty]['code'] !== \T_STRING) {
381
+                    if ( $prevNonEmpty === false || $tokens[ $prevNonEmpty ][ 'code' ] !== \T_STRING ) {
382 382
                         return false;
383 383
                     }
384 384
                 }
385 385
 
386 386
                 // Examine what comes after the namespace/parent/self/double colon, if anything.
387
-                return $this->isStaticValue($phpcsFile, $tokens, ($nextNonEmpty + 1), $end, $nestedArrays);
387
+                return $this->isStaticValue( $phpcsFile, $tokens, ( $nextNonEmpty + 1 ), $end, $nestedArrays );
388 388
 
389 389
             case \T_ARRAY:
390 390
             case \T_OPEN_SHORT_ARRAY:
391 391
                 ++$nestedArrays;
392 392
 
393
-                $arrayItems = $this->getFunctionCallParameters($phpcsFile, $nextNonSimple);
394
-                if (empty($arrayItems) === false) {
395
-                    foreach ($arrayItems as $item) {
393
+                $arrayItems = $this->getFunctionCallParameters( $phpcsFile, $nextNonSimple );
394
+                if ( empty( $arrayItems ) === false ) {
395
+                    foreach ( $arrayItems as $item ) {
396 396
                         // Check for a double arrow, but only if it's for this array item, not for a nested array.
397 397
                         $doubleArrow = false;
398 398
 
399 399
                         $maybeDoubleArrow = $phpcsFile->findNext(
400
-                            array(\T_DOUBLE_ARROW, \T_ARRAY, \T_OPEN_SHORT_ARRAY),
401
-                            $item['start'],
402
-                            ($item['end'] + 1)
400
+                            array( \T_DOUBLE_ARROW, \T_ARRAY, \T_OPEN_SHORT_ARRAY ),
401
+                            $item[ 'start' ],
402
+                            ( $item[ 'end' ] + 1 )
403 403
                         );
404
-                        if ($maybeDoubleArrow !== false && $tokens[$maybeDoubleArrow]['code'] === \T_DOUBLE_ARROW) {
404
+                        if ( $maybeDoubleArrow !== false && $tokens[ $maybeDoubleArrow ][ 'code' ] === \T_DOUBLE_ARROW ) {
405 405
                             // Double arrow is for this nesting level.
406 406
                             $doubleArrow = $maybeDoubleArrow;
407 407
                         }
408 408
 
409
-                        if ($doubleArrow === false) {
410
-                            if ($this->isStaticValue($phpcsFile, $tokens, $item['start'], $item['end'], $nestedArrays) === false) {
409
+                        if ( $doubleArrow === false ) {
410
+                            if ( $this->isStaticValue( $phpcsFile, $tokens, $item[ 'start' ], $item[ 'end' ], $nestedArrays ) === false ) {
411 411
                                 return false;
412 412
                             }
413 413
 
414 414
                         } else {
415 415
                             // Examine array key.
416
-                            if ($this->isStaticValue($phpcsFile, $tokens, $item['start'], ($doubleArrow - 1), $nestedArrays) === false) {
416
+                            if ( $this->isStaticValue( $phpcsFile, $tokens, $item[ 'start' ], ( $doubleArrow - 1 ), $nestedArrays ) === false ) {
417 417
                                 return false;
418 418
                             }
419 419
 
420 420
                             // Examine array value.
421
-                            if ($this->isStaticValue($phpcsFile, $tokens, ($doubleArrow + 1), $item['end'], $nestedArrays) === false) {
421
+                            if ( $this->isStaticValue( $phpcsFile, $tokens, ( $doubleArrow + 1 ), $item[ 'end' ], $nestedArrays ) === false ) {
422 422
                                 return false;
423 423
                             }
424 424
                         }
@@ -432,27 +432,27 @@  discard block
 block discarded – undo
432 432
                  * We already know we will have a valid closer as otherwise we wouldn't have been
433 433
                  * able to get the array items.
434 434
                  */
435
-                $closer = ($nextNonSimple + 1);
436
-                if ($tokens[$nextNonSimple]['code'] === \T_OPEN_SHORT_ARRAY
437
-                    && isset($tokens[$nextNonSimple]['bracket_closer']) === true
435
+                $closer = ( $nextNonSimple + 1 );
436
+                if ( $tokens[ $nextNonSimple ][ 'code' ] === \T_OPEN_SHORT_ARRAY
437
+                    && isset( $tokens[ $nextNonSimple ][ 'bracket_closer' ] ) === true
438 438
                 ) {
439
-                    $closer = $tokens[$nextNonSimple]['bracket_closer'];
439
+                    $closer = $tokens[ $nextNonSimple ][ 'bracket_closer' ];
440 440
                 } else {
441
-                    $maybeOpener = $phpcsFile->findNext(Tokens::$emptyTokens, ($nextNonSimple + 1), ($end + 1), true);
442
-                    if ($tokens[$maybeOpener]['code'] === \T_OPEN_PARENTHESIS) {
441
+                    $maybeOpener = $phpcsFile->findNext( Tokens::$emptyTokens, ( $nextNonSimple + 1 ), ( $end + 1 ), true );
442
+                    if ( $tokens[ $maybeOpener ][ 'code' ] === \T_OPEN_PARENTHESIS ) {
443 443
                         $opener = $maybeOpener;
444
-                        if (isset($tokens[$opener]['parenthesis_closer']) === true) {
445
-                            $closer = $tokens[$opener]['parenthesis_closer'];
444
+                        if ( isset( $tokens[ $opener ][ 'parenthesis_closer' ] ) === true ) {
445
+                            $closer = $tokens[ $opener ][ 'parenthesis_closer' ];
446 446
                         }
447 447
                     }
448 448
                 }
449 449
 
450
-                if ($closer === $end) {
450
+                if ( $closer === $end ) {
451 451
                     return true;
452 452
                 }
453 453
 
454 454
                 // Examine what comes after the array, if anything.
455
-                return $this->isStaticValue($phpcsFile, $tokens, ($closer + 1), $end, $nestedArrays);
455
+                return $this->isStaticValue( $phpcsFile, $tokens, ( $closer + 1 ), $end, $nestedArrays );
456 456
 
457 457
         }
458 458
 
@@ -471,25 +471,25 @@  discard block
 block discarded – undo
471 471
      *
472 472
      * @return void
473 473
      */
474
-    protected function throwError(File $phpcsFile, $stackPtr, $type, $content = '')
474
+    protected function throwError( File $phpcsFile, $stackPtr, $type, $content = '' )
475 475
     {
476 476
         $error     = static::ERROR_PHRASE;
477 477
         $phrase    = '';
478 478
         $errorCode = 'Found';
479 479
 
480
-        if (isset($this->errorPhrases[$type]) === true) {
481
-            $errorCode = $this->stringToErrorCode($type) . 'Found';
482
-            $phrase    = $this->errorPhrases[$type];
480
+        if ( isset( $this->errorPhrases[ $type ] ) === true ) {
481
+            $errorCode = $this->stringToErrorCode( $type ) . 'Found';
482
+            $phrase    = $this->errorPhrases[ $type ];
483 483
         }
484 484
 
485
-        $data = array($phrase);
485
+        $data = array( $phrase );
486 486
 
487
-        if (empty($content) === false) {
487
+        if ( empty( $content ) === false ) {
488 488
             $error .= ' Found: %s';
489
-            $data[] = $content;
489
+            $data[ ] = $content;
490 490
         }
491 491
 
492
-        $phpcsFile->addError($error, $stackPtr, $errorCode, $data);
492
+        $phpcsFile->addError( $error, $stackPtr, $errorCode, $data );
493 493
     }
494 494
 
495 495
 
@@ -505,26 +505,26 @@  discard block
 block discarded – undo
505 505
      *
506 506
      * @return bool|int True if this is the real end. Int stackPtr to skip to if not.
507 507
      */
508
-    private function isRealEndOfDeclaration($tokens, $endPtr, $targetLevel)
508
+    private function isRealEndOfDeclaration( $tokens, $endPtr, $targetLevel )
509 509
     {
510 510
         // Ignore anything within short array definition brackets for now.
511
-        if ($tokens[$endPtr]['code'] === \T_OPEN_SHORT_ARRAY
512
-            && (isset($tokens[$endPtr]['bracket_opener'])
513
-                && $tokens[$endPtr]['bracket_opener'] === $endPtr)
514
-            && isset($tokens[$endPtr]['bracket_closer'])
511
+        if ( $tokens[ $endPtr ][ 'code' ] === \T_OPEN_SHORT_ARRAY
512
+            && ( isset( $tokens[ $endPtr ][ 'bracket_opener' ] )
513
+                && $tokens[ $endPtr ][ 'bracket_opener' ] === $endPtr )
514
+            && isset( $tokens[ $endPtr ][ 'bracket_closer' ] )
515 515
         ) {
516 516
             // Skip forward to the end of the short array definition.
517
-            return $tokens[$endPtr]['bracket_closer'];
517
+            return $tokens[ $endPtr ][ 'bracket_closer' ];
518 518
         }
519 519
 
520 520
         // Skip past comma's at a lower nesting level.
521
-        if ($tokens[$endPtr]['code'] === \T_COMMA) {
521
+        if ( $tokens[ $endPtr ][ 'code' ] === \T_COMMA ) {
522 522
             // Check if a comma is at the nesting level we're targetting.
523 523
             $nestingLevel = 0;
524
-            if (isset($tokens[$endPtr]['nested_parenthesis']) === true) {
525
-                $nestingLevel = \count($tokens[$endPtr]['nested_parenthesis']);
524
+            if ( isset( $tokens[ $endPtr ][ 'nested_parenthesis' ] ) === true ) {
525
+                $nestingLevel = \count( $tokens[ $endPtr ][ 'nested_parenthesis' ] );
526 526
             }
527
-            if ($nestingLevel > $targetLevel) {
527
+            if ( $nestingLevel > $targetLevel ) {
528 528
                 return $endPtr;
529 529
             }
530 530
         }
Please login to merge, or discard this patch.
Braces   +9 added lines, -18 removed lines patch added patch discarded remove patch
@@ -30,8 +30,7 @@  discard block
 block discarded – undo
30 30
  * @package  PHPCompatibility
31 31
  * @author   Juliette Reinders Folmer <[email protected]>
32 32
  */
33
-class NewConstantScalarExpressionsSniff extends Sniff
34
-{
33
+class NewConstantScalarExpressionsSniff extends Sniff {
35 34
 
36 35
     /**
37 36
      * Error message.
@@ -91,8 +90,7 @@  discard block
 block discarded – undo
91 90
      *
92 91
      * @return array
93 92
      */
94
-    public function register()
95
-    {
93
+    public function register() {
96 94
         // Set the properties up only once.
97 95
         $this->setProperties();
98 96
 
@@ -111,8 +109,7 @@  discard block
 block discarded – undo
111 109
      *
112 110
      * @return void
113 111
      */
114
-    public function setProperties()
115
-    {
112
+    public function setProperties() {
116 113
         $this->safeOperands += Tokens::$heredocTokens;
117 114
         $this->safeOperands += Tokens::$emptyTokens;
118 115
     }
@@ -123,8 +120,7 @@  discard block
 block discarded – undo
123 120
      *
124 121
      * @return bool
125 122
      */
126
-    protected function bowOutEarly()
127
-    {
123
+    protected function bowOutEarly() {
128 124
         return ($this->supportsBelow('5.5') !== true);
129 125
     }
130 126
 
@@ -138,8 +134,7 @@  discard block
 block discarded – undo
138 134
      *
139 135
      * @return void|int Null or integer stack pointer to skip forward.
140 136
      */
141
-    public function process(File $phpcsFile, $stackPtr)
142
-    {
137
+    public function process(File $phpcsFile, $stackPtr) {
143 138
         if ($this->bowOutEarly() === true) {
144 139
             return;
145 140
         }
@@ -304,8 +299,7 @@  discard block
 block discarded – undo
304 299
      *
305 300
      * @return bool
306 301
      */
307
-    protected function isValidAssignment(File $phpcsFile, $stackPtr, $end)
308
-    {
302
+    protected function isValidAssignment(File $phpcsFile, $stackPtr, $end) {
309 303
         $tokens = $phpcsFile->getTokens();
310 304
         $next   = $phpcsFile->findNext(Tokens::$emptyTokens, ($stackPtr + 1), $end, true);
311 305
         if ($next === false || $tokens[$next]['code'] !== \T_EQUAL) {
@@ -331,8 +325,7 @@  discard block
 block discarded – undo
331 325
      *
332 326
      * @return bool
333 327
      */
334
-    protected function isStaticValue(File $phpcsFile, $tokens, $start, $end, $nestedArrays = 0)
335
-    {
328
+    protected function isStaticValue(File $phpcsFile, $tokens, $start, $end, $nestedArrays = 0) {
336 329
         $nextNonSimple = $phpcsFile->findNext($this->safeOperands, $start, ($end + 1), true);
337 330
         if ($nextNonSimple === false) {
338 331
             return true;
@@ -471,8 +464,7 @@  discard block
 block discarded – undo
471 464
      *
472 465
      * @return void
473 466
      */
474
-    protected function throwError(File $phpcsFile, $stackPtr, $type, $content = '')
475
-    {
467
+    protected function throwError(File $phpcsFile, $stackPtr, $type, $content = '') {
476 468
         $error     = static::ERROR_PHRASE;
477 469
         $phrase    = '';
478 470
         $errorCode = 'Found';
@@ -505,8 +497,7 @@  discard block
 block discarded – undo
505 497
      *
506 498
      * @return bool|int True if this is the real end. Int stackPtr to skip to if not.
507 499
      */
508
-    private function isRealEndOfDeclaration($tokens, $endPtr, $targetLevel)
509
-    {
500
+    private function isRealEndOfDeclaration($tokens, $endPtr, $targetLevel) {
510 501
         // Ignore anything within short array definition brackets for now.
511 502
         if ($tokens[$endPtr]['code'] === \T_OPEN_SHORT_ARRAY
512 503
             && (isset($tokens[$endPtr]['bracket_opener'])
Please login to merge, or discard this patch.
php-compatibility/PHPCompatibility/Sniffs/Keywords/NewKeywordsSniff.php 4 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -301,7 +301,7 @@
 block discarded – undo
301 301
     /**
302 302
      * Get an array of the non-PHP-version array keys used in a sub-array.
303 303
      *
304
-     * @return array
304
+     * @return string[]
305 305
      */
306 306
     protected function getNonVersionArrayKeys()
307 307
     {
Please login to merge, or discard this patch.
Indentation   +323 added lines, -323 removed lines patch added patch discarded remove patch
@@ -25,196 +25,196 @@  discard block
 block discarded – undo
25 25
 class NewKeywordsSniff extends AbstractNewFeatureSniff
26 26
 {
27 27
 
28
-    /**
29
-     * A list of new keywords, not present in older versions.
30
-     *
31
-     * The array lists : version number with false (not present) or true (present).
32
-     * If's sufficient to list the last version which did not contain the keyword.
33
-     *
34
-     * Description will be used as part of the error message.
35
-     * Condition is the name of a callback method within this class or the parent class
36
-     * which checks whether the token complies with a certain condition.
37
-     * The callback function will be passed the $phpcsFile and the $stackPtr.
38
-     * The callback function should return `true` if the condition is met and the
39
-     * error should *not* be thrown.
40
-     *
41
-     * @var array(string => array(string => int|string|null))
42
-     */
43
-    protected $newKeywords = array(
44
-        'T_HALT_COMPILER' => array(
45
-            '5.0'         => false,
46
-            '5.1'         => true,
47
-            'description' => '"__halt_compiler" keyword',
48
-        ),
49
-        'T_CONST' => array(
50
-            '5.2'         => false,
51
-            '5.3'         => true,
52
-            'description' => '"const" keyword',
53
-            'condition'   => 'isClassConstant', // Keyword is only new when not in class context.
54
-        ),
55
-        'T_CALLABLE' => array(
56
-            '5.3'         => false,
57
-            '5.4'         => true,
58
-            'description' => '"callable" keyword',
59
-            'content'     => 'callable',
60
-        ),
61
-        'T_DIR' => array(
62
-            '5.2'         => false,
63
-            '5.3'         => true,
64
-            'description' => '__DIR__ magic constant',
65
-            'content'     => '__DIR__',
66
-        ),
67
-        'T_GOTO' => array(
68
-            '5.2'         => false,
69
-            '5.3'         => true,
70
-            'description' => '"goto" keyword',
71
-            'content'     => 'goto',
72
-        ),
73
-        'T_INSTEADOF' => array(
74
-            '5.3'         => false,
75
-            '5.4'         => true,
76
-            'description' => '"insteadof" keyword (for traits)',
77
-            'content'     => 'insteadof',
78
-        ),
79
-        'T_NAMESPACE' => array(
80
-            '5.2'         => false,
81
-            '5.3'         => true,
82
-            'description' => '"namespace" keyword',
83
-            'content'     => 'namespace',
84
-        ),
85
-        'T_NS_C' => array(
86
-            '5.2'         => false,
87
-            '5.3'         => true,
88
-            'description' => '__NAMESPACE__ magic constant',
89
-            'content'     => '__NAMESPACE__',
90
-        ),
91
-        'T_USE' => array(
92
-            '5.2'         => false,
93
-            '5.3'         => true,
94
-            'description' => '"use" keyword (for traits/namespaces/anonymous functions)',
95
-        ),
96
-        'T_START_NOWDOC' => array(
97
-            '5.2'         => false,
98
-            '5.3'         => true,
99
-            'description' => 'nowdoc functionality',
100
-        ),
101
-        'T_END_NOWDOC' => array(
102
-            '5.2'         => false,
103
-            '5.3'         => true,
104
-            'description' => 'nowdoc functionality',
105
-        ),
106
-        'T_START_HEREDOC' => array(
107
-            '5.2'         => false,
108
-            '5.3'         => true,
109
-            'description' => '(Double) quoted Heredoc identifier',
110
-            'condition'   => 'isNotQuoted', // Heredoc is only new with quoted identifier.
111
-        ),
112
-        'T_TRAIT' => array(
113
-            '5.3'         => false,
114
-            '5.4'         => true,
115
-            'description' => '"trait" keyword',
116
-            'content'     => 'trait',
117
-        ),
118
-        'T_TRAIT_C' => array(
119
-            '5.3'         => false,
120
-            '5.4'         => true,
121
-            'description' => '__TRAIT__ magic constant',
122
-            'content'     => '__TRAIT__',
123
-        ),
124
-        // The specifics for distinguishing between 'yield' and 'yield from' are dealt
125
-        // with in the translation logic.
126
-        // This token has to be placed above the `T_YIELD` token in this array to allow for this.
127
-        'T_YIELD_FROM' => array(
128
-            '5.6'         => false,
129
-            '7.0'         => true,
130
-            'description' => '"yield from" keyword (for generators)',
131
-            'content'     => 'yield',
132
-        ),
133
-        'T_YIELD' => array(
134
-            '5.4'         => false,
135
-            '5.5'         => true,
136
-            'description' => '"yield" keyword (for generators)',
137
-            'content'     => 'yield',
138
-        ),
139
-        'T_FINALLY' => array(
140
-            '5.4'         => false,
141
-            '5.5'         => true,
142
-            'description' => '"finally" keyword (in exception handling)',
143
-            'content'     => 'finally',
144
-        ),
145
-    );
146
-
147
-    /**
148
-     * Translation table for T_STRING tokens.
149
-     *
150
-     * Will be set up from the register() method.
151
-     *
152
-     * @var array(string => string)
153
-     */
154
-    protected $translateContentToToken = array();
155
-
156
-
157
-    /**
158
-     * Returns an array of tokens this test wants to listen for.
159
-     *
160
-     * @return array
161
-     */
162
-    public function register()
163
-    {
164
-        $tokens    = array();
165
-        $translate = array();
166
-        foreach ($this->newKeywords as $token => $versions) {
167
-            if (\defined($token)) {
168
-                $tokens[] = constant($token);
169
-            }
170
-            if (isset($versions['content'])) {
171
-                $translate[strtolower($versions['content'])] = $token;
172
-            }
173
-        }
174
-
175
-        /*
28
+	/**
29
+	 * A list of new keywords, not present in older versions.
30
+	 *
31
+	 * The array lists : version number with false (not present) or true (present).
32
+	 * If's sufficient to list the last version which did not contain the keyword.
33
+	 *
34
+	 * Description will be used as part of the error message.
35
+	 * Condition is the name of a callback method within this class or the parent class
36
+	 * which checks whether the token complies with a certain condition.
37
+	 * The callback function will be passed the $phpcsFile and the $stackPtr.
38
+	 * The callback function should return `true` if the condition is met and the
39
+	 * error should *not* be thrown.
40
+	 *
41
+	 * @var array(string => array(string => int|string|null))
42
+	 */
43
+	protected $newKeywords = array(
44
+		'T_HALT_COMPILER' => array(
45
+			'5.0'         => false,
46
+			'5.1'         => true,
47
+			'description' => '"__halt_compiler" keyword',
48
+		),
49
+		'T_CONST' => array(
50
+			'5.2'         => false,
51
+			'5.3'         => true,
52
+			'description' => '"const" keyword',
53
+			'condition'   => 'isClassConstant', // Keyword is only new when not in class context.
54
+		),
55
+		'T_CALLABLE' => array(
56
+			'5.3'         => false,
57
+			'5.4'         => true,
58
+			'description' => '"callable" keyword',
59
+			'content'     => 'callable',
60
+		),
61
+		'T_DIR' => array(
62
+			'5.2'         => false,
63
+			'5.3'         => true,
64
+			'description' => '__DIR__ magic constant',
65
+			'content'     => '__DIR__',
66
+		),
67
+		'T_GOTO' => array(
68
+			'5.2'         => false,
69
+			'5.3'         => true,
70
+			'description' => '"goto" keyword',
71
+			'content'     => 'goto',
72
+		),
73
+		'T_INSTEADOF' => array(
74
+			'5.3'         => false,
75
+			'5.4'         => true,
76
+			'description' => '"insteadof" keyword (for traits)',
77
+			'content'     => 'insteadof',
78
+		),
79
+		'T_NAMESPACE' => array(
80
+			'5.2'         => false,
81
+			'5.3'         => true,
82
+			'description' => '"namespace" keyword',
83
+			'content'     => 'namespace',
84
+		),
85
+		'T_NS_C' => array(
86
+			'5.2'         => false,
87
+			'5.3'         => true,
88
+			'description' => '__NAMESPACE__ magic constant',
89
+			'content'     => '__NAMESPACE__',
90
+		),
91
+		'T_USE' => array(
92
+			'5.2'         => false,
93
+			'5.3'         => true,
94
+			'description' => '"use" keyword (for traits/namespaces/anonymous functions)',
95
+		),
96
+		'T_START_NOWDOC' => array(
97
+			'5.2'         => false,
98
+			'5.3'         => true,
99
+			'description' => 'nowdoc functionality',
100
+		),
101
+		'T_END_NOWDOC' => array(
102
+			'5.2'         => false,
103
+			'5.3'         => true,
104
+			'description' => 'nowdoc functionality',
105
+		),
106
+		'T_START_HEREDOC' => array(
107
+			'5.2'         => false,
108
+			'5.3'         => true,
109
+			'description' => '(Double) quoted Heredoc identifier',
110
+			'condition'   => 'isNotQuoted', // Heredoc is only new with quoted identifier.
111
+		),
112
+		'T_TRAIT' => array(
113
+			'5.3'         => false,
114
+			'5.4'         => true,
115
+			'description' => '"trait" keyword',
116
+			'content'     => 'trait',
117
+		),
118
+		'T_TRAIT_C' => array(
119
+			'5.3'         => false,
120
+			'5.4'         => true,
121
+			'description' => '__TRAIT__ magic constant',
122
+			'content'     => '__TRAIT__',
123
+		),
124
+		// The specifics for distinguishing between 'yield' and 'yield from' are dealt
125
+		// with in the translation logic.
126
+		// This token has to be placed above the `T_YIELD` token in this array to allow for this.
127
+		'T_YIELD_FROM' => array(
128
+			'5.6'         => false,
129
+			'7.0'         => true,
130
+			'description' => '"yield from" keyword (for generators)',
131
+			'content'     => 'yield',
132
+		),
133
+		'T_YIELD' => array(
134
+			'5.4'         => false,
135
+			'5.5'         => true,
136
+			'description' => '"yield" keyword (for generators)',
137
+			'content'     => 'yield',
138
+		),
139
+		'T_FINALLY' => array(
140
+			'5.4'         => false,
141
+			'5.5'         => true,
142
+			'description' => '"finally" keyword (in exception handling)',
143
+			'content'     => 'finally',
144
+		),
145
+	);
146
+
147
+	/**
148
+	 * Translation table for T_STRING tokens.
149
+	 *
150
+	 * Will be set up from the register() method.
151
+	 *
152
+	 * @var array(string => string)
153
+	 */
154
+	protected $translateContentToToken = array();
155
+
156
+
157
+	/**
158
+	 * Returns an array of tokens this test wants to listen for.
159
+	 *
160
+	 * @return array
161
+	 */
162
+	public function register()
163
+	{
164
+		$tokens    = array();
165
+		$translate = array();
166
+		foreach ($this->newKeywords as $token => $versions) {
167
+			if (\defined($token)) {
168
+				$tokens[] = constant($token);
169
+			}
170
+			if (isset($versions['content'])) {
171
+				$translate[strtolower($versions['content'])] = $token;
172
+			}
173
+		}
174
+
175
+		/*
176 176
          * Deal with tokens not recognized by the PHP version the sniffer is run
177 177
          * under and (not correctly) compensated for by PHPCS.
178 178
          */
179
-        if (empty($translate) === false) {
180
-            $this->translateContentToToken = $translate;
181
-            $tokens[]                      = \T_STRING;
182
-        }
183
-
184
-        return $tokens;
185
-    }
186
-
187
-
188
-    /**
189
-     * Processes this test, when one of its tokens is encountered.
190
-     *
191
-     * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned.
192
-     * @param int                   $stackPtr  The position of the current token in
193
-     *                                         the stack passed in $tokens.
194
-     *
195
-     * @return void
196
-     */
197
-    public function process(File $phpcsFile, $stackPtr)
198
-    {
199
-        $tokens    = $phpcsFile->getTokens();
200
-        $tokenType = $tokens[$stackPtr]['type'];
201
-
202
-        // Allow for dealing with multi-token keywords, like "yield from".
203
-        $end = $stackPtr;
204
-
205
-        // Translate T_STRING token if necessary.
206
-        if ($tokens[$stackPtr]['type'] === 'T_STRING') {
207
-            $content = strtolower($tokens[$stackPtr]['content']);
208
-
209
-            if (isset($this->translateContentToToken[$content]) === false) {
210
-                // Not one of the tokens we're looking for.
211
-                return;
212
-            }
213
-
214
-            $tokenType = $this->translateContentToToken[$content];
215
-        }
216
-
217
-        /*
179
+		if (empty($translate) === false) {
180
+			$this->translateContentToToken = $translate;
181
+			$tokens[]                      = \T_STRING;
182
+		}
183
+
184
+		return $tokens;
185
+	}
186
+
187
+
188
+	/**
189
+	 * Processes this test, when one of its tokens is encountered.
190
+	 *
191
+	 * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned.
192
+	 * @param int                   $stackPtr  The position of the current token in
193
+	 *                                         the stack passed in $tokens.
194
+	 *
195
+	 * @return void
196
+	 */
197
+	public function process(File $phpcsFile, $stackPtr)
198
+	{
199
+		$tokens    = $phpcsFile->getTokens();
200
+		$tokenType = $tokens[$stackPtr]['type'];
201
+
202
+		// Allow for dealing with multi-token keywords, like "yield from".
203
+		$end = $stackPtr;
204
+
205
+		// Translate T_STRING token if necessary.
206
+		if ($tokens[$stackPtr]['type'] === 'T_STRING') {
207
+			$content = strtolower($tokens[$stackPtr]['content']);
208
+
209
+			if (isset($this->translateContentToToken[$content]) === false) {
210
+				// Not one of the tokens we're looking for.
211
+				return;
212
+			}
213
+
214
+			$tokenType = $this->translateContentToToken[$content];
215
+		}
216
+
217
+		/*
218 218
          * Special case: distinguish between `yield` and `yield from`.
219 219
          *
220 220
          * PHPCS currently (at least up to v 3.0.1) does not backfill for the
@@ -227,140 +227,140 @@  discard block
 block discarded – undo
227 227
          * In PHP 7.0+ both are tokenized as their respective token, however,
228 228
          * a multi-line "yield from" is tokenized as two tokens.
229 229
          */
230
-        if ($tokenType === 'T_YIELD') {
231
-            $nextToken = $phpcsFile->findNext(\T_WHITESPACE, ($end + 1), null, true);
232
-            if ($tokens[$nextToken]['code'] === \T_STRING
233
-                && $tokens[$nextToken]['content'] === 'from'
234
-            ) {
235
-                $tokenType = 'T_YIELD_FROM';
236
-                $end       = $nextToken;
237
-            }
238
-            unset($nextToken);
239
-        }
240
-
241
-        if ($tokenType === 'T_YIELD_FROM' && $tokens[($stackPtr - 1)]['type'] === 'T_YIELD_FROM') {
242
-            // Multi-line "yield from", no need to report it twice.
243
-            return;
244
-        }
245
-
246
-        if (isset($this->newKeywords[$tokenType]) === false) {
247
-            return;
248
-        }
249
-
250
-        $nextToken = $phpcsFile->findNext(Tokens::$emptyTokens, ($end + 1), null, true);
251
-        $prevToken = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($stackPtr - 1), null, true);
252
-
253
-        if ($prevToken !== false
254
-            && ($tokens[$prevToken]['code'] === \T_DOUBLE_COLON
255
-            || $tokens[$prevToken]['code'] === \T_OBJECT_OPERATOR)
256
-        ) {
257
-            // Class property of the same name as one of the keywords. Ignore.
258
-            return;
259
-        }
260
-
261
-        // Skip attempts to use keywords as functions or class names - the former
262
-        // will be reported by ForbiddenNamesAsInvokedFunctionsSniff, whilst the
263
-        // latter will be (partially) reported by the ForbiddenNames sniff.
264
-        // Either type will result in false-positives when targetting lower versions
265
-        // of PHP where the name was not reserved, unless we explicitly check for
266
-        // them.
267
-        if (($nextToken === false
268
-                || $tokens[$nextToken]['type'] !== 'T_OPEN_PARENTHESIS')
269
-            && ($prevToken === false
270
-                || $tokens[$prevToken]['type'] !== 'T_CLASS'
271
-                || $tokens[$prevToken]['type'] !== 'T_INTERFACE')
272
-        ) {
273
-            // Skip based on token scope condition.
274
-            if (isset($this->newKeywords[$tokenType]['condition'])
275
-                && \call_user_func(array($this, $this->newKeywords[$tokenType]['condition']), $phpcsFile, $stackPtr) === true
276
-            ) {
277
-                return;
278
-            }
279
-
280
-            $itemInfo = array(
281
-                'name'   => $tokenType,
282
-            );
283
-            $this->handleFeature($phpcsFile, $stackPtr, $itemInfo);
284
-        }
285
-    }
286
-
287
-
288
-    /**
289
-     * Get the relevant sub-array for a specific item from a multi-dimensional array.
290
-     *
291
-     * @param array $itemInfo Base information about the item.
292
-     *
293
-     * @return array Version and other information about the item.
294
-     */
295
-    public function getItemArray(array $itemInfo)
296
-    {
297
-        return $this->newKeywords[$itemInfo['name']];
298
-    }
299
-
300
-
301
-    /**
302
-     * Get an array of the non-PHP-version array keys used in a sub-array.
303
-     *
304
-     * @return array
305
-     */
306
-    protected function getNonVersionArrayKeys()
307
-    {
308
-        return array(
309
-            'description',
310
-            'condition',
311
-            'content',
312
-        );
313
-    }
314
-
315
-
316
-    /**
317
-     * Retrieve the relevant detail (version) information for use in an error message.
318
-     *
319
-     * @param array $itemArray Version and other information about the item.
320
-     * @param array $itemInfo  Base information about the item.
321
-     *
322
-     * @return array
323
-     */
324
-    public function getErrorInfo(array $itemArray, array $itemInfo)
325
-    {
326
-        $errorInfo                = parent::getErrorInfo($itemArray, $itemInfo);
327
-        $errorInfo['description'] = $itemArray['description'];
328
-
329
-        return $errorInfo;
330
-    }
331
-
332
-
333
-    /**
334
-     * Allow for concrete child classes to filter the error data before it's passed to PHPCS.
335
-     *
336
-     * @param array $data      The error data array which was created.
337
-     * @param array $itemInfo  Base information about the item this error message applies to.
338
-     * @param array $errorInfo Detail information about an item this error message applies to.
339
-     *
340
-     * @return array
341
-     */
342
-    protected function filterErrorData(array $data, array $itemInfo, array $errorInfo)
343
-    {
344
-        $data[0] = $errorInfo['description'];
345
-        return $data;
346
-    }
347
-
348
-
349
-    /**
350
-     * Callback for the quoted heredoc identifier condition.
351
-     *
352
-     * A double quoted identifier will have the opening quote on position 3
353
-     * in the string: `<<<"ID"`.
354
-     *
355
-     * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned.
356
-     * @param int                   $stackPtr  The position of the current token in
357
-     *                                         the stack passed in $tokens.
358
-     *
359
-     * @return bool
360
-     */
361
-    public function isNotQuoted(File $phpcsFile, $stackPtr)
362
-    {
363
-        $tokens = $phpcsFile->getTokens();
364
-        return ($tokens[$stackPtr]['content'][3] !== '"');
365
-    }
230
+		if ($tokenType === 'T_YIELD') {
231
+			$nextToken = $phpcsFile->findNext(\T_WHITESPACE, ($end + 1), null, true);
232
+			if ($tokens[$nextToken]['code'] === \T_STRING
233
+				&& $tokens[$nextToken]['content'] === 'from'
234
+			) {
235
+				$tokenType = 'T_YIELD_FROM';
236
+				$end       = $nextToken;
237
+			}
238
+			unset($nextToken);
239
+		}
240
+
241
+		if ($tokenType === 'T_YIELD_FROM' && $tokens[($stackPtr - 1)]['type'] === 'T_YIELD_FROM') {
242
+			// Multi-line "yield from", no need to report it twice.
243
+			return;
244
+		}
245
+
246
+		if (isset($this->newKeywords[$tokenType]) === false) {
247
+			return;
248
+		}
249
+
250
+		$nextToken = $phpcsFile->findNext(Tokens::$emptyTokens, ($end + 1), null, true);
251
+		$prevToken = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($stackPtr - 1), null, true);
252
+
253
+		if ($prevToken !== false
254
+			&& ($tokens[$prevToken]['code'] === \T_DOUBLE_COLON
255
+			|| $tokens[$prevToken]['code'] === \T_OBJECT_OPERATOR)
256
+		) {
257
+			// Class property of the same name as one of the keywords. Ignore.
258
+			return;
259
+		}
260
+
261
+		// Skip attempts to use keywords as functions or class names - the former
262
+		// will be reported by ForbiddenNamesAsInvokedFunctionsSniff, whilst the
263
+		// latter will be (partially) reported by the ForbiddenNames sniff.
264
+		// Either type will result in false-positives when targetting lower versions
265
+		// of PHP where the name was not reserved, unless we explicitly check for
266
+		// them.
267
+		if (($nextToken === false
268
+				|| $tokens[$nextToken]['type'] !== 'T_OPEN_PARENTHESIS')
269
+			&& ($prevToken === false
270
+				|| $tokens[$prevToken]['type'] !== 'T_CLASS'
271
+				|| $tokens[$prevToken]['type'] !== 'T_INTERFACE')
272
+		) {
273
+			// Skip based on token scope condition.
274
+			if (isset($this->newKeywords[$tokenType]['condition'])
275
+				&& \call_user_func(array($this, $this->newKeywords[$tokenType]['condition']), $phpcsFile, $stackPtr) === true
276
+			) {
277
+				return;
278
+			}
279
+
280
+			$itemInfo = array(
281
+				'name'   => $tokenType,
282
+			);
283
+			$this->handleFeature($phpcsFile, $stackPtr, $itemInfo);
284
+		}
285
+	}
286
+
287
+
288
+	/**
289
+	 * Get the relevant sub-array for a specific item from a multi-dimensional array.
290
+	 *
291
+	 * @param array $itemInfo Base information about the item.
292
+	 *
293
+	 * @return array Version and other information about the item.
294
+	 */
295
+	public function getItemArray(array $itemInfo)
296
+	{
297
+		return $this->newKeywords[$itemInfo['name']];
298
+	}
299
+
300
+
301
+	/**
302
+	 * Get an array of the non-PHP-version array keys used in a sub-array.
303
+	 *
304
+	 * @return array
305
+	 */
306
+	protected function getNonVersionArrayKeys()
307
+	{
308
+		return array(
309
+			'description',
310
+			'condition',
311
+			'content',
312
+		);
313
+	}
314
+
315
+
316
+	/**
317
+	 * Retrieve the relevant detail (version) information for use in an error message.
318
+	 *
319
+	 * @param array $itemArray Version and other information about the item.
320
+	 * @param array $itemInfo  Base information about the item.
321
+	 *
322
+	 * @return array
323
+	 */
324
+	public function getErrorInfo(array $itemArray, array $itemInfo)
325
+	{
326
+		$errorInfo                = parent::getErrorInfo($itemArray, $itemInfo);
327
+		$errorInfo['description'] = $itemArray['description'];
328
+
329
+		return $errorInfo;
330
+	}
331
+
332
+
333
+	/**
334
+	 * Allow for concrete child classes to filter the error data before it's passed to PHPCS.
335
+	 *
336
+	 * @param array $data      The error data array which was created.
337
+	 * @param array $itemInfo  Base information about the item this error message applies to.
338
+	 * @param array $errorInfo Detail information about an item this error message applies to.
339
+	 *
340
+	 * @return array
341
+	 */
342
+	protected function filterErrorData(array $data, array $itemInfo, array $errorInfo)
343
+	{
344
+		$data[0] = $errorInfo['description'];
345
+		return $data;
346
+	}
347
+
348
+
349
+	/**
350
+	 * Callback for the quoted heredoc identifier condition.
351
+	 *
352
+	 * A double quoted identifier will have the opening quote on position 3
353
+	 * in the string: `<<<"ID"`.
354
+	 *
355
+	 * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned.
356
+	 * @param int                   $stackPtr  The position of the current token in
357
+	 *                                         the stack passed in $tokens.
358
+	 *
359
+	 * @return bool
360
+	 */
361
+	public function isNotQuoted(File $phpcsFile, $stackPtr)
362
+	{
363
+		$tokens = $phpcsFile->getTokens();
364
+		return ($tokens[$stackPtr]['content'][3] !== '"');
365
+	}
366 366
 }
Please login to merge, or discard this patch.
Spacing   +42 added lines, -42 removed lines patch added patch discarded remove patch
@@ -163,12 +163,12 @@  discard block
 block discarded – undo
163 163
     {
164 164
         $tokens    = array();
165 165
         $translate = array();
166
-        foreach ($this->newKeywords as $token => $versions) {
167
-            if (\defined($token)) {
168
-                $tokens[] = constant($token);
166
+        foreach ( $this->newKeywords as $token => $versions ) {
167
+            if ( \defined( $token ) ) {
168
+                $tokens[ ] = constant( $token );
169 169
             }
170
-            if (isset($versions['content'])) {
171
-                $translate[strtolower($versions['content'])] = $token;
170
+            if ( isset( $versions[ 'content' ] ) ) {
171
+                $translate[ strtolower( $versions[ 'content' ] ) ] = $token;
172 172
             }
173 173
         }
174 174
 
@@ -176,9 +176,9 @@  discard block
 block discarded – undo
176 176
          * Deal with tokens not recognized by the PHP version the sniffer is run
177 177
          * under and (not correctly) compensated for by PHPCS.
178 178
          */
179
-        if (empty($translate) === false) {
179
+        if ( empty( $translate ) === false ) {
180 180
             $this->translateContentToToken = $translate;
181
-            $tokens[]                      = \T_STRING;
181
+            $tokens[ ]                      = \T_STRING;
182 182
         }
183 183
 
184 184
         return $tokens;
@@ -194,24 +194,24 @@  discard block
 block discarded – undo
194 194
      *
195 195
      * @return void
196 196
      */
197
-    public function process(File $phpcsFile, $stackPtr)
197
+    public function process( File $phpcsFile, $stackPtr )
198 198
     {
199 199
         $tokens    = $phpcsFile->getTokens();
200
-        $tokenType = $tokens[$stackPtr]['type'];
200
+        $tokenType = $tokens[ $stackPtr ][ 'type' ];
201 201
 
202 202
         // Allow for dealing with multi-token keywords, like "yield from".
203 203
         $end = $stackPtr;
204 204
 
205 205
         // Translate T_STRING token if necessary.
206
-        if ($tokens[$stackPtr]['type'] === 'T_STRING') {
207
-            $content = strtolower($tokens[$stackPtr]['content']);
206
+        if ( $tokens[ $stackPtr ][ 'type' ] === 'T_STRING' ) {
207
+            $content = strtolower( $tokens[ $stackPtr ][ 'content' ] );
208 208
 
209
-            if (isset($this->translateContentToToken[$content]) === false) {
209
+            if ( isset( $this->translateContentToToken[ $content ] ) === false ) {
210 210
                 // Not one of the tokens we're looking for.
211 211
                 return;
212 212
             }
213 213
 
214
-            $tokenType = $this->translateContentToToken[$content];
214
+            $tokenType = $this->translateContentToToken[ $content ];
215 215
         }
216 216
 
217 217
         /*
@@ -227,32 +227,32 @@  discard block
 block discarded – undo
227 227
          * In PHP 7.0+ both are tokenized as their respective token, however,
228 228
          * a multi-line "yield from" is tokenized as two tokens.
229 229
          */
230
-        if ($tokenType === 'T_YIELD') {
231
-            $nextToken = $phpcsFile->findNext(\T_WHITESPACE, ($end + 1), null, true);
232
-            if ($tokens[$nextToken]['code'] === \T_STRING
233
-                && $tokens[$nextToken]['content'] === 'from'
230
+        if ( $tokenType === 'T_YIELD' ) {
231
+            $nextToken = $phpcsFile->findNext( \T_WHITESPACE, ( $end + 1 ), null, true );
232
+            if ( $tokens[ $nextToken ][ 'code' ] === \T_STRING
233
+                && $tokens[ $nextToken ][ 'content' ] === 'from'
234 234
             ) {
235 235
                 $tokenType = 'T_YIELD_FROM';
236 236
                 $end       = $nextToken;
237 237
             }
238
-            unset($nextToken);
238
+            unset( $nextToken );
239 239
         }
240 240
 
241
-        if ($tokenType === 'T_YIELD_FROM' && $tokens[($stackPtr - 1)]['type'] === 'T_YIELD_FROM') {
241
+        if ( $tokenType === 'T_YIELD_FROM' && $tokens[ ( $stackPtr - 1 ) ][ 'type' ] === 'T_YIELD_FROM' ) {
242 242
             // Multi-line "yield from", no need to report it twice.
243 243
             return;
244 244
         }
245 245
 
246
-        if (isset($this->newKeywords[$tokenType]) === false) {
246
+        if ( isset( $this->newKeywords[ $tokenType ] ) === false ) {
247 247
             return;
248 248
         }
249 249
 
250
-        $nextToken = $phpcsFile->findNext(Tokens::$emptyTokens, ($end + 1), null, true);
251
-        $prevToken = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($stackPtr - 1), null, true);
250
+        $nextToken = $phpcsFile->findNext( Tokens::$emptyTokens, ( $end + 1 ), null, true );
251
+        $prevToken = $phpcsFile->findPrevious( Tokens::$emptyTokens, ( $stackPtr - 1 ), null, true );
252 252
 
253
-        if ($prevToken !== false
254
-            && ($tokens[$prevToken]['code'] === \T_DOUBLE_COLON
255
-            || $tokens[$prevToken]['code'] === \T_OBJECT_OPERATOR)
253
+        if ( $prevToken !== false
254
+            && ( $tokens[ $prevToken ][ 'code' ] === \T_DOUBLE_COLON
255
+            || $tokens[ $prevToken ][ 'code' ] === \T_OBJECT_OPERATOR )
256 256
         ) {
257 257
             // Class property of the same name as one of the keywords. Ignore.
258 258
             return;
@@ -264,15 +264,15 @@  discard block
 block discarded – undo
264 264
         // Either type will result in false-positives when targetting lower versions
265 265
         // of PHP where the name was not reserved, unless we explicitly check for
266 266
         // them.
267
-        if (($nextToken === false
268
-                || $tokens[$nextToken]['type'] !== 'T_OPEN_PARENTHESIS')
269
-            && ($prevToken === false
270
-                || $tokens[$prevToken]['type'] !== 'T_CLASS'
271
-                || $tokens[$prevToken]['type'] !== 'T_INTERFACE')
267
+        if ( ( $nextToken === false
268
+                || $tokens[ $nextToken ][ 'type' ] !== 'T_OPEN_PARENTHESIS' )
269
+            && ( $prevToken === false
270
+                || $tokens[ $prevToken ][ 'type' ] !== 'T_CLASS'
271
+                || $tokens[ $prevToken ][ 'type' ] !== 'T_INTERFACE' )
272 272
         ) {
273 273
             // Skip based on token scope condition.
274
-            if (isset($this->newKeywords[$tokenType]['condition'])
275
-                && \call_user_func(array($this, $this->newKeywords[$tokenType]['condition']), $phpcsFile, $stackPtr) === true
274
+            if ( isset( $this->newKeywords[ $tokenType ][ 'condition' ] )
275
+                && \call_user_func( array( $this, $this->newKeywords[ $tokenType ][ 'condition' ] ), $phpcsFile, $stackPtr ) === true
276 276
             ) {
277 277
                 return;
278 278
             }
@@ -280,7 +280,7 @@  discard block
 block discarded – undo
280 280
             $itemInfo = array(
281 281
                 'name'   => $tokenType,
282 282
             );
283
-            $this->handleFeature($phpcsFile, $stackPtr, $itemInfo);
283
+            $this->handleFeature( $phpcsFile, $stackPtr, $itemInfo );
284 284
         }
285 285
     }
286 286
 
@@ -292,9 +292,9 @@  discard block
 block discarded – undo
292 292
      *
293 293
      * @return array Version and other information about the item.
294 294
      */
295
-    public function getItemArray(array $itemInfo)
295
+    public function getItemArray( array $itemInfo )
296 296
     {
297
-        return $this->newKeywords[$itemInfo['name']];
297
+        return $this->newKeywords[ $itemInfo[ 'name' ] ];
298 298
     }
299 299
 
300 300
 
@@ -321,10 +321,10 @@  discard block
 block discarded – undo
321 321
      *
322 322
      * @return array
323 323
      */
324
-    public function getErrorInfo(array $itemArray, array $itemInfo)
324
+    public function getErrorInfo( array $itemArray, array $itemInfo )
325 325
     {
326
-        $errorInfo                = parent::getErrorInfo($itemArray, $itemInfo);
327
-        $errorInfo['description'] = $itemArray['description'];
326
+        $errorInfo                = parent::getErrorInfo( $itemArray, $itemInfo );
327
+        $errorInfo[ 'description' ] = $itemArray[ 'description' ];
328 328
 
329 329
         return $errorInfo;
330 330
     }
@@ -339,9 +339,9 @@  discard block
 block discarded – undo
339 339
      *
340 340
      * @return array
341 341
      */
342
-    protected function filterErrorData(array $data, array $itemInfo, array $errorInfo)
342
+    protected function filterErrorData( array $data, array $itemInfo, array $errorInfo )
343 343
     {
344
-        $data[0] = $errorInfo['description'];
344
+        $data[ 0 ] = $errorInfo[ 'description' ];
345 345
         return $data;
346 346
     }
347 347
 
@@ -358,9 +358,9 @@  discard block
 block discarded – undo
358 358
      *
359 359
      * @return bool
360 360
      */
361
-    public function isNotQuoted(File $phpcsFile, $stackPtr)
361
+    public function isNotQuoted( File $phpcsFile, $stackPtr )
362 362
     {
363 363
         $tokens = $phpcsFile->getTokens();
364
-        return ($tokens[$stackPtr]['content'][3] !== '"');
364
+        return ( $tokens[ $stackPtr ][ 'content' ][ 3 ] !== '"' );
365 365
     }
366 366
 }
Please login to merge, or discard this patch.
Braces   +8 added lines, -16 removed lines patch added patch discarded remove patch
@@ -22,8 +22,7 @@  discard block
 block discarded – undo
22 22
  * @author    Wim Godden <[email protected]>
23 23
  * @copyright 2013 Cu.be Solutions bvba
24 24
  */
25
-class NewKeywordsSniff extends AbstractNewFeatureSniff
26
-{
25
+class NewKeywordsSniff extends AbstractNewFeatureSniff {
27 26
 
28 27
     /**
29 28
      * A list of new keywords, not present in older versions.
@@ -159,8 +158,7 @@  discard block
 block discarded – undo
159 158
      *
160 159
      * @return array
161 160
      */
162
-    public function register()
163
-    {
161
+    public function register() {
164 162
         $tokens    = array();
165 163
         $translate = array();
166 164
         foreach ($this->newKeywords as $token => $versions) {
@@ -194,8 +192,7 @@  discard block
 block discarded – undo
194 192
      *
195 193
      * @return void
196 194
      */
197
-    public function process(File $phpcsFile, $stackPtr)
198
-    {
195
+    public function process(File $phpcsFile, $stackPtr) {
199 196
         $tokens    = $phpcsFile->getTokens();
200 197
         $tokenType = $tokens[$stackPtr]['type'];
201 198
 
@@ -292,8 +289,7 @@  discard block
 block discarded – undo
292 289
      *
293 290
      * @return array Version and other information about the item.
294 291
      */
295
-    public function getItemArray(array $itemInfo)
296
-    {
292
+    public function getItemArray(array $itemInfo) {
297 293
         return $this->newKeywords[$itemInfo['name']];
298 294
     }
299 295
 
@@ -303,8 +299,7 @@  discard block
 block discarded – undo
303 299
      *
304 300
      * @return array
305 301
      */
306
-    protected function getNonVersionArrayKeys()
307
-    {
302
+    protected function getNonVersionArrayKeys() {
308 303
         return array(
309 304
             'description',
310 305
             'condition',
@@ -321,8 +316,7 @@  discard block
 block discarded – undo
321 316
      *
322 317
      * @return array
323 318
      */
324
-    public function getErrorInfo(array $itemArray, array $itemInfo)
325
-    {
319
+    public function getErrorInfo(array $itemArray, array $itemInfo) {
326 320
         $errorInfo                = parent::getErrorInfo($itemArray, $itemInfo);
327 321
         $errorInfo['description'] = $itemArray['description'];
328 322
 
@@ -339,8 +333,7 @@  discard block
 block discarded – undo
339 333
      *
340 334
      * @return array
341 335
      */
342
-    protected function filterErrorData(array $data, array $itemInfo, array $errorInfo)
343
-    {
336
+    protected function filterErrorData(array $data, array $itemInfo, array $errorInfo) {
344 337
         $data[0] = $errorInfo['description'];
345 338
         return $data;
346 339
     }
@@ -358,8 +351,7 @@  discard block
 block discarded – undo
358 351
      *
359 352
      * @return bool
360 353
      */
361
-    public function isNotQuoted(File $phpcsFile, $stackPtr)
362
-    {
354
+    public function isNotQuoted(File $phpcsFile, $stackPtr) {
363 355
         $tokens = $phpcsFile->getTokens();
364 356
         return ($tokens[$stackPtr]['content'][3] !== '"');
365 357
     }
Please login to merge, or discard this patch.
PHPCompatibility/Sniffs/MethodUse/NewDirectCallsToCloneSniff.php 4 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -35,7 +35,7 @@
 block discarded – undo
35 35
      *
36 36
      * @since 9.1.0
37 37
      *
38
-     * @return array
38
+     * @return integer[]
39 39
      */
40 40
     public function register()
41 41
     {
Please login to merge, or discard this patch.
Indentation   +51 added lines, -51 removed lines patch added patch discarded remove patch
@@ -30,43 +30,43 @@  discard block
 block discarded – undo
30 30
 class NewDirectCallsToCloneSniff extends Sniff
31 31
 {
32 32
 
33
-    /**
34
-     * Returns an array of tokens this test wants to listen for.
35
-     *
36
-     * @since 9.1.0
37
-     *
38
-     * @return array
39
-     */
40
-    public function register()
41
-    {
42
-        return array(
43
-            \T_DOUBLE_COLON,
44
-            \T_OBJECT_OPERATOR,
45
-        );
46
-    }
33
+	/**
34
+	 * Returns an array of tokens this test wants to listen for.
35
+	 *
36
+	 * @since 9.1.0
37
+	 *
38
+	 * @return array
39
+	 */
40
+	public function register()
41
+	{
42
+		return array(
43
+			\T_DOUBLE_COLON,
44
+			\T_OBJECT_OPERATOR,
45
+		);
46
+	}
47 47
 
48
-    /**
49
-     * Processes this test, when one of its tokens is encountered.
50
-     *
51
-     * @since 9.1.0
52
-     *
53
-     * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned.
54
-     * @param int                   $stackPtr  The position of the current token in
55
-     *                                         the stack passed in $tokens.
56
-     *
57
-     * @return void
58
-     */
59
-    public function process(File $phpcsFile, $stackPtr)
60
-    {
61
-        if ($this->supportsBelow('5.6') === false) {
62
-            return;
63
-        }
48
+	/**
49
+	 * Processes this test, when one of its tokens is encountered.
50
+	 *
51
+	 * @since 9.1.0
52
+	 *
53
+	 * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned.
54
+	 * @param int                   $stackPtr  The position of the current token in
55
+	 *                                         the stack passed in $tokens.
56
+	 *
57
+	 * @return void
58
+	 */
59
+	public function process(File $phpcsFile, $stackPtr)
60
+	{
61
+		if ($this->supportsBelow('5.6') === false) {
62
+			return;
63
+		}
64 64
 
65
-        $tokens = $phpcsFile->getTokens();
65
+		$tokens = $phpcsFile->getTokens();
66 66
 
67
-        $nextNonEmpty = $phpcsFile->findNext(Tokens::$emptyTokens, ($stackPtr + 1), null, true);
68
-        if ($nextNonEmpty === false || $tokens[$nextNonEmpty]['code'] !== \T_STRING) {
69
-            /*
67
+		$nextNonEmpty = $phpcsFile->findNext(Tokens::$emptyTokens, ($stackPtr + 1), null, true);
68
+		if ($nextNonEmpty === false || $tokens[$nextNonEmpty]['code'] !== \T_STRING) {
69
+			/*
70 70
              * Not a method call.
71 71
              *
72 72
              * Note: This disregards method calls with the method name in a variable, like:
@@ -74,24 +74,24 @@  discard block
 block discarded – undo
74 74
              *   $obj->$method();
75 75
              * However, that would be very hard to examine reliably anyway.
76 76
              */
77
-            return;
78
-        }
77
+			return;
78
+		}
79 79
 
80
-        if (strtolower($tokens[$nextNonEmpty]['content']) !== '__clone') {
81
-            // Not a call to the __clone() method.
82
-            return;
83
-        }
80
+		if (strtolower($tokens[$nextNonEmpty]['content']) !== '__clone') {
81
+			// Not a call to the __clone() method.
82
+			return;
83
+		}
84 84
 
85
-        $nextNextNonEmpty = $phpcsFile->findNext(Tokens::$emptyTokens, ($nextNonEmpty + 1), null, true);
86
-        if ($nextNextNonEmpty === false || $tokens[$nextNextNonEmpty]['code'] !== \T_OPEN_PARENTHESIS) {
87
-            // Not a method call.
88
-            return;
89
-        }
85
+		$nextNextNonEmpty = $phpcsFile->findNext(Tokens::$emptyTokens, ($nextNonEmpty + 1), null, true);
86
+		if ($nextNextNonEmpty === false || $tokens[$nextNextNonEmpty]['code'] !== \T_OPEN_PARENTHESIS) {
87
+			// Not a method call.
88
+			return;
89
+		}
90 90
 
91
-        $phpcsFile->addError(
92
-            'Direct calls to the __clone() magic method are not allowed in PHP 5.6 or earlier.',
93
-            $nextNonEmpty,
94
-            'Found'
95
-        );
96
-    }
91
+		$phpcsFile->addError(
92
+			'Direct calls to the __clone() magic method are not allowed in PHP 5.6 or earlier.',
93
+			$nextNonEmpty,
94
+			'Found'
95
+		);
96
+	}
97 97
 }
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -56,16 +56,16 @@  discard block
 block discarded – undo
56 56
      *
57 57
      * @return void
58 58
      */
59
-    public function process(File $phpcsFile, $stackPtr)
59
+    public function process( File $phpcsFile, $stackPtr )
60 60
     {
61
-        if ($this->supportsBelow('5.6') === false) {
61
+        if ( $this->supportsBelow( '5.6' ) === false ) {
62 62
             return;
63 63
         }
64 64
 
65 65
         $tokens = $phpcsFile->getTokens();
66 66
 
67
-        $nextNonEmpty = $phpcsFile->findNext(Tokens::$emptyTokens, ($stackPtr + 1), null, true);
68
-        if ($nextNonEmpty === false || $tokens[$nextNonEmpty]['code'] !== \T_STRING) {
67
+        $nextNonEmpty = $phpcsFile->findNext( Tokens::$emptyTokens, ( $stackPtr + 1 ), null, true );
68
+        if ( $nextNonEmpty === false || $tokens[ $nextNonEmpty ][ 'code' ] !== \T_STRING ) {
69 69
             /*
70 70
              * Not a method call.
71 71
              *
@@ -77,13 +77,13 @@  discard block
 block discarded – undo
77 77
             return;
78 78
         }
79 79
 
80
-        if (strtolower($tokens[$nextNonEmpty]['content']) !== '__clone') {
80
+        if ( strtolower( $tokens[ $nextNonEmpty ][ 'content' ] ) !== '__clone' ) {
81 81
             // Not a call to the __clone() method.
82 82
             return;
83 83
         }
84 84
 
85
-        $nextNextNonEmpty = $phpcsFile->findNext(Tokens::$emptyTokens, ($nextNonEmpty + 1), null, true);
86
-        if ($nextNextNonEmpty === false || $tokens[$nextNextNonEmpty]['code'] !== \T_OPEN_PARENTHESIS) {
85
+        $nextNextNonEmpty = $phpcsFile->findNext( Tokens::$emptyTokens, ( $nextNonEmpty + 1 ), null, true );
86
+        if ( $nextNextNonEmpty === false || $tokens[ $nextNextNonEmpty ][ 'code' ] !== \T_OPEN_PARENTHESIS ) {
87 87
             // Not a method call.
88 88
             return;
89 89
         }
Please login to merge, or discard this patch.
Braces   +3 added lines, -6 removed lines patch added patch discarded remove patch
@@ -27,8 +27,7 @@  discard block
 block discarded – undo
27 27
  *
28 28
  * @since 9.1.0
29 29
  */
30
-class NewDirectCallsToCloneSniff extends Sniff
31
-{
30
+class NewDirectCallsToCloneSniff extends Sniff {
32 31
 
33 32
     /**
34 33
      * Returns an array of tokens this test wants to listen for.
@@ -37,8 +36,7 @@  discard block
 block discarded – undo
37 36
      *
38 37
      * @return array
39 38
      */
40
-    public function register()
41
-    {
39
+    public function register() {
42 40
         return array(
43 41
             \T_DOUBLE_COLON,
44 42
             \T_OBJECT_OPERATOR,
@@ -56,8 +54,7 @@  discard block
 block discarded – undo
56 54
      *
57 55
      * @return void
58 56
      */
59
-    public function process(File $phpcsFile, $stackPtr)
60
-    {
57
+    public function process(File $phpcsFile, $stackPtr) {
61 58
         if ($this->supportsBelow('5.6') === false) {
62 59
             return;
63 60
         }
Please login to merge, or discard this patch.
vendor/squizlabs/php_codesniffer/autoload.php 4 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -59,7 +59,7 @@  discard block
 block discarded – undo
59 59
          *
60 60
          * @param string $class The name of the class to load.
61 61
          *
62
-         * @return bool
62
+         * @return null|boolean
63 63
          */
64 64
         public static function load($class)
65 65
         {
@@ -220,7 +220,7 @@  discard block
 block discarded – undo
220 220
         /**
221 221
          * Retrieve the namespaces and paths registered by external standards.
222 222
          *
223
-         * @return array
223
+         * @return string[]
224 224
          */
225 225
         public static function getSearchPaths()
226 226
         {
Please login to merge, or discard this patch.
Indentation   +280 added lines, -280 removed lines patch added patch discarded remove patch
@@ -17,284 +17,284 @@
 block discarded – undo
17 17
 namespace PHP_CodeSniffer;
18 18
 
19 19
 if (class_exists('PHP_CodeSniffer\Autoload', false) === false) {
20
-    class Autoload
21
-    {
22
-
23
-        /**
24
-         * The composer autoloader.
25
-         *
26
-         * @var \Composer\Autoload\ClassLoader
27
-         */
28
-        private static $composerAutoloader = null;
29
-
30
-        /**
31
-         * A mapping of file names to class names.
32
-         *
33
-         * @var array<string, string>
34
-         */
35
-        private static $loadedClasses = [];
36
-
37
-        /**
38
-         * A mapping of class names to file names.
39
-         *
40
-         * @var array<string, string>
41
-         */
42
-        private static $loadedFiles = [];
43
-
44
-        /**
45
-         * A list of additional directories to search during autoloading.
46
-         *
47
-         * This is typically a list of coding standard directories.
48
-         *
49
-         * @var string[]
50
-         */
51
-        private static $searchPaths = [];
52
-
53
-
54
-        /**
55
-         * Loads a class.
56
-         *
57
-         * This method only loads classes that exist in the PHP_CodeSniffer namespace.
58
-         * All other classes are ignored and loaded by subsequent autoloaders.
59
-         *
60
-         * @param string $class The name of the class to load.
61
-         *
62
-         * @return bool
63
-         */
64
-        public static function load($class)
65
-        {
66
-            // Include the composer autoloader if there is one, but re-register it
67
-            // so this autoloader runs before the composer one as we need to include
68
-            // all files so we can figure out what the class/interface/trait name is.
69
-            if (self::$composerAutoloader === null) {
70
-                // Make sure we don't try to load any of Composer's classes
71
-                // while the autoloader is being setup.
72
-                if (strpos($class, 'Composer\\') === 0) {
73
-                    return;
74
-                }
75
-
76
-                if (strpos(__DIR__, 'phar://') !== 0
77
-                    && file_exists(__DIR__.'/../../autoload.php') === true
78
-                ) {
79
-                    self::$composerAutoloader = include __DIR__.'/../../autoload.php';
80
-                    if (self::$composerAutoloader instanceof \Composer\Autoload\ClassLoader) {
81
-                        self::$composerAutoloader->unregister();
82
-                        self::$composerAutoloader->register();
83
-                    } else {
84
-                        // Something went wrong, so keep going without the autoloader
85
-                        // although namespaced sniffs might error.
86
-                        self::$composerAutoloader = false;
87
-                    }
88
-                } else {
89
-                    self::$composerAutoloader = false;
90
-                }
91
-            }//end if
92
-
93
-            $ds   = DIRECTORY_SEPARATOR;
94
-            $path = false;
95
-
96
-            if (substr($class, 0, 16) === 'PHP_CodeSniffer\\') {
97
-                if (substr($class, 0, 22) === 'PHP_CodeSniffer\Tests\\') {
98
-                    $isInstalled = !is_dir(__DIR__.$ds.'tests');
99
-                    if ($isInstalled === false) {
100
-                        $path = __DIR__.$ds.'tests';
101
-                    } else {
102
-                        $path = '@test_dir@'.$ds.'PHP_CodeSniffer'.$ds.'CodeSniffer';
103
-                    }
104
-
105
-                    $path .= $ds.substr(str_replace('\\', $ds, $class), 22).'.php';
106
-                } else {
107
-                    $path = __DIR__.$ds.'src'.$ds.substr(str_replace('\\', $ds, $class), 16).'.php';
108
-                }
109
-            }
110
-
111
-            // See if the composer autoloader knows where the class is.
112
-            if ($path === false && self::$composerAutoloader !== false) {
113
-                $path = self::$composerAutoloader->findFile($class);
114
-            }
115
-
116
-            // See if the class is inside one of our alternate search paths.
117
-            if ($path === false) {
118
-                foreach (self::$searchPaths as $searchPath => $nsPrefix) {
119
-                    $className = $class;
120
-                    if ($nsPrefix !== '' && substr($class, 0, strlen($nsPrefix)) === $nsPrefix) {
121
-                        $className = substr($class, (strlen($nsPrefix) + 1));
122
-                    }
123
-
124
-                    $path = $searchPath.$ds.str_replace('\\', $ds, $className).'.php';
125
-                    if (is_file($path) === true) {
126
-                        break;
127
-                    }
128
-
129
-                    $path = false;
130
-                }
131
-            }
132
-
133
-            if ($path !== false && is_file($path) === true) {
134
-                self::loadFile($path);
135
-                return true;
136
-            }
137
-
138
-            return false;
139
-
140
-        }//end load()
141
-
142
-
143
-        /**
144
-         * Includes a file and tracks what class or interface was loaded as a result.
145
-         *
146
-         * @param string $path The path of the file to load.
147
-         *
148
-         * @return string The fully qualified name of the class in the loaded file.
149
-         */
150
-        public static function loadFile($path)
151
-        {
152
-            if (strpos(__DIR__, 'phar://') !== 0) {
153
-                $path = realpath($path);
154
-                if ($path === false) {
155
-                    return false;
156
-                }
157
-            }
158
-
159
-            if (isset(self::$loadedClasses[$path]) === true) {
160
-                return self::$loadedClasses[$path];
161
-            }
162
-
163
-            $classes    = get_declared_classes();
164
-            $interfaces = get_declared_interfaces();
165
-            $traits     = get_declared_traits();
166
-
167
-            include $path;
168
-
169
-            $className  = null;
170
-            $newClasses = array_reverse(array_diff(get_declared_classes(), $classes));
171
-            foreach ($newClasses as $name) {
172
-                if (isset(self::$loadedFiles[$name]) === false) {
173
-                    $className = $name;
174
-                    break;
175
-                }
176
-            }
177
-
178
-            if ($className === null) {
179
-                $newClasses = array_reverse(array_diff(get_declared_interfaces(), $interfaces));
180
-                foreach ($newClasses as $name) {
181
-                    if (isset(self::$loadedFiles[$name]) === false) {
182
-                        $className = $name;
183
-                        break;
184
-                    }
185
-                }
186
-            }
187
-
188
-            if ($className === null) {
189
-                $newClasses = array_reverse(array_diff(get_declared_traits(), $traits));
190
-                foreach ($newClasses as $name) {
191
-                    if (isset(self::$loadedFiles[$name]) === false) {
192
-                        $className = $name;
193
-                        break;
194
-                    }
195
-                }
196
-            }
197
-
198
-            self::$loadedClasses[$path]    = $className;
199
-            self::$loadedFiles[$className] = $path;
200
-            return self::$loadedClasses[$path];
201
-
202
-        }//end loadFile()
203
-
204
-
205
-        /**
206
-         * Adds a directory to search during autoloading.
207
-         *
208
-         * @param string $path     The path to the directory to search.
209
-         * @param string $nsPrefix The namespace prefix used by files under this path.
210
-         *
211
-         * @return void
212
-         */
213
-        public static function addSearchPath($path, $nsPrefix='')
214
-        {
215
-            self::$searchPaths[$path] = rtrim(trim((string) $nsPrefix), '\\');
216
-
217
-        }//end addSearchPath()
218
-
219
-
220
-        /**
221
-         * Retrieve the namespaces and paths registered by external standards.
222
-         *
223
-         * @return array
224
-         */
225
-        public static function getSearchPaths()
226
-        {
227
-            return self::$searchPaths;
228
-
229
-        }//end getSearchPaths()
230
-
231
-
232
-        /**
233
-         * Gets the class name for the given file path.
234
-         *
235
-         * @param string $path The name of the file.
236
-         *
237
-         * @throws \Exception If the file path has not been loaded.
238
-         * @return string
239
-         */
240
-        public static function getLoadedClassName($path)
241
-        {
242
-            if (isset(self::$loadedClasses[$path]) === false) {
243
-                throw new \Exception("Cannot get class name for $path; file has not been included");
244
-            }
245
-
246
-            return self::$loadedClasses[$path];
247
-
248
-        }//end getLoadedClassName()
249
-
250
-
251
-        /**
252
-         * Gets the file path for the given class name.
253
-         *
254
-         * @param string $class The name of the class.
255
-         *
256
-         * @throws \Exception If the class name has not been loaded
257
-         * @return string
258
-         */
259
-        public static function getLoadedFileName($class)
260
-        {
261
-            if (isset(self::$loadedFiles[$class]) === false) {
262
-                throw new \Exception("Cannot get file name for $class; class has not been included");
263
-            }
264
-
265
-            return self::$loadedFiles[$class];
266
-
267
-        }//end getLoadedFileName()
268
-
269
-
270
-        /**
271
-         * Gets the mapping of file names to class names.
272
-         *
273
-         * @return array<string, string>
274
-         */
275
-        public static function getLoadedClasses()
276
-        {
277
-            return self::$loadedClasses;
278
-
279
-        }//end getLoadedClasses()
280
-
281
-
282
-        /**
283
-         * Gets the mapping of class names to file names.
284
-         *
285
-         * @return array<string, string>
286
-         */
287
-        public static function getLoadedFiles()
288
-        {
289
-            return self::$loadedFiles;
290
-
291
-        }//end getLoadedFiles()
292
-
293
-
294
-    }//end class
295
-
296
-    // Register the autoloader before any existing autoloaders to ensure
297
-    // it gets a chance to hear about every autoload request, and record
298
-    // the file and class name for it.
299
-    spl_autoload_register(__NAMESPACE__.'\Autoload::load', true, true);
20
+	class Autoload
21
+	{
22
+
23
+		/**
24
+		 * The composer autoloader.
25
+		 *
26
+		 * @var \Composer\Autoload\ClassLoader
27
+		 */
28
+		private static $composerAutoloader = null;
29
+
30
+		/**
31
+		 * A mapping of file names to class names.
32
+		 *
33
+		 * @var array<string, string>
34
+		 */
35
+		private static $loadedClasses = [];
36
+
37
+		/**
38
+		 * A mapping of class names to file names.
39
+		 *
40
+		 * @var array<string, string>
41
+		 */
42
+		private static $loadedFiles = [];
43
+
44
+		/**
45
+		 * A list of additional directories to search during autoloading.
46
+		 *
47
+		 * This is typically a list of coding standard directories.
48
+		 *
49
+		 * @var string[]
50
+		 */
51
+		private static $searchPaths = [];
52
+
53
+
54
+		/**
55
+		 * Loads a class.
56
+		 *
57
+		 * This method only loads classes that exist in the PHP_CodeSniffer namespace.
58
+		 * All other classes are ignored and loaded by subsequent autoloaders.
59
+		 *
60
+		 * @param string $class The name of the class to load.
61
+		 *
62
+		 * @return bool
63
+		 */
64
+		public static function load($class)
65
+		{
66
+			// Include the composer autoloader if there is one, but re-register it
67
+			// so this autoloader runs before the composer one as we need to include
68
+			// all files so we can figure out what the class/interface/trait name is.
69
+			if (self::$composerAutoloader === null) {
70
+				// Make sure we don't try to load any of Composer's classes
71
+				// while the autoloader is being setup.
72
+				if (strpos($class, 'Composer\\') === 0) {
73
+					return;
74
+				}
75
+
76
+				if (strpos(__DIR__, 'phar://') !== 0
77
+					&& file_exists(__DIR__.'/../../autoload.php') === true
78
+				) {
79
+					self::$composerAutoloader = include __DIR__.'/../../autoload.php';
80
+					if (self::$composerAutoloader instanceof \Composer\Autoload\ClassLoader) {
81
+						self::$composerAutoloader->unregister();
82
+						self::$composerAutoloader->register();
83
+					} else {
84
+						// Something went wrong, so keep going without the autoloader
85
+						// although namespaced sniffs might error.
86
+						self::$composerAutoloader = false;
87
+					}
88
+				} else {
89
+					self::$composerAutoloader = false;
90
+				}
91
+			}//end if
92
+
93
+			$ds   = DIRECTORY_SEPARATOR;
94
+			$path = false;
95
+
96
+			if (substr($class, 0, 16) === 'PHP_CodeSniffer\\') {
97
+				if (substr($class, 0, 22) === 'PHP_CodeSniffer\Tests\\') {
98
+					$isInstalled = !is_dir(__DIR__.$ds.'tests');
99
+					if ($isInstalled === false) {
100
+						$path = __DIR__.$ds.'tests';
101
+					} else {
102
+						$path = '@test_dir@'.$ds.'PHP_CodeSniffer'.$ds.'CodeSniffer';
103
+					}
104
+
105
+					$path .= $ds.substr(str_replace('\\', $ds, $class), 22).'.php';
106
+				} else {
107
+					$path = __DIR__.$ds.'src'.$ds.substr(str_replace('\\', $ds, $class), 16).'.php';
108
+				}
109
+			}
110
+
111
+			// See if the composer autoloader knows where the class is.
112
+			if ($path === false && self::$composerAutoloader !== false) {
113
+				$path = self::$composerAutoloader->findFile($class);
114
+			}
115
+
116
+			// See if the class is inside one of our alternate search paths.
117
+			if ($path === false) {
118
+				foreach (self::$searchPaths as $searchPath => $nsPrefix) {
119
+					$className = $class;
120
+					if ($nsPrefix !== '' && substr($class, 0, strlen($nsPrefix)) === $nsPrefix) {
121
+						$className = substr($class, (strlen($nsPrefix) + 1));
122
+					}
123
+
124
+					$path = $searchPath.$ds.str_replace('\\', $ds, $className).'.php';
125
+					if (is_file($path) === true) {
126
+						break;
127
+					}
128
+
129
+					$path = false;
130
+				}
131
+			}
132
+
133
+			if ($path !== false && is_file($path) === true) {
134
+				self::loadFile($path);
135
+				return true;
136
+			}
137
+
138
+			return false;
139
+
140
+		}//end load()
141
+
142
+
143
+		/**
144
+		 * Includes a file and tracks what class or interface was loaded as a result.
145
+		 *
146
+		 * @param string $path The path of the file to load.
147
+		 *
148
+		 * @return string The fully qualified name of the class in the loaded file.
149
+		 */
150
+		public static function loadFile($path)
151
+		{
152
+			if (strpos(__DIR__, 'phar://') !== 0) {
153
+				$path = realpath($path);
154
+				if ($path === false) {
155
+					return false;
156
+				}
157
+			}
158
+
159
+			if (isset(self::$loadedClasses[$path]) === true) {
160
+				return self::$loadedClasses[$path];
161
+			}
162
+
163
+			$classes    = get_declared_classes();
164
+			$interfaces = get_declared_interfaces();
165
+			$traits     = get_declared_traits();
166
+
167
+			include $path;
168
+
169
+			$className  = null;
170
+			$newClasses = array_reverse(array_diff(get_declared_classes(), $classes));
171
+			foreach ($newClasses as $name) {
172
+				if (isset(self::$loadedFiles[$name]) === false) {
173
+					$className = $name;
174
+					break;
175
+				}
176
+			}
177
+
178
+			if ($className === null) {
179
+				$newClasses = array_reverse(array_diff(get_declared_interfaces(), $interfaces));
180
+				foreach ($newClasses as $name) {
181
+					if (isset(self::$loadedFiles[$name]) === false) {
182
+						$className = $name;
183
+						break;
184
+					}
185
+				}
186
+			}
187
+
188
+			if ($className === null) {
189
+				$newClasses = array_reverse(array_diff(get_declared_traits(), $traits));
190
+				foreach ($newClasses as $name) {
191
+					if (isset(self::$loadedFiles[$name]) === false) {
192
+						$className = $name;
193
+						break;
194
+					}
195
+				}
196
+			}
197
+
198
+			self::$loadedClasses[$path]    = $className;
199
+			self::$loadedFiles[$className] = $path;
200
+			return self::$loadedClasses[$path];
201
+
202
+		}//end loadFile()
203
+
204
+
205
+		/**
206
+		 * Adds a directory to search during autoloading.
207
+		 *
208
+		 * @param string $path     The path to the directory to search.
209
+		 * @param string $nsPrefix The namespace prefix used by files under this path.
210
+		 *
211
+		 * @return void
212
+		 */
213
+		public static function addSearchPath($path, $nsPrefix='')
214
+		{
215
+			self::$searchPaths[$path] = rtrim(trim((string) $nsPrefix), '\\');
216
+
217
+		}//end addSearchPath()
218
+
219
+
220
+		/**
221
+		 * Retrieve the namespaces and paths registered by external standards.
222
+		 *
223
+		 * @return array
224
+		 */
225
+		public static function getSearchPaths()
226
+		{
227
+			return self::$searchPaths;
228
+
229
+		}//end getSearchPaths()
230
+
231
+
232
+		/**
233
+		 * Gets the class name for the given file path.
234
+		 *
235
+		 * @param string $path The name of the file.
236
+		 *
237
+		 * @throws \Exception If the file path has not been loaded.
238
+		 * @return string
239
+		 */
240
+		public static function getLoadedClassName($path)
241
+		{
242
+			if (isset(self::$loadedClasses[$path]) === false) {
243
+				throw new \Exception("Cannot get class name for $path; file has not been included");
244
+			}
245
+
246
+			return self::$loadedClasses[$path];
247
+
248
+		}//end getLoadedClassName()
249
+
250
+
251
+		/**
252
+		 * Gets the file path for the given class name.
253
+		 *
254
+		 * @param string $class The name of the class.
255
+		 *
256
+		 * @throws \Exception If the class name has not been loaded
257
+		 * @return string
258
+		 */
259
+		public static function getLoadedFileName($class)
260
+		{
261
+			if (isset(self::$loadedFiles[$class]) === false) {
262
+				throw new \Exception("Cannot get file name for $class; class has not been included");
263
+			}
264
+
265
+			return self::$loadedFiles[$class];
266
+
267
+		}//end getLoadedFileName()
268
+
269
+
270
+		/**
271
+		 * Gets the mapping of file names to class names.
272
+		 *
273
+		 * @return array<string, string>
274
+		 */
275
+		public static function getLoadedClasses()
276
+		{
277
+			return self::$loadedClasses;
278
+
279
+		}//end getLoadedClasses()
280
+
281
+
282
+		/**
283
+		 * Gets the mapping of class names to file names.
284
+		 *
285
+		 * @return array<string, string>
286
+		 */
287
+		public static function getLoadedFiles()
288
+		{
289
+			return self::$loadedFiles;
290
+
291
+		}//end getLoadedFiles()
292
+
293
+
294
+	}//end class
295
+
296
+	// Register the autoloader before any existing autoloaders to ensure
297
+	// it gets a chance to hear about every autoload request, and record
298
+	// the file and class name for it.
299
+	spl_autoload_register(__NAMESPACE__.'\Autoload::load', true, true);
300 300
 }//end if
Please login to merge, or discard this patch.
Spacing   +60 added lines, -60 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
 
17 17
 namespace PHP_CodeSniffer;
18 18
 
19
-if (class_exists('PHP_CodeSniffer\Autoload', false) === false) {
19
+if ( class_exists( 'PHP_CodeSniffer\Autoload', false ) === false ) {
20 20
     class Autoload
21 21
     {
22 22
 
@@ -32,14 +32,14 @@  discard block
 block discarded – undo
32 32
          *
33 33
          * @var array<string, string>
34 34
          */
35
-        private static $loadedClasses = [];
35
+        private static $loadedClasses = [ ];
36 36
 
37 37
         /**
38 38
          * A mapping of class names to file names.
39 39
          *
40 40
          * @var array<string, string>
41 41
          */
42
-        private static $loadedFiles = [];
42
+        private static $loadedFiles = [ ];
43 43
 
44 44
         /**
45 45
          * A list of additional directories to search during autoloading.
@@ -48,7 +48,7 @@  discard block
 block discarded – undo
48 48
          *
49 49
          * @var string[]
50 50
          */
51
-        private static $searchPaths = [];
51
+        private static $searchPaths = [ ];
52 52
 
53 53
 
54 54
         /**
@@ -61,23 +61,23 @@  discard block
 block discarded – undo
61 61
          *
62 62
          * @return bool
63 63
          */
64
-        public static function load($class)
64
+        public static function load( $class )
65 65
         {
66 66
             // Include the composer autoloader if there is one, but re-register it
67 67
             // so this autoloader runs before the composer one as we need to include
68 68
             // all files so we can figure out what the class/interface/trait name is.
69
-            if (self::$composerAutoloader === null) {
69
+            if ( self::$composerAutoloader === null ) {
70 70
                 // Make sure we don't try to load any of Composer's classes
71 71
                 // while the autoloader is being setup.
72
-                if (strpos($class, 'Composer\\') === 0) {
72
+                if ( strpos( $class, 'Composer\\' ) === 0 ) {
73 73
                     return;
74 74
                 }
75 75
 
76
-                if (strpos(__DIR__, 'phar://') !== 0
77
-                    && file_exists(__DIR__.'/../../autoload.php') === true
76
+                if ( strpos( __DIR__, 'phar://' ) !== 0
77
+                    && file_exists( __DIR__ . '/../../autoload.php' ) === true
78 78
                 ) {
79
-                    self::$composerAutoloader = include __DIR__.'/../../autoload.php';
80
-                    if (self::$composerAutoloader instanceof \Composer\Autoload\ClassLoader) {
79
+                    self::$composerAutoloader = include __DIR__ . '/../../autoload.php';
80
+                    if ( self::$composerAutoloader instanceof \Composer\Autoload\ClassLoader ) {
81 81
                         self::$composerAutoloader->unregister();
82 82
                         self::$composerAutoloader->register();
83 83
                     } else {
@@ -93,36 +93,36 @@  discard block
 block discarded – undo
93 93
             $ds   = DIRECTORY_SEPARATOR;
94 94
             $path = false;
95 95
 
96
-            if (substr($class, 0, 16) === 'PHP_CodeSniffer\\') {
97
-                if (substr($class, 0, 22) === 'PHP_CodeSniffer\Tests\\') {
98
-                    $isInstalled = !is_dir(__DIR__.$ds.'tests');
99
-                    if ($isInstalled === false) {
100
-                        $path = __DIR__.$ds.'tests';
96
+            if ( substr( $class, 0, 16 ) === 'PHP_CodeSniffer\\' ) {
97
+                if ( substr( $class, 0, 22 ) === 'PHP_CodeSniffer\Tests\\' ) {
98
+                    $isInstalled = ! is_dir( __DIR__ . $ds . 'tests' );
99
+                    if ( $isInstalled === false ) {
100
+                        $path = __DIR__ . $ds . 'tests';
101 101
                     } else {
102
-                        $path = '@test_dir@'.$ds.'PHP_CodeSniffer'.$ds.'CodeSniffer';
102
+                        $path = '@test_dir@' . $ds . 'PHP_CodeSniffer' . $ds . 'CodeSniffer';
103 103
                     }
104 104
 
105
-                    $path .= $ds.substr(str_replace('\\', $ds, $class), 22).'.php';
105
+                    $path .= $ds . substr( str_replace( '\\', $ds, $class ), 22 ) . '.php';
106 106
                 } else {
107
-                    $path = __DIR__.$ds.'src'.$ds.substr(str_replace('\\', $ds, $class), 16).'.php';
107
+                    $path = __DIR__ . $ds . 'src' . $ds . substr( str_replace( '\\', $ds, $class ), 16 ) . '.php';
108 108
                 }
109 109
             }
110 110
 
111 111
             // See if the composer autoloader knows where the class is.
112
-            if ($path === false && self::$composerAutoloader !== false) {
113
-                $path = self::$composerAutoloader->findFile($class);
112
+            if ( $path === false && self::$composerAutoloader !== false ) {
113
+                $path = self::$composerAutoloader->findFile( $class );
114 114
             }
115 115
 
116 116
             // See if the class is inside one of our alternate search paths.
117
-            if ($path === false) {
118
-                foreach (self::$searchPaths as $searchPath => $nsPrefix) {
117
+            if ( $path === false ) {
118
+                foreach ( self::$searchPaths as $searchPath => $nsPrefix ) {
119 119
                     $className = $class;
120
-                    if ($nsPrefix !== '' && substr($class, 0, strlen($nsPrefix)) === $nsPrefix) {
121
-                        $className = substr($class, (strlen($nsPrefix) + 1));
120
+                    if ( $nsPrefix !== '' && substr( $class, 0, strlen( $nsPrefix ) ) === $nsPrefix ) {
121
+                        $className = substr( $class, ( strlen( $nsPrefix ) + 1 ) );
122 122
                     }
123 123
 
124
-                    $path = $searchPath.$ds.str_replace('\\', $ds, $className).'.php';
125
-                    if (is_file($path) === true) {
124
+                    $path = $searchPath . $ds . str_replace( '\\', $ds, $className ) . '.php';
125
+                    if ( is_file( $path ) === true ) {
126 126
                         break;
127 127
                     }
128 128
 
@@ -130,8 +130,8 @@  discard block
 block discarded – undo
130 130
                 }
131 131
             }
132 132
 
133
-            if ($path !== false && is_file($path) === true) {
134
-                self::loadFile($path);
133
+            if ( $path !== false && is_file( $path ) === true ) {
134
+                self::loadFile( $path );
135 135
                 return true;
136 136
             }
137 137
 
@@ -147,17 +147,17 @@  discard block
 block discarded – undo
147 147
          *
148 148
          * @return string The fully qualified name of the class in the loaded file.
149 149
          */
150
-        public static function loadFile($path)
150
+        public static function loadFile( $path )
151 151
         {
152
-            if (strpos(__DIR__, 'phar://') !== 0) {
153
-                $path = realpath($path);
154
-                if ($path === false) {
152
+            if ( strpos( __DIR__, 'phar://' ) !== 0 ) {
153
+                $path = realpath( $path );
154
+                if ( $path === false ) {
155 155
                     return false;
156 156
                 }
157 157
             }
158 158
 
159
-            if (isset(self::$loadedClasses[$path]) === true) {
160
-                return self::$loadedClasses[$path];
159
+            if ( isset( self::$loadedClasses[ $path ] ) === true ) {
160
+                return self::$loadedClasses[ $path ];
161 161
             }
162 162
 
163 163
             $classes    = get_declared_classes();
@@ -167,37 +167,37 @@  discard block
 block discarded – undo
167 167
             include $path;
168 168
 
169 169
             $className  = null;
170
-            $newClasses = array_reverse(array_diff(get_declared_classes(), $classes));
171
-            foreach ($newClasses as $name) {
172
-                if (isset(self::$loadedFiles[$name]) === false) {
170
+            $newClasses = array_reverse( array_diff( get_declared_classes(), $classes ) );
171
+            foreach ( $newClasses as $name ) {
172
+                if ( isset( self::$loadedFiles[ $name ] ) === false ) {
173 173
                     $className = $name;
174 174
                     break;
175 175
                 }
176 176
             }
177 177
 
178
-            if ($className === null) {
179
-                $newClasses = array_reverse(array_diff(get_declared_interfaces(), $interfaces));
180
-                foreach ($newClasses as $name) {
181
-                    if (isset(self::$loadedFiles[$name]) === false) {
178
+            if ( $className === null ) {
179
+                $newClasses = array_reverse( array_diff( get_declared_interfaces(), $interfaces ) );
180
+                foreach ( $newClasses as $name ) {
181
+                    if ( isset( self::$loadedFiles[ $name ] ) === false ) {
182 182
                         $className = $name;
183 183
                         break;
184 184
                     }
185 185
                 }
186 186
             }
187 187
 
188
-            if ($className === null) {
189
-                $newClasses = array_reverse(array_diff(get_declared_traits(), $traits));
190
-                foreach ($newClasses as $name) {
191
-                    if (isset(self::$loadedFiles[$name]) === false) {
188
+            if ( $className === null ) {
189
+                $newClasses = array_reverse( array_diff( get_declared_traits(), $traits ) );
190
+                foreach ( $newClasses as $name ) {
191
+                    if ( isset( self::$loadedFiles[ $name ] ) === false ) {
192 192
                         $className = $name;
193 193
                         break;
194 194
                     }
195 195
                 }
196 196
             }
197 197
 
198
-            self::$loadedClasses[$path]    = $className;
199
-            self::$loadedFiles[$className] = $path;
200
-            return self::$loadedClasses[$path];
198
+            self::$loadedClasses[ $path ]    = $className;
199
+            self::$loadedFiles[ $className ] = $path;
200
+            return self::$loadedClasses[ $path ];
201 201
 
202 202
         }//end loadFile()
203 203
 
@@ -210,9 +210,9 @@  discard block
 block discarded – undo
210 210
          *
211 211
          * @return void
212 212
          */
213
-        public static function addSearchPath($path, $nsPrefix='')
213
+        public static function addSearchPath( $path, $nsPrefix = '' )
214 214
         {
215
-            self::$searchPaths[$path] = rtrim(trim((string) $nsPrefix), '\\');
215
+            self::$searchPaths[ $path ] = rtrim( trim( (string)$nsPrefix ), '\\' );
216 216
 
217 217
         }//end addSearchPath()
218 218
 
@@ -237,13 +237,13 @@  discard block
 block discarded – undo
237 237
          * @throws \Exception If the file path has not been loaded.
238 238
          * @return string
239 239
          */
240
-        public static function getLoadedClassName($path)
240
+        public static function getLoadedClassName( $path )
241 241
         {
242
-            if (isset(self::$loadedClasses[$path]) === false) {
243
-                throw new \Exception("Cannot get class name for $path; file has not been included");
242
+            if ( isset( self::$loadedClasses[ $path ] ) === false ) {
243
+                throw new \Exception( "Cannot get class name for $path; file has not been included" );
244 244
             }
245 245
 
246
-            return self::$loadedClasses[$path];
246
+            return self::$loadedClasses[ $path ];
247 247
 
248 248
         }//end getLoadedClassName()
249 249
 
@@ -256,13 +256,13 @@  discard block
 block discarded – undo
256 256
          * @throws \Exception If the class name has not been loaded
257 257
          * @return string
258 258
          */
259
-        public static function getLoadedFileName($class)
259
+        public static function getLoadedFileName( $class )
260 260
         {
261
-            if (isset(self::$loadedFiles[$class]) === false) {
262
-                throw new \Exception("Cannot get file name for $class; class has not been included");
261
+            if ( isset( self::$loadedFiles[ $class ] ) === false ) {
262
+                throw new \Exception( "Cannot get file name for $class; class has not been included" );
263 263
             }
264 264
 
265
-            return self::$loadedFiles[$class];
265
+            return self::$loadedFiles[ $class ];
266 266
 
267 267
         }//end getLoadedFileName()
268 268
 
@@ -296,5 +296,5 @@  discard block
 block discarded – undo
296 296
     // Register the autoloader before any existing autoloaders to ensure
297 297
     // it gets a chance to hear about every autoload request, and record
298 298
     // the file and class name for it.
299
-    spl_autoload_register(__NAMESPACE__.'\Autoload::load', true, true);
299
+    spl_autoload_register( __NAMESPACE__ . '\Autoload::load', true, true );
300 300
 }//end if
Please login to merge, or discard this patch.
Braces   +9 added lines, -18 removed lines patch added patch discarded remove patch
@@ -17,8 +17,7 @@  discard block
 block discarded – undo
17 17
 namespace PHP_CodeSniffer;
18 18
 
19 19
 if (class_exists('PHP_CodeSniffer\Autoload', false) === false) {
20
-    class Autoload
21
-    {
20
+    class Autoload {
22 21
 
23 22
         /**
24 23
          * The composer autoloader.
@@ -61,8 +60,7 @@  discard block
 block discarded – undo
61 60
          *
62 61
          * @return bool
63 62
          */
64
-        public static function load($class)
65
-        {
63
+        public static function load($class) {
66 64
             // Include the composer autoloader if there is one, but re-register it
67 65
             // so this autoloader runs before the composer one as we need to include
68 66
             // all files so we can figure out what the class/interface/trait name is.
@@ -147,8 +145,7 @@  discard block
 block discarded – undo
147 145
          *
148 146
          * @return string The fully qualified name of the class in the loaded file.
149 147
          */
150
-        public static function loadFile($path)
151
-        {
148
+        public static function loadFile($path) {
152 149
             if (strpos(__DIR__, 'phar://') !== 0) {
153 150
                 $path = realpath($path);
154 151
                 if ($path === false) {
@@ -210,8 +207,7 @@  discard block
 block discarded – undo
210 207
          *
211 208
          * @return void
212 209
          */
213
-        public static function addSearchPath($path, $nsPrefix='')
214
-        {
210
+        public static function addSearchPath($path, $nsPrefix='') {
215 211
             self::$searchPaths[$path] = rtrim(trim((string) $nsPrefix), '\\');
216 212
 
217 213
         }//end addSearchPath()
@@ -222,8 +218,7 @@  discard block
 block discarded – undo
222 218
          *
223 219
          * @return array
224 220
          */
225
-        public static function getSearchPaths()
226
-        {
221
+        public static function getSearchPaths() {
227 222
             return self::$searchPaths;
228 223
 
229 224
         }//end getSearchPaths()
@@ -237,8 +232,7 @@  discard block
 block discarded – undo
237 232
          * @throws \Exception If the file path has not been loaded.
238 233
          * @return string
239 234
          */
240
-        public static function getLoadedClassName($path)
241
-        {
235
+        public static function getLoadedClassName($path) {
242 236
             if (isset(self::$loadedClasses[$path]) === false) {
243 237
                 throw new \Exception("Cannot get class name for $path; file has not been included");
244 238
             }
@@ -256,8 +250,7 @@  discard block
 block discarded – undo
256 250
          * @throws \Exception If the class name has not been loaded
257 251
          * @return string
258 252
          */
259
-        public static function getLoadedFileName($class)
260
-        {
253
+        public static function getLoadedFileName($class) {
261 254
             if (isset(self::$loadedFiles[$class]) === false) {
262 255
                 throw new \Exception("Cannot get file name for $class; class has not been included");
263 256
             }
@@ -272,8 +265,7 @@  discard block
 block discarded – undo
272 265
          *
273 266
          * @return array<string, string>
274 267
          */
275
-        public static function getLoadedClasses()
276
-        {
268
+        public static function getLoadedClasses() {
277 269
             return self::$loadedClasses;
278 270
 
279 271
         }//end getLoadedClasses()
@@ -284,8 +276,7 @@  discard block
 block discarded – undo
284 276
          *
285 277
          * @return array<string, string>
286 278
          */
287
-        public static function getLoadedFiles()
288
-        {
279
+        public static function getLoadedFiles() {
289 280
             return self::$loadedFiles;
290 281
 
291 282
         }//end getLoadedFiles()
Please login to merge, or discard this patch.
vendor/squizlabs/php_codesniffer/src/Files/File.php 5 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -705,7 +705,7 @@  discard block
 block discarded – undo
705 705
      * @param string $error    The error message.
706 706
      * @param int    $line     The line on which the error occurred.
707 707
      * @param string $code     A violation code unique to the sniff message.
708
-     * @param array  $data     Replacements for the error message.
708
+     * @param string[]  $data     Replacements for the error message.
709 709
      * @param int    $severity The severity level for this error. A value of 0
710 710
      *                         will be converted into the default severity level.
711 711
      *
@@ -729,7 +729,7 @@  discard block
 block discarded – undo
729 729
      * @param string $warning  The error message.
730 730
      * @param int    $line     The line on which the warning occurred.
731 731
      * @param string $code     A violation code unique to the sniff message.
732
-     * @param array  $data     Replacements for the warning message.
732
+     * @param string[]  $data     Replacements for the warning message.
733 733
      * @param int    $severity The severity level for this warning. A value of 0 will
734 734
      *                         will be converted into the default severity level.
735 735
      *
Please login to merge, or discard this patch.
Indentation   +2461 added lines, -2461 removed lines patch added patch discarded remove patch
@@ -19,2467 +19,2467 @@
 block discarded – undo
19 19
 class File
20 20
 {
21 21
 
22
-    /**
23
-     * The absolute path to the file associated with this object.
24
-     *
25
-     * @var string
26
-     */
27
-    public $path = '';
28
-
29
-    /**
30
-     * The content of the file.
31
-     *
32
-     * @var string
33
-     */
34
-    protected $content = '';
35
-
36
-    /**
37
-     * The config data for the run.
38
-     *
39
-     * @var \PHP_CodeSniffer\Config
40
-     */
41
-    public $config = null;
42
-
43
-    /**
44
-     * The ruleset used for the run.
45
-     *
46
-     * @var \PHP_CodeSniffer\Ruleset
47
-     */
48
-    public $ruleset = null;
49
-
50
-    /**
51
-     * If TRUE, the entire file is being ignored.
52
-     *
53
-     * @var boolean
54
-     */
55
-    public $ignored = false;
56
-
57
-    /**
58
-     * The EOL character this file uses.
59
-     *
60
-     * @var string
61
-     */
62
-    public $eolChar = '';
63
-
64
-    /**
65
-     * The Fixer object to control fixing errors.
66
-     *
67
-     * @var \PHP_CodeSniffer\Fixer
68
-     */
69
-    public $fixer = null;
70
-
71
-    /**
72
-     * The tokenizer being used for this file.
73
-     *
74
-     * @var \PHP_CodeSniffer\Tokenizers\Tokenizer
75
-     */
76
-    public $tokenizer = null;
77
-
78
-    /**
79
-     * The name of the tokenizer being used for this file.
80
-     *
81
-     * @var string
82
-     */
83
-    public $tokenizerType = 'PHP';
84
-
85
-    /**
86
-     * Was the file loaded from cache?
87
-     *
88
-     * If TRUE, the file was loaded from a local cache.
89
-     * If FALSE, the file was tokenized and processed fully.
90
-     *
91
-     * @var boolean
92
-     */
93
-    public $fromCache = false;
94
-
95
-    /**
96
-     * The number of tokens in this file.
97
-     *
98
-     * Stored here to save calling count() everywhere.
99
-     *
100
-     * @var integer
101
-     */
102
-    public $numTokens = 0;
103
-
104
-    /**
105
-     * The tokens stack map.
106
-     *
107
-     * @var array
108
-     */
109
-    protected $tokens = [];
110
-
111
-    /**
112
-     * The errors raised from sniffs.
113
-     *
114
-     * @var array
115
-     * @see getErrors()
116
-     */
117
-    protected $errors = [];
118
-
119
-    /**
120
-     * The warnings raised from sniffs.
121
-     *
122
-     * @var array
123
-     * @see getWarnings()
124
-     */
125
-    protected $warnings = [];
126
-
127
-    /**
128
-     * The metrics recorded by sniffs.
129
-     *
130
-     * @var array
131
-     * @see getMetrics()
132
-     */
133
-    protected $metrics = [];
134
-
135
-    /**
136
-     * The metrics recorded for each token.
137
-     *
138
-     * Stops the same metric being recorded for the same token twice.
139
-     *
140
-     * @var array
141
-     * @see getMetrics()
142
-     */
143
-    private $metricTokens = [];
144
-
145
-    /**
146
-     * The total number of errors raised.
147
-     *
148
-     * @var integer
149
-     */
150
-    protected $errorCount = 0;
151
-
152
-    /**
153
-     * The total number of warnings raised.
154
-     *
155
-     * @var integer
156
-     */
157
-    protected $warningCount = 0;
158
-
159
-    /**
160
-     * The total number of errors and warnings that can be fixed.
161
-     *
162
-     * @var integer
163
-     */
164
-    protected $fixableCount = 0;
165
-
166
-    /**
167
-     * The total number of errors and warnings that were fixed.
168
-     *
169
-     * @var integer
170
-     */
171
-    protected $fixedCount = 0;
172
-
173
-    /**
174
-     * An array of sniffs that are being ignored.
175
-     *
176
-     * @var array
177
-     */
178
-    protected $ignoredListeners = [];
179
-
180
-    /**
181
-     * An array of message codes that are being ignored.
182
-     *
183
-     * @var array
184
-     */
185
-    protected $ignoredCodes = [];
186
-
187
-    /**
188
-     * An array of sniffs listening to this file's processing.
189
-     *
190
-     * @var \PHP_CodeSniffer\Sniffs\Sniff[]
191
-     */
192
-    protected $listeners = [];
193
-
194
-    /**
195
-     * The class name of the sniff currently processing the file.
196
-     *
197
-     * @var string
198
-     */
199
-    protected $activeListener = '';
200
-
201
-    /**
202
-     * An array of sniffs being processed and how long they took.
203
-     *
204
-     * @var array
205
-     */
206
-    protected $listenerTimes = [];
207
-
208
-    /**
209
-     * A cache of often used config settings to improve performance.
210
-     *
211
-     * Storing them here saves 10k+ calls to __get() in the Config class.
212
-     *
213
-     * @var array
214
-     */
215
-    protected $configCache = [];
216
-
217
-
218
-    /**
219
-     * Constructs a file.
220
-     *
221
-     * @param string                   $path    The absolute path to the file to process.
222
-     * @param \PHP_CodeSniffer\Ruleset $ruleset The ruleset used for the run.
223
-     * @param \PHP_CodeSniffer\Config  $config  The config data for the run.
224
-     *
225
-     * @return void
226
-     */
227
-    public function __construct($path, Ruleset $ruleset, Config $config)
228
-    {
229
-        $this->path    = $path;
230
-        $this->ruleset = $ruleset;
231
-        $this->config  = $config;
232
-        $this->fixer   = new Fixer();
233
-
234
-        $parts     = explode('.', $path);
235
-        $extension = array_pop($parts);
236
-        if (isset($config->extensions[$extension]) === true) {
237
-            $this->tokenizerType = $config->extensions[$extension];
238
-        } else {
239
-            // Revert to default.
240
-            $this->tokenizerType = 'PHP';
241
-        }
242
-
243
-        $this->configCache['cache']           = $this->config->cache;
244
-        $this->configCache['sniffs']          = array_map('strtolower', $this->config->sniffs);
245
-        $this->configCache['exclude']         = array_map('strtolower', $this->config->exclude);
246
-        $this->configCache['errorSeverity']   = $this->config->errorSeverity;
247
-        $this->configCache['warningSeverity'] = $this->config->warningSeverity;
248
-        $this->configCache['recordErrors']    = $this->config->recordErrors;
249
-        $this->configCache['ignorePatterns']  = $this->ruleset->ignorePatterns;
250
-        $this->configCache['includePatterns'] = $this->ruleset->includePatterns;
251
-
252
-    }//end __construct()
253
-
254
-
255
-    /**
256
-     * Set the content of the file.
257
-     *
258
-     * Setting the content also calculates the EOL char being used.
259
-     *
260
-     * @param string $content The file content.
261
-     *
262
-     * @return void
263
-     */
264
-    public function setContent($content)
265
-    {
266
-        $this->content = $content;
267
-        $this->tokens  = [];
268
-
269
-        try {
270
-            $this->eolChar = Util\Common::detectLineEndings($content);
271
-        } catch (RuntimeException $e) {
272
-            $this->addWarningOnLine($e->getMessage(), 1, 'Internal.DetectLineEndings');
273
-            return;
274
-        }
275
-
276
-    }//end setContent()
277
-
278
-
279
-    /**
280
-     * Reloads the content of the file.
281
-     *
282
-     * By default, we have no idea where our content comes from,
283
-     * so we can't do anything.
284
-     *
285
-     * @return void
286
-     */
287
-    public function reloadContent()
288
-    {
289
-
290
-    }//end reloadContent()
291
-
292
-
293
-    /**
294
-     * Disables caching of this file.
295
-     *
296
-     * @return void
297
-     */
298
-    public function disableCaching()
299
-    {
300
-        $this->configCache['cache'] = false;
301
-
302
-    }//end disableCaching()
303
-
304
-
305
-    /**
306
-     * Starts the stack traversal and tells listeners when tokens are found.
307
-     *
308
-     * @return void
309
-     */
310
-    public function process()
311
-    {
312
-        if ($this->ignored === true) {
313
-            return;
314
-        }
315
-
316
-        $this->errors       = [];
317
-        $this->warnings     = [];
318
-        $this->errorCount   = 0;
319
-        $this->warningCount = 0;
320
-        $this->fixableCount = 0;
321
-
322
-        $this->parse();
323
-
324
-        // Check if tokenizer errors cause this file to be ignored.
325
-        if ($this->ignored === true) {
326
-            return;
327
-        }
328
-
329
-        $this->fixer->startFile($this);
330
-
331
-        if (PHP_CODESNIFFER_VERBOSITY > 2) {
332
-            echo "\t*** START TOKEN PROCESSING ***".PHP_EOL;
333
-        }
334
-
335
-        $foundCode        = false;
336
-        $listenerIgnoreTo = [];
337
-        $inTests          = defined('PHP_CODESNIFFER_IN_TESTS');
338
-        $checkAnnotations = $this->config->annotations;
339
-
340
-        // Foreach of the listeners that have registered to listen for this
341
-        // token, get them to process it.
342
-        foreach ($this->tokens as $stackPtr => $token) {
343
-            // Check for ignored lines.
344
-            if ($checkAnnotations === true
345
-                && ($token['code'] === T_COMMENT
346
-                || $token['code'] === T_PHPCS_IGNORE_FILE
347
-                || $token['code'] === T_PHPCS_SET
348
-                || $token['code'] === T_DOC_COMMENT_STRING
349
-                || $token['code'] === T_DOC_COMMENT_TAG
350
-                || ($inTests === true && $token['code'] === T_INLINE_HTML))
351
-            ) {
352
-                $commentText      = ltrim($this->tokens[$stackPtr]['content'], ' /*');
353
-                $commentTextLower = strtolower($commentText);
354
-                if (strpos($commentText, '@codingStandards') !== false) {
355
-                    if (strpos($commentText, '@codingStandardsIgnoreFile') !== false) {
356
-                        // Ignoring the whole file, just a little late.
357
-                        $this->errors       = [];
358
-                        $this->warnings     = [];
359
-                        $this->errorCount   = 0;
360
-                        $this->warningCount = 0;
361
-                        $this->fixableCount = 0;
362
-                        return;
363
-                    } else if (strpos($commentText, '@codingStandardsChangeSetting') !== false) {
364
-                        $start   = strpos($commentText, '@codingStandardsChangeSetting');
365
-                        $comment = substr($commentText, ($start + 30));
366
-                        $parts   = explode(' ', $comment);
367
-                        if (count($parts) >= 2) {
368
-                            $sniffParts = explode('.', $parts[0]);
369
-                            if (count($sniffParts) >= 3) {
370
-                                // If the sniff code is not known to us, it has not been registered in this run.
371
-                                // But don't throw an error as it could be there for a different standard to use.
372
-                                if (isset($this->ruleset->sniffCodes[$parts[0]]) === true) {
373
-                                    $listenerCode  = array_shift($parts);
374
-                                    $propertyCode  = array_shift($parts);
375
-                                    $propertyValue = rtrim(implode(' ', $parts), " */\r\n");
376
-                                    $listenerClass = $this->ruleset->sniffCodes[$listenerCode];
377
-                                    $this->ruleset->setSniffProperty($listenerClass, $propertyCode, $propertyValue);
378
-                                }
379
-                            }
380
-                        }
381
-                    }//end if
382
-                } else if (substr($commentTextLower, 0, 16) === 'phpcs:ignorefile'
383
-                    || substr($commentTextLower, 0, 17) === '@phpcs:ignorefile'
384
-                ) {
385
-                    // Ignoring the whole file, just a little late.
386
-                    $this->errors       = [];
387
-                    $this->warnings     = [];
388
-                    $this->errorCount   = 0;
389
-                    $this->warningCount = 0;
390
-                    $this->fixableCount = 0;
391
-                    return;
392
-                } else if (substr($commentTextLower, 0, 9) === 'phpcs:set'
393
-                    || substr($commentTextLower, 0, 10) === '@phpcs:set'
394
-                ) {
395
-                    if (isset($token['sniffCode']) === true) {
396
-                        $listenerCode = $token['sniffCode'];
397
-                        if (isset($this->ruleset->sniffCodes[$listenerCode]) === true) {
398
-                            $propertyCode  = $token['sniffProperty'];
399
-                            $propertyValue = $token['sniffPropertyValue'];
400
-                            $listenerClass = $this->ruleset->sniffCodes[$listenerCode];
401
-                            $this->ruleset->setSniffProperty($listenerClass, $propertyCode, $propertyValue);
402
-                        }
403
-                    }
404
-                }//end if
405
-            }//end if
406
-
407
-            if (PHP_CODESNIFFER_VERBOSITY > 2) {
408
-                $type    = $token['type'];
409
-                $content = Util\Common::prepareForOutput($token['content']);
410
-                echo "\t\tProcess token $stackPtr: $type => $content".PHP_EOL;
411
-            }
412
-
413
-            if ($token['code'] !== T_INLINE_HTML) {
414
-                $foundCode = true;
415
-            }
416
-
417
-            if (isset($this->ruleset->tokenListeners[$token['code']]) === false) {
418
-                continue;
419
-            }
420
-
421
-            foreach ($this->ruleset->tokenListeners[$token['code']] as $listenerData) {
422
-                if (isset($this->ignoredListeners[$listenerData['class']]) === true
423
-                    || (isset($listenerIgnoreTo[$listenerData['class']]) === true
424
-                    && $listenerIgnoreTo[$listenerData['class']] > $stackPtr)
425
-                ) {
426
-                    // This sniff is ignoring past this token, or the whole file.
427
-                    continue;
428
-                }
429
-
430
-                // Make sure this sniff supports the tokenizer
431
-                // we are currently using.
432
-                $class = $listenerData['class'];
433
-
434
-                if (isset($listenerData['tokenizers'][$this->tokenizerType]) === false) {
435
-                    continue;
436
-                }
437
-
438
-                // If the file path matches one of our ignore patterns, skip it.
439
-                // While there is support for a type of each pattern
440
-                // (absolute or relative) we don't actually support it here.
441
-                foreach ($listenerData['ignore'] as $pattern) {
442
-                    // We assume a / directory separator, as do the exclude rules
443
-                    // most developers write, so we need a special case for any system
444
-                    // that is different.
445
-                    if (DIRECTORY_SEPARATOR === '\\') {
446
-                        $pattern = str_replace('/', '\\\\', $pattern);
447
-                    }
448
-
449
-                    $pattern = '`'.$pattern.'`i';
450
-                    if (preg_match($pattern, $this->path) === 1) {
451
-                        $this->ignoredListeners[$class] = true;
452
-                        continue(2);
453
-                    }
454
-                }
455
-
456
-                // If the file path does not match one of our include patterns, skip it.
457
-                // While there is support for a type of each pattern
458
-                // (absolute or relative) we don't actually support it here.
459
-                if (empty($listenerData['include']) === false) {
460
-                    $included = false;
461
-                    foreach ($listenerData['include'] as $pattern) {
462
-                        // We assume a / directory separator, as do the exclude rules
463
-                        // most developers write, so we need a special case for any system
464
-                        // that is different.
465
-                        if (DIRECTORY_SEPARATOR === '\\') {
466
-                            $pattern = str_replace('/', '\\\\', $pattern);
467
-                        }
468
-
469
-                        $pattern = '`'.$pattern.'`i';
470
-                        if (preg_match($pattern, $this->path) === 1) {
471
-                            $included = true;
472
-                            break;
473
-                        }
474
-                    }
475
-
476
-                    if ($included === false) {
477
-                        $this->ignoredListeners[$class] = true;
478
-                        continue;
479
-                    }
480
-                }//end if
481
-
482
-                $this->activeListener = $class;
483
-
484
-                if (PHP_CODESNIFFER_VERBOSITY > 2) {
485
-                    $startTime = microtime(true);
486
-                    echo "\t\t\tProcessing ".$this->activeListener.'... ';
487
-                }
488
-
489
-                $ignoreTo = $this->ruleset->sniffs[$class]->process($this, $stackPtr);
490
-                if ($ignoreTo !== null) {
491
-                    $listenerIgnoreTo[$this->activeListener] = $ignoreTo;
492
-                }
493
-
494
-                if (PHP_CODESNIFFER_VERBOSITY > 2) {
495
-                    $timeTaken = (microtime(true) - $startTime);
496
-                    if (isset($this->listenerTimes[$this->activeListener]) === false) {
497
-                        $this->listenerTimes[$this->activeListener] = 0;
498
-                    }
499
-
500
-                    $this->listenerTimes[$this->activeListener] += $timeTaken;
501
-
502
-                    $timeTaken = round(($timeTaken), 4);
503
-                    echo "DONE in $timeTaken seconds".PHP_EOL;
504
-                }
505
-
506
-                $this->activeListener = '';
507
-            }//end foreach
508
-        }//end foreach
509
-
510
-        // If short open tags are off but the file being checked uses
511
-        // short open tags, the whole content will be inline HTML
512
-        // and nothing will be checked. So try and handle this case.
513
-        // We don't show this error for STDIN because we can't be sure the content
514
-        // actually came directly from the user. It could be something like
515
-        // refs from a Git pre-push hook.
516
-        if ($foundCode === false && $this->tokenizerType === 'PHP' && $this->path !== 'STDIN') {
517
-            $shortTags = (bool) ini_get('short_open_tag');
518
-            if ($shortTags === false) {
519
-                $error = 'No PHP code was found in this file and short open tags are not allowed by this install of PHP. This file may be using short open tags but PHP does not allow them.';
520
-                $this->addWarning($error, null, 'Internal.NoCodeFound');
521
-            }
522
-        }
523
-
524
-        if (PHP_CODESNIFFER_VERBOSITY > 2) {
525
-            echo "\t*** END TOKEN PROCESSING ***".PHP_EOL;
526
-            echo "\t*** START SNIFF PROCESSING REPORT ***".PHP_EOL;
527
-
528
-            asort($this->listenerTimes, SORT_NUMERIC);
529
-            $this->listenerTimes = array_reverse($this->listenerTimes, true);
530
-            foreach ($this->listenerTimes as $listener => $timeTaken) {
531
-                echo "\t$listener: ".round(($timeTaken), 4).' secs'.PHP_EOL;
532
-            }
533
-
534
-            echo "\t*** END SNIFF PROCESSING REPORT ***".PHP_EOL;
535
-        }
536
-
537
-        $this->fixedCount += $this->fixer->getFixCount();
538
-
539
-    }//end process()
540
-
541
-
542
-    /**
543
-     * Tokenizes the file and prepares it for the test run.
544
-     *
545
-     * @return void
546
-     */
547
-    public function parse()
548
-    {
549
-        if (empty($this->tokens) === false) {
550
-            // File has already been parsed.
551
-            return;
552
-        }
553
-
554
-        try {
555
-            $tokenizerClass  = 'PHP_CodeSniffer\Tokenizers\\'.$this->tokenizerType;
556
-            $this->tokenizer = new $tokenizerClass($this->content, $this->config, $this->eolChar);
557
-            $this->tokens    = $this->tokenizer->getTokens();
558
-        } catch (TokenizerException $e) {
559
-            $this->ignored = true;
560
-            $this->addWarning($e->getMessage(), null, 'Internal.Tokenizer.Exception');
561
-            if (PHP_CODESNIFFER_VERBOSITY > 0) {
562
-                echo "[$this->tokenizerType => tokenizer error]... ";
563
-                if (PHP_CODESNIFFER_VERBOSITY > 1) {
564
-                    echo PHP_EOL;
565
-                }
566
-            }
567
-
568
-            return;
569
-        }
570
-
571
-        $this->numTokens = count($this->tokens);
572
-
573
-        // Check for mixed line endings as these can cause tokenizer errors and we
574
-        // should let the user know that the results they get may be incorrect.
575
-        // This is done by removing all backslashes, removing the newline char we
576
-        // detected, then converting newlines chars into text. If any backslashes
577
-        // are left at the end, we have additional newline chars in use.
578
-        $contents = str_replace('\\', '', $this->content);
579
-        $contents = str_replace($this->eolChar, '', $contents);
580
-        $contents = str_replace("\n", '\n', $contents);
581
-        $contents = str_replace("\r", '\r', $contents);
582
-        if (strpos($contents, '\\') !== false) {
583
-            $error = 'File has mixed line endings; this may cause incorrect results';
584
-            $this->addWarningOnLine($error, 1, 'Internal.LineEndings.Mixed');
585
-        }
586
-
587
-        if (PHP_CODESNIFFER_VERBOSITY > 0) {
588
-            if ($this->numTokens === 0) {
589
-                $numLines = 0;
590
-            } else {
591
-                $numLines = $this->tokens[($this->numTokens - 1)]['line'];
592
-            }
593
-
594
-            echo "[$this->tokenizerType => $this->numTokens tokens in $numLines lines]... ";
595
-            if (PHP_CODESNIFFER_VERBOSITY > 1) {
596
-                echo PHP_EOL;
597
-            }
598
-        }
599
-
600
-    }//end parse()
601
-
602
-
603
-    /**
604
-     * Returns the token stack for this file.
605
-     *
606
-     * @return array
607
-     */
608
-    public function getTokens()
609
-    {
610
-        return $this->tokens;
611
-
612
-    }//end getTokens()
613
-
614
-
615
-    /**
616
-     * Remove vars stored in this file that are no longer required.
617
-     *
618
-     * @return void
619
-     */
620
-    public function cleanUp()
621
-    {
622
-        $this->listenerTimes = null;
623
-        $this->content       = null;
624
-        $this->tokens        = null;
625
-        $this->metricTokens  = null;
626
-        $this->tokenizer     = null;
627
-        $this->fixer         = null;
628
-        $this->config        = null;
629
-        $this->ruleset       = null;
630
-
631
-    }//end cleanUp()
632
-
633
-
634
-    /**
635
-     * Records an error against a specific token in the file.
636
-     *
637
-     * @param string  $error    The error message.
638
-     * @param int     $stackPtr The stack position where the error occurred.
639
-     * @param string  $code     A violation code unique to the sniff message.
640
-     * @param array   $data     Replacements for the error message.
641
-     * @param int     $severity The severity level for this error. A value of 0
642
-     *                          will be converted into the default severity level.
643
-     * @param boolean $fixable  Can the error be fixed by the sniff?
644
-     *
645
-     * @return boolean
646
-     */
647
-    public function addError(
648
-        $error,
649
-        $stackPtr,
650
-        $code,
651
-        $data=[],
652
-        $severity=0,
653
-        $fixable=false
654
-    ) {
655
-        if ($stackPtr === null) {
656
-            $line   = 1;
657
-            $column = 1;
658
-        } else {
659
-            $line   = $this->tokens[$stackPtr]['line'];
660
-            $column = $this->tokens[$stackPtr]['column'];
661
-        }
662
-
663
-        return $this->addMessage(true, $error, $line, $column, $code, $data, $severity, $fixable);
664
-
665
-    }//end addError()
666
-
667
-
668
-    /**
669
-     * Records a warning against a specific token in the file.
670
-     *
671
-     * @param string  $warning  The error message.
672
-     * @param int     $stackPtr The stack position where the error occurred.
673
-     * @param string  $code     A violation code unique to the sniff message.
674
-     * @param array   $data     Replacements for the warning message.
675
-     * @param int     $severity The severity level for this warning. A value of 0
676
-     *                          will be converted into the default severity level.
677
-     * @param boolean $fixable  Can the warning be fixed by the sniff?
678
-     *
679
-     * @return boolean
680
-     */
681
-    public function addWarning(
682
-        $warning,
683
-        $stackPtr,
684
-        $code,
685
-        $data=[],
686
-        $severity=0,
687
-        $fixable=false
688
-    ) {
689
-        if ($stackPtr === null) {
690
-            $line   = 1;
691
-            $column = 1;
692
-        } else {
693
-            $line   = $this->tokens[$stackPtr]['line'];
694
-            $column = $this->tokens[$stackPtr]['column'];
695
-        }
696
-
697
-        return $this->addMessage(false, $warning, $line, $column, $code, $data, $severity, $fixable);
698
-
699
-    }//end addWarning()
700
-
701
-
702
-    /**
703
-     * Records an error against a specific line in the file.
704
-     *
705
-     * @param string $error    The error message.
706
-     * @param int    $line     The line on which the error occurred.
707
-     * @param string $code     A violation code unique to the sniff message.
708
-     * @param array  $data     Replacements for the error message.
709
-     * @param int    $severity The severity level for this error. A value of 0
710
-     *                         will be converted into the default severity level.
711
-     *
712
-     * @return boolean
713
-     */
714
-    public function addErrorOnLine(
715
-        $error,
716
-        $line,
717
-        $code,
718
-        $data=[],
719
-        $severity=0
720
-    ) {
721
-        return $this->addMessage(true, $error, $line, 1, $code, $data, $severity, false);
722
-
723
-    }//end addErrorOnLine()
724
-
725
-
726
-    /**
727
-     * Records a warning against a specific token in the file.
728
-     *
729
-     * @param string $warning  The error message.
730
-     * @param int    $line     The line on which the warning occurred.
731
-     * @param string $code     A violation code unique to the sniff message.
732
-     * @param array  $data     Replacements for the warning message.
733
-     * @param int    $severity The severity level for this warning. A value of 0 will
734
-     *                         will be converted into the default severity level.
735
-     *
736
-     * @return boolean
737
-     */
738
-    public function addWarningOnLine(
739
-        $warning,
740
-        $line,
741
-        $code,
742
-        $data=[],
743
-        $severity=0
744
-    ) {
745
-        return $this->addMessage(false, $warning, $line, 1, $code, $data, $severity, false);
746
-
747
-    }//end addWarningOnLine()
748
-
749
-
750
-    /**
751
-     * Records a fixable error against a specific token in the file.
752
-     *
753
-     * Returns true if the error was recorded and should be fixed.
754
-     *
755
-     * @param string $error    The error message.
756
-     * @param int    $stackPtr The stack position where the error occurred.
757
-     * @param string $code     A violation code unique to the sniff message.
758
-     * @param array  $data     Replacements for the error message.
759
-     * @param int    $severity The severity level for this error. A value of 0
760
-     *                         will be converted into the default severity level.
761
-     *
762
-     * @return boolean
763
-     */
764
-    public function addFixableError(
765
-        $error,
766
-        $stackPtr,
767
-        $code,
768
-        $data=[],
769
-        $severity=0
770
-    ) {
771
-        $recorded = $this->addError($error, $stackPtr, $code, $data, $severity, true);
772
-        if ($recorded === true && $this->fixer->enabled === true) {
773
-            return true;
774
-        }
775
-
776
-        return false;
777
-
778
-    }//end addFixableError()
779
-
780
-
781
-    /**
782
-     * Records a fixable warning against a specific token in the file.
783
-     *
784
-     * Returns true if the warning was recorded and should be fixed.
785
-     *
786
-     * @param string $warning  The error message.
787
-     * @param int    $stackPtr The stack position where the error occurred.
788
-     * @param string $code     A violation code unique to the sniff message.
789
-     * @param array  $data     Replacements for the warning message.
790
-     * @param int    $severity The severity level for this warning. A value of 0
791
-     *                         will be converted into the default severity level.
792
-     *
793
-     * @return boolean
794
-     */
795
-    public function addFixableWarning(
796
-        $warning,
797
-        $stackPtr,
798
-        $code,
799
-        $data=[],
800
-        $severity=0
801
-    ) {
802
-        $recorded = $this->addWarning($warning, $stackPtr, $code, $data, $severity, true);
803
-        if ($recorded === true && $this->fixer->enabled === true) {
804
-            return true;
805
-        }
806
-
807
-        return false;
808
-
809
-    }//end addFixableWarning()
810
-
811
-
812
-    /**
813
-     * Adds an error to the error stack.
814
-     *
815
-     * @param boolean $error    Is this an error message?
816
-     * @param string  $message  The text of the message.
817
-     * @param int     $line     The line on which the message occurred.
818
-     * @param int     $column   The column at which the message occurred.
819
-     * @param string  $code     A violation code unique to the sniff message.
820
-     * @param array   $data     Replacements for the message.
821
-     * @param int     $severity The severity level for this message. A value of 0
822
-     *                          will be converted into the default severity level.
823
-     * @param boolean $fixable  Can the problem be fixed by the sniff?
824
-     *
825
-     * @return boolean
826
-     */
827
-    protected function addMessage($error, $message, $line, $column, $code, $data, $severity, $fixable)
828
-    {
829
-        // Check if this line is ignoring all message codes.
830
-        if (isset($this->tokenizer->ignoredLines[$line]['.all']) === true) {
831
-            return false;
832
-        }
833
-
834
-        // Work out which sniff generated the message.
835
-        $parts = explode('.', $code);
836
-        if ($parts[0] === 'Internal') {
837
-            // An internal message.
838
-            $listenerCode = Util\Common::getSniffCode($this->activeListener);
839
-            $sniffCode    = $code;
840
-            $checkCodes   = [$sniffCode];
841
-        } else {
842
-            if ($parts[0] !== $code) {
843
-                // The full message code has been passed in.
844
-                $sniffCode    = $code;
845
-                $listenerCode = substr($sniffCode, 0, strrpos($sniffCode, '.'));
846
-            } else {
847
-                $listenerCode = Util\Common::getSniffCode($this->activeListener);
848
-                $sniffCode    = $listenerCode.'.'.$code;
849
-                $parts        = explode('.', $sniffCode);
850
-            }
851
-
852
-            $checkCodes = [
853
-                $sniffCode,
854
-                $parts[0].'.'.$parts[1].'.'.$parts[2],
855
-                $parts[0].'.'.$parts[1],
856
-                $parts[0],
857
-            ];
858
-        }//end if
859
-
860
-        if (isset($this->tokenizer->ignoredLines[$line]) === true) {
861
-            // Check if this line is ignoring this specific message.
862
-            $ignored = false;
863
-            foreach ($checkCodes as $checkCode) {
864
-                if (isset($this->tokenizer->ignoredLines[$line][$checkCode]) === true) {
865
-                    $ignored = true;
866
-                    break;
867
-                }
868
-            }
869
-
870
-            // If it is ignored, make sure it's not whitelisted.
871
-            if ($ignored === true
872
-                && isset($this->tokenizer->ignoredLines[$line]['.except']) === true
873
-            ) {
874
-                foreach ($checkCodes as $checkCode) {
875
-                    if (isset($this->tokenizer->ignoredLines[$line]['.except'][$checkCode]) === true) {
876
-                        $ignored = false;
877
-                        break;
878
-                    }
879
-                }
880
-            }
881
-
882
-            if ($ignored === true) {
883
-                return false;
884
-            }
885
-        }//end if
886
-
887
-        $includeAll = true;
888
-        if ($this->configCache['cache'] === false
889
-            || $this->configCache['recordErrors'] === false
890
-        ) {
891
-            $includeAll = false;
892
-        }
893
-
894
-        // Filter out any messages for sniffs that shouldn't have run
895
-        // due to the use of the --sniffs command line argument.
896
-        if ($includeAll === false
897
-            && ((empty($this->configCache['sniffs']) === false
898
-            && in_array(strtolower($listenerCode), $this->configCache['sniffs'], true) === false)
899
-            || (empty($this->configCache['exclude']) === false
900
-            && in_array(strtolower($listenerCode), $this->configCache['exclude'], true) === true))
901
-        ) {
902
-            return false;
903
-        }
904
-
905
-        // If we know this sniff code is being ignored for this file, return early.
906
-        foreach ($checkCodes as $checkCode) {
907
-            if (isset($this->ignoredCodes[$checkCode]) === true) {
908
-                return false;
909
-            }
910
-        }
911
-
912
-        $oppositeType = 'warning';
913
-        if ($error === false) {
914
-            $oppositeType = 'error';
915
-        }
916
-
917
-        foreach ($checkCodes as $checkCode) {
918
-            // Make sure this message type has not been set to the opposite message type.
919
-            if (isset($this->ruleset->ruleset[$checkCode]['type']) === true
920
-                && $this->ruleset->ruleset[$checkCode]['type'] === $oppositeType
921
-            ) {
922
-                $error = !$error;
923
-                break;
924
-            }
925
-        }
926
-
927
-        if ($error === true) {
928
-            $configSeverity = $this->configCache['errorSeverity'];
929
-            $messageCount   = &$this->errorCount;
930
-            $messages       = &$this->errors;
931
-        } else {
932
-            $configSeverity = $this->configCache['warningSeverity'];
933
-            $messageCount   = &$this->warningCount;
934
-            $messages       = &$this->warnings;
935
-        }
936
-
937
-        if ($includeAll === false && $configSeverity === 0) {
938
-            // Don't bother doing any processing as these messages are just going to
939
-            // be hidden in the reports anyway.
940
-            return false;
941
-        }
942
-
943
-        if ($severity === 0) {
944
-            $severity = 5;
945
-        }
946
-
947
-        foreach ($checkCodes as $checkCode) {
948
-            // Make sure we are interested in this severity level.
949
-            if (isset($this->ruleset->ruleset[$checkCode]['severity']) === true) {
950
-                $severity = $this->ruleset->ruleset[$checkCode]['severity'];
951
-                break;
952
-            }
953
-        }
954
-
955
-        if ($includeAll === false && $configSeverity > $severity) {
956
-            return false;
957
-        }
958
-
959
-        // Make sure we are not ignoring this file.
960
-        $included = null;
961
-        foreach ($checkCodes as $checkCode) {
962
-            $patterns = null;
963
-
964
-            if (isset($this->configCache['includePatterns'][$checkCode]) === true) {
965
-                $patterns  = $this->configCache['includePatterns'][$checkCode];
966
-                $excluding = false;
967
-            } else if (isset($this->configCache['ignorePatterns'][$checkCode]) === true) {
968
-                $patterns  = $this->configCache['ignorePatterns'][$checkCode];
969
-                $excluding = true;
970
-            }
971
-
972
-            if ($patterns === null) {
973
-                continue;
974
-            }
975
-
976
-            foreach ($patterns as $pattern => $type) {
977
-                // While there is support for a type of each pattern
978
-                // (absolute or relative) we don't actually support it here.
979
-                $replacements = [
980
-                    '\\,' => ',',
981
-                    '*'   => '.*',
982
-                ];
983
-
984
-                // We assume a / directory separator, as do the exclude rules
985
-                // most developers write, so we need a special case for any system
986
-                // that is different.
987
-                if (DIRECTORY_SEPARATOR === '\\') {
988
-                    $replacements['/'] = '\\\\';
989
-                }
990
-
991
-                $pattern = '`'.strtr($pattern, $replacements).'`i';
992
-                $matched = preg_match($pattern, $this->path);
993
-
994
-                if ($matched === 0) {
995
-                    if ($excluding === false && $included === null) {
996
-                        // This file path is not being included.
997
-                        $included = false;
998
-                    }
999
-
1000
-                    continue;
1001
-                }
1002
-
1003
-                if ($excluding === true) {
1004
-                    // This file path is being excluded.
1005
-                    $this->ignoredCodes[$checkCode] = true;
1006
-                    return false;
1007
-                }
1008
-
1009
-                // This file path is being included.
1010
-                $included = true;
1011
-                break;
1012
-            }//end foreach
1013
-        }//end foreach
1014
-
1015
-        if ($included === false) {
1016
-            // There were include rules set, but this file
1017
-            // path didn't match any of them.
1018
-            return false;
1019
-        }
1020
-
1021
-        $messageCount++;
1022
-        if ($fixable === true) {
1023
-            $this->fixableCount++;
1024
-        }
1025
-
1026
-        if ($this->configCache['recordErrors'] === false
1027
-            && $includeAll === false
1028
-        ) {
1029
-            return true;
1030
-        }
1031
-
1032
-        // Work out the error message.
1033
-        if (isset($this->ruleset->ruleset[$sniffCode]['message']) === true) {
1034
-            $message = $this->ruleset->ruleset[$sniffCode]['message'];
1035
-        }
1036
-
1037
-        if (empty($data) === false) {
1038
-            $message = vsprintf($message, $data);
1039
-        }
1040
-
1041
-        if (isset($messages[$line]) === false) {
1042
-            $messages[$line] = [];
1043
-        }
1044
-
1045
-        if (isset($messages[$line][$column]) === false) {
1046
-            $messages[$line][$column] = [];
1047
-        }
1048
-
1049
-        $messages[$line][$column][] = [
1050
-            'message'  => $message,
1051
-            'source'   => $sniffCode,
1052
-            'listener' => $this->activeListener,
1053
-            'severity' => $severity,
1054
-            'fixable'  => $fixable,
1055
-        ];
1056
-
1057
-        if (PHP_CODESNIFFER_VERBOSITY > 1
1058
-            && $this->fixer->enabled === true
1059
-            && $fixable === true
1060
-        ) {
1061
-            @ob_end_clean();
1062
-            echo "\tE: [Line $line] $message ($sniffCode)".PHP_EOL;
1063
-            ob_start();
1064
-        }
1065
-
1066
-        return true;
1067
-
1068
-    }//end addMessage()
1069
-
1070
-
1071
-    /**
1072
-     * Record a metric about the file being examined.
1073
-     *
1074
-     * @param int    $stackPtr The stack position where the metric was recorded.
1075
-     * @param string $metric   The name of the metric being recorded.
1076
-     * @param string $value    The value of the metric being recorded.
1077
-     *
1078
-     * @return boolean
1079
-     */
1080
-    public function recordMetric($stackPtr, $metric, $value)
1081
-    {
1082
-        if (isset($this->metrics[$metric]) === false) {
1083
-            $this->metrics[$metric] = ['values' => [$value => 1]];
1084
-            $this->metricTokens[$metric][$stackPtr] = true;
1085
-        } else if (isset($this->metricTokens[$metric][$stackPtr]) === false) {
1086
-            $this->metricTokens[$metric][$stackPtr] = true;
1087
-            if (isset($this->metrics[$metric]['values'][$value]) === false) {
1088
-                $this->metrics[$metric]['values'][$value] = 1;
1089
-            } else {
1090
-                $this->metrics[$metric]['values'][$value]++;
1091
-            }
1092
-        }
1093
-
1094
-        return true;
1095
-
1096
-    }//end recordMetric()
1097
-
1098
-
1099
-    /**
1100
-     * Returns the number of errors raised.
1101
-     *
1102
-     * @return int
1103
-     */
1104
-    public function getErrorCount()
1105
-    {
1106
-        return $this->errorCount;
1107
-
1108
-    }//end getErrorCount()
1109
-
1110
-
1111
-    /**
1112
-     * Returns the number of warnings raised.
1113
-     *
1114
-     * @return int
1115
-     */
1116
-    public function getWarningCount()
1117
-    {
1118
-        return $this->warningCount;
1119
-
1120
-    }//end getWarningCount()
1121
-
1122
-
1123
-    /**
1124
-     * Returns the number of fixable errors/warnings raised.
1125
-     *
1126
-     * @return int
1127
-     */
1128
-    public function getFixableCount()
1129
-    {
1130
-        return $this->fixableCount;
1131
-
1132
-    }//end getFixableCount()
1133
-
1134
-
1135
-    /**
1136
-     * Returns the number of fixed errors/warnings.
1137
-     *
1138
-     * @return int
1139
-     */
1140
-    public function getFixedCount()
1141
-    {
1142
-        return $this->fixedCount;
1143
-
1144
-    }//end getFixedCount()
1145
-
1146
-
1147
-    /**
1148
-     * Returns the list of ignored lines.
1149
-     *
1150
-     * @return array
1151
-     */
1152
-    public function getIgnoredLines()
1153
-    {
1154
-        return $this->tokenizer->ignoredLines;
1155
-
1156
-    }//end getIgnoredLines()
1157
-
1158
-
1159
-    /**
1160
-     * Returns the errors raised from processing this file.
1161
-     *
1162
-     * @return array
1163
-     */
1164
-    public function getErrors()
1165
-    {
1166
-        return $this->errors;
1167
-
1168
-    }//end getErrors()
1169
-
1170
-
1171
-    /**
1172
-     * Returns the warnings raised from processing this file.
1173
-     *
1174
-     * @return array
1175
-     */
1176
-    public function getWarnings()
1177
-    {
1178
-        return $this->warnings;
1179
-
1180
-    }//end getWarnings()
1181
-
1182
-
1183
-    /**
1184
-     * Returns the metrics found while processing this file.
1185
-     *
1186
-     * @return array
1187
-     */
1188
-    public function getMetrics()
1189
-    {
1190
-        return $this->metrics;
1191
-
1192
-    }//end getMetrics()
1193
-
1194
-
1195
-    /**
1196
-     * Returns the absolute filename of this file.
1197
-     *
1198
-     * @return string
1199
-     */
1200
-    public function getFilename()
1201
-    {
1202
-        return $this->path;
1203
-
1204
-    }//end getFilename()
1205
-
1206
-
1207
-    /**
1208
-     * Returns the declaration names for classes, interfaces, traits, and functions.
1209
-     *
1210
-     * @param int $stackPtr The position of the declaration token which
1211
-     *                      declared the class, interface, trait, or function.
1212
-     *
1213
-     * @return string|null The name of the class, interface, trait, or function;
1214
-     *                     or NULL if the function or class is anonymous.
1215
-     * @throws \PHP_CodeSniffer\Exceptions\RuntimeException If the specified token is not of type
1216
-     *                                                      T_FUNCTION, T_CLASS, T_ANON_CLASS,
1217
-     *                                                      T_CLOSURE, T_TRAIT, or T_INTERFACE.
1218
-     */
1219
-    public function getDeclarationName($stackPtr)
1220
-    {
1221
-        $tokenCode = $this->tokens[$stackPtr]['code'];
1222
-
1223
-        if ($tokenCode === T_ANON_CLASS || $tokenCode === T_CLOSURE) {
1224
-            return null;
1225
-        }
1226
-
1227
-        if ($tokenCode !== T_FUNCTION
1228
-            && $tokenCode !== T_CLASS
1229
-            && $tokenCode !== T_INTERFACE
1230
-            && $tokenCode !== T_TRAIT
1231
-        ) {
1232
-            throw new RuntimeException('Token type "'.$this->tokens[$stackPtr]['type'].'" is not T_FUNCTION, T_CLASS, T_INTERFACE or T_TRAIT');
1233
-        }
1234
-
1235
-        if ($tokenCode === T_FUNCTION
1236
-            && strtolower($this->tokens[$stackPtr]['content']) !== 'function'
1237
-        ) {
1238
-            // This is a function declared without the "function" keyword.
1239
-            // So this token is the function name.
1240
-            return $this->tokens[$stackPtr]['content'];
1241
-        }
1242
-
1243
-        $content = null;
1244
-        for ($i = $stackPtr; $i < $this->numTokens; $i++) {
1245
-            if ($this->tokens[$i]['code'] === T_STRING) {
1246
-                $content = $this->tokens[$i]['content'];
1247
-                break;
1248
-            }
1249
-        }
1250
-
1251
-        return $content;
1252
-
1253
-    }//end getDeclarationName()
1254
-
1255
-
1256
-    /**
1257
-     * Returns the method parameters for the specified function token.
1258
-     *
1259
-     * Each parameter is in the following format:
1260
-     *
1261
-     * <code>
1262
-     *   0 => array(
1263
-     *         'name'              => '$var',  // The variable name.
1264
-     *         'token'             => integer, // The stack pointer to the variable name.
1265
-     *         'content'           => string,  // The full content of the variable definition.
1266
-     *         'pass_by_reference' => boolean, // Is the variable passed by reference?
1267
-     *         'variable_length'   => boolean, // Is the param of variable length through use of `...` ?
1268
-     *         'type_hint'         => string,  // The type hint for the variable.
1269
-     *         'type_hint_token'   => integer, // The stack pointer to the type hint
1270
-     *                                         // or false if there is no type hint.
1271
-     *         'nullable_type'     => boolean, // Is the variable using a nullable type?
1272
-     *        )
1273
-     * </code>
1274
-     *
1275
-     * Parameters with default values have an additional array index of
1276
-     * 'default' with the value of the default as a string.
1277
-     *
1278
-     * @param int $stackPtr The position in the stack of the function token
1279
-     *                      to acquire the parameters for.
1280
-     *
1281
-     * @return array
1282
-     * @throws \PHP_CodeSniffer\Exceptions\TokenizerException If the specified $stackPtr is not of
1283
-     *                                                        type T_FUNCTION or T_CLOSURE.
1284
-     */
1285
-    public function getMethodParameters($stackPtr)
1286
-    {
1287
-        if ($this->tokens[$stackPtr]['code'] !== T_FUNCTION
1288
-            && $this->tokens[$stackPtr]['code'] !== T_CLOSURE
1289
-        ) {
1290
-            throw new TokenizerException('$stackPtr must be of type T_FUNCTION or T_CLOSURE');
1291
-        }
1292
-
1293
-        $opener = $this->tokens[$stackPtr]['parenthesis_opener'];
1294
-        $closer = $this->tokens[$stackPtr]['parenthesis_closer'];
1295
-
1296
-        $vars            = [];
1297
-        $currVar         = null;
1298
-        $paramStart      = ($opener + 1);
1299
-        $defaultStart    = null;
1300
-        $paramCount      = 0;
1301
-        $passByReference = false;
1302
-        $variableLength  = false;
1303
-        $typeHint        = '';
1304
-        $typeHintToken   = false;
1305
-        $nullableType    = false;
1306
-
1307
-        for ($i = $paramStart; $i <= $closer; $i++) {
1308
-            // Check to see if this token has a parenthesis or bracket opener. If it does
1309
-            // it's likely to be an array which might have arguments in it. This
1310
-            // could cause problems in our parsing below, so lets just skip to the
1311
-            // end of it.
1312
-            if (isset($this->tokens[$i]['parenthesis_opener']) === true) {
1313
-                // Don't do this if it's the close parenthesis for the method.
1314
-                if ($i !== $this->tokens[$i]['parenthesis_closer']) {
1315
-                    $i = ($this->tokens[$i]['parenthesis_closer'] + 1);
1316
-                }
1317
-            }
1318
-
1319
-            if (isset($this->tokens[$i]['bracket_opener']) === true) {
1320
-                // Don't do this if it's the close parenthesis for the method.
1321
-                if ($i !== $this->tokens[$i]['bracket_closer']) {
1322
-                    $i = ($this->tokens[$i]['bracket_closer'] + 1);
1323
-                }
1324
-            }
1325
-
1326
-            switch ($this->tokens[$i]['code']) {
1327
-            case T_BITWISE_AND:
1328
-                if ($defaultStart === null) {
1329
-                    $passByReference = true;
1330
-                }
1331
-                break;
1332
-            case T_VARIABLE:
1333
-                $currVar = $i;
1334
-                break;
1335
-            case T_ELLIPSIS:
1336
-                $variableLength = true;
1337
-                break;
1338
-            case T_CALLABLE:
1339
-                if ($typeHintToken === false) {
1340
-                    $typeHintToken = $i;
1341
-                }
1342
-
1343
-                $typeHint .= $this->tokens[$i]['content'];
1344
-                break;
1345
-            case T_SELF:
1346
-            case T_PARENT:
1347
-            case T_STATIC:
1348
-                // Self and parent are valid, static invalid, but was probably intended as type hint.
1349
-                if (isset($defaultStart) === false) {
1350
-                    if ($typeHintToken === false) {
1351
-                        $typeHintToken = $i;
1352
-                    }
1353
-
1354
-                    $typeHint .= $this->tokens[$i]['content'];
1355
-                }
1356
-                break;
1357
-            case T_STRING:
1358
-                // This is a string, so it may be a type hint, but it could
1359
-                // also be a constant used as a default value.
1360
-                $prevComma = false;
1361
-                for ($t = $i; $t >= $opener; $t--) {
1362
-                    if ($this->tokens[$t]['code'] === T_COMMA) {
1363
-                        $prevComma = $t;
1364
-                        break;
1365
-                    }
1366
-                }
1367
-
1368
-                if ($prevComma !== false) {
1369
-                    $nextEquals = false;
1370
-                    for ($t = $prevComma; $t < $i; $t++) {
1371
-                        if ($this->tokens[$t]['code'] === T_EQUAL) {
1372
-                            $nextEquals = $t;
1373
-                            break;
1374
-                        }
1375
-                    }
1376
-
1377
-                    if ($nextEquals !== false) {
1378
-                        break;
1379
-                    }
1380
-                }
1381
-
1382
-                if ($defaultStart === null) {
1383
-                    if ($typeHintToken === false) {
1384
-                        $typeHintToken = $i;
1385
-                    }
1386
-
1387
-                    $typeHint .= $this->tokens[$i]['content'];
1388
-                }
1389
-                break;
1390
-            case T_NS_SEPARATOR:
1391
-                // Part of a type hint or default value.
1392
-                if ($defaultStart === null) {
1393
-                    if ($typeHintToken === false) {
1394
-                        $typeHintToken = $i;
1395
-                    }
1396
-
1397
-                    $typeHint .= $this->tokens[$i]['content'];
1398
-                }
1399
-                break;
1400
-            case T_NULLABLE:
1401
-                if ($defaultStart === null) {
1402
-                    $nullableType = true;
1403
-                    $typeHint    .= $this->tokens[$i]['content'];
1404
-                }
1405
-                break;
1406
-            case T_CLOSE_PARENTHESIS:
1407
-            case T_COMMA:
1408
-                // If it's null, then there must be no parameters for this
1409
-                // method.
1410
-                if ($currVar === null) {
1411
-                    continue 2;
1412
-                }
1413
-
1414
-                $vars[$paramCount]            = [];
1415
-                $vars[$paramCount]['token']   = $currVar;
1416
-                $vars[$paramCount]['name']    = $this->tokens[$currVar]['content'];
1417
-                $vars[$paramCount]['content'] = trim($this->getTokensAsString($paramStart, ($i - $paramStart)));
1418
-
1419
-                if ($defaultStart !== null) {
1420
-                    $vars[$paramCount]['default'] = trim($this->getTokensAsString($defaultStart, ($i - $defaultStart)));
1421
-                }
1422
-
1423
-                $vars[$paramCount]['pass_by_reference'] = $passByReference;
1424
-                $vars[$paramCount]['variable_length']   = $variableLength;
1425
-                $vars[$paramCount]['type_hint']         = $typeHint;
1426
-                $vars[$paramCount]['type_hint_token']   = $typeHintToken;
1427
-                $vars[$paramCount]['nullable_type']     = $nullableType;
1428
-
1429
-                // Reset the vars, as we are about to process the next parameter.
1430
-                $defaultStart    = null;
1431
-                $paramStart      = ($i + 1);
1432
-                $passByReference = false;
1433
-                $variableLength  = false;
1434
-                $typeHint        = '';
1435
-                $typeHintToken   = false;
1436
-                $nullableType    = false;
1437
-
1438
-                $paramCount++;
1439
-                break;
1440
-            case T_EQUAL:
1441
-                $defaultStart = ($i + 1);
1442
-                break;
1443
-            }//end switch
1444
-        }//end for
1445
-
1446
-        return $vars;
1447
-
1448
-    }//end getMethodParameters()
1449
-
1450
-
1451
-    /**
1452
-     * Returns the visibility and implementation properties of a method.
1453
-     *
1454
-     * The format of the array is:
1455
-     * <code>
1456
-     *   array(
1457
-     *    'scope'                => 'public', // public protected or protected
1458
-     *    'scope_specified'      => true,     // true is scope keyword was found.
1459
-     *    'return_type'          => '',       // the return type of the method.
1460
-     *    'return_type_token'    => integer,  // The stack pointer to the start of the return type
1461
-     *                                        // or false if there is no return type.
1462
-     *    'nullable_return_type' => false,    // true if the return type is nullable.
1463
-     *    'is_abstract'          => false,    // true if the abstract keyword was found.
1464
-     *    'is_final'             => false,    // true if the final keyword was found.
1465
-     *    'is_static'            => false,    // true if the static keyword was found.
1466
-     *    'has_body'             => false,    // true if the method has a body
1467
-     *   );
1468
-     * </code>
1469
-     *
1470
-     * @param int $stackPtr The position in the stack of the function token to
1471
-     *                      acquire the properties for.
1472
-     *
1473
-     * @return array
1474
-     * @throws \PHP_CodeSniffer\Exceptions\TokenizerException If the specified position is not a
1475
-     *                                                        T_FUNCTION token.
1476
-     */
1477
-    public function getMethodProperties($stackPtr)
1478
-    {
1479
-        if ($this->tokens[$stackPtr]['code'] !== T_FUNCTION
1480
-            && $this->tokens[$stackPtr]['code'] !== T_CLOSURE
1481
-        ) {
1482
-            throw new TokenizerException('$stackPtr must be of type T_FUNCTION or T_CLOSURE');
1483
-        }
1484
-
1485
-        if ($this->tokens[$stackPtr]['code'] === T_FUNCTION) {
1486
-            $valid = [
1487
-                T_PUBLIC      => T_PUBLIC,
1488
-                T_PRIVATE     => T_PRIVATE,
1489
-                T_PROTECTED   => T_PROTECTED,
1490
-                T_STATIC      => T_STATIC,
1491
-                T_FINAL       => T_FINAL,
1492
-                T_ABSTRACT    => T_ABSTRACT,
1493
-                T_WHITESPACE  => T_WHITESPACE,
1494
-                T_COMMENT     => T_COMMENT,
1495
-                T_DOC_COMMENT => T_DOC_COMMENT,
1496
-            ];
1497
-        } else {
1498
-            $valid = [
1499
-                T_STATIC      => T_STATIC,
1500
-                T_WHITESPACE  => T_WHITESPACE,
1501
-                T_COMMENT     => T_COMMENT,
1502
-                T_DOC_COMMENT => T_DOC_COMMENT,
1503
-            ];
1504
-        }
1505
-
1506
-        $scope          = 'public';
1507
-        $scopeSpecified = false;
1508
-        $isAbstract     = false;
1509
-        $isFinal        = false;
1510
-        $isStatic       = false;
1511
-
1512
-        for ($i = ($stackPtr - 1); $i > 0; $i--) {
1513
-            if (isset($valid[$this->tokens[$i]['code']]) === false) {
1514
-                break;
1515
-            }
1516
-
1517
-            switch ($this->tokens[$i]['code']) {
1518
-            case T_PUBLIC:
1519
-                $scope          = 'public';
1520
-                $scopeSpecified = true;
1521
-                break;
1522
-            case T_PRIVATE:
1523
-                $scope          = 'private';
1524
-                $scopeSpecified = true;
1525
-                break;
1526
-            case T_PROTECTED:
1527
-                $scope          = 'protected';
1528
-                $scopeSpecified = true;
1529
-                break;
1530
-            case T_ABSTRACT:
1531
-                $isAbstract = true;
1532
-                break;
1533
-            case T_FINAL:
1534
-                $isFinal = true;
1535
-                break;
1536
-            case T_STATIC:
1537
-                $isStatic = true;
1538
-                break;
1539
-            }//end switch
1540
-        }//end for
1541
-
1542
-        $returnType         = '';
1543
-        $returnTypeToken    = false;
1544
-        $nullableReturnType = false;
1545
-        $hasBody            = true;
1546
-
1547
-        if (isset($this->tokens[$stackPtr]['parenthesis_closer']) === true) {
1548
-            $scopeOpener = null;
1549
-            if (isset($this->tokens[$stackPtr]['scope_opener']) === true) {
1550
-                $scopeOpener = $this->tokens[$stackPtr]['scope_opener'];
1551
-            }
1552
-
1553
-            $valid = [
1554
-                T_STRING       => T_STRING,
1555
-                T_CALLABLE     => T_CALLABLE,
1556
-                T_SELF         => T_SELF,
1557
-                T_PARENT       => T_PARENT,
1558
-                T_NS_SEPARATOR => T_NS_SEPARATOR,
1559
-            ];
1560
-
1561
-            for ($i = $this->tokens[$stackPtr]['parenthesis_closer']; $i < $this->numTokens; $i++) {
1562
-                if (($scopeOpener === null && $this->tokens[$i]['code'] === T_SEMICOLON)
1563
-                    || ($scopeOpener !== null && $i === $scopeOpener)
1564
-                ) {
1565
-                    // End of function definition.
1566
-                    break;
1567
-                }
1568
-
1569
-                if ($this->tokens[$i]['code'] === T_NULLABLE) {
1570
-                    $nullableReturnType = true;
1571
-                }
1572
-
1573
-                if (isset($valid[$this->tokens[$i]['code']]) === true) {
1574
-                    if ($returnTypeToken === false) {
1575
-                        $returnTypeToken = $i;
1576
-                    }
1577
-
1578
-                    $returnType .= $this->tokens[$i]['content'];
1579
-                }
1580
-            }
1581
-
1582
-            $end     = $this->findNext([T_OPEN_CURLY_BRACKET, T_SEMICOLON], $this->tokens[$stackPtr]['parenthesis_closer']);
1583
-            $hasBody = $this->tokens[$end]['code'] === T_OPEN_CURLY_BRACKET;
1584
-        }//end if
1585
-
1586
-        if ($returnType !== '' && $nullableReturnType === true) {
1587
-            $returnType = '?'.$returnType;
1588
-        }
1589
-
1590
-        return [
1591
-            'scope'                => $scope,
1592
-            'scope_specified'      => $scopeSpecified,
1593
-            'return_type'          => $returnType,
1594
-            'return_type_token'    => $returnTypeToken,
1595
-            'nullable_return_type' => $nullableReturnType,
1596
-            'is_abstract'          => $isAbstract,
1597
-            'is_final'             => $isFinal,
1598
-            'is_static'            => $isStatic,
1599
-            'has_body'             => $hasBody,
1600
-        ];
1601
-
1602
-    }//end getMethodProperties()
1603
-
1604
-
1605
-    /**
1606
-     * Returns the visibility and implementation properties of the class member
1607
-     * variable found at the specified position in the stack.
1608
-     *
1609
-     * The format of the array is:
1610
-     *
1611
-     * <code>
1612
-     *   array(
1613
-     *    'scope'           => 'public', // public protected or protected.
1614
-     *    'scope_specified' => false,    // true if the scope was explicitly specified.
1615
-     *    'is_static'       => false,    // true if the static keyword was found.
1616
-     *   );
1617
-     * </code>
1618
-     *
1619
-     * @param int $stackPtr The position in the stack of the T_VARIABLE token to
1620
-     *                      acquire the properties for.
1621
-     *
1622
-     * @return array
1623
-     * @throws \PHP_CodeSniffer\Exceptions\TokenizerException If the specified position is not a
1624
-     *                                                        T_VARIABLE token, or if the position is not
1625
-     *                                                        a class member variable.
1626
-     */
1627
-    public function getMemberProperties($stackPtr)
1628
-    {
1629
-        if ($this->tokens[$stackPtr]['code'] !== T_VARIABLE) {
1630
-            throw new TokenizerException('$stackPtr must be of type T_VARIABLE');
1631
-        }
1632
-
1633
-        $conditions = array_keys($this->tokens[$stackPtr]['conditions']);
1634
-        $ptr        = array_pop($conditions);
1635
-        if (isset($this->tokens[$ptr]) === false
1636
-            || ($this->tokens[$ptr]['code'] !== T_CLASS
1637
-            && $this->tokens[$ptr]['code'] !== T_ANON_CLASS
1638
-            && $this->tokens[$ptr]['code'] !== T_TRAIT)
1639
-        ) {
1640
-            if (isset($this->tokens[$ptr]) === true
1641
-                && $this->tokens[$ptr]['code'] === T_INTERFACE
1642
-            ) {
1643
-                // T_VARIABLEs in interfaces can actually be method arguments
1644
-                // but they wont be seen as being inside the method because there
1645
-                // are no scope openers and closers for abstract methods. If it is in
1646
-                // parentheses, we can be pretty sure it is a method argument.
1647
-                if (isset($this->tokens[$stackPtr]['nested_parenthesis']) === false
1648
-                    || empty($this->tokens[$stackPtr]['nested_parenthesis']) === true
1649
-                ) {
1650
-                    $error = 'Possible parse error: interfaces may not include member vars';
1651
-                    $this->addWarning($error, $stackPtr, 'Internal.ParseError.InterfaceHasMemberVar');
1652
-                    return [];
1653
-                }
1654
-            } else {
1655
-                throw new TokenizerException('$stackPtr is not a class member var');
1656
-            }
1657
-        }
1658
-
1659
-        // Make sure it's not a method parameter.
1660
-        if (empty($this->tokens[$stackPtr]['nested_parenthesis']) === false) {
1661
-            $parenthesis = array_keys($this->tokens[$stackPtr]['nested_parenthesis']);
1662
-            $deepestOpen = array_pop($parenthesis);
1663
-            if ($deepestOpen > $ptr
1664
-                && isset($this->tokens[$deepestOpen]['parenthesis_owner']) === true
1665
-                && $this->tokens[$this->tokens[$deepestOpen]['parenthesis_owner']]['code'] === T_FUNCTION
1666
-            ) {
1667
-                throw new TokenizerException('$stackPtr is not a class member var');
1668
-            }
1669
-        }
1670
-
1671
-        $valid = [
1672
-            T_PUBLIC    => T_PUBLIC,
1673
-            T_PRIVATE   => T_PRIVATE,
1674
-            T_PROTECTED => T_PROTECTED,
1675
-            T_STATIC    => T_STATIC,
1676
-            T_VAR       => T_VAR,
1677
-        ];
1678
-
1679
-        $valid += Util\Tokens::$emptyTokens;
1680
-
1681
-        $scope          = 'public';
1682
-        $scopeSpecified = false;
1683
-        $isStatic       = false;
1684
-
1685
-        $startOfStatement = $this->findPrevious(
1686
-            [
1687
-                T_SEMICOLON,
1688
-                T_OPEN_CURLY_BRACKET,
1689
-                T_CLOSE_CURLY_BRACKET,
1690
-            ],
1691
-            ($stackPtr - 1)
1692
-        );
1693
-
1694
-        for ($i = ($startOfStatement + 1); $i < $stackPtr; $i++) {
1695
-            if (isset($valid[$this->tokens[$i]['code']]) === false) {
1696
-                break;
1697
-            }
1698
-
1699
-            switch ($this->tokens[$i]['code']) {
1700
-            case T_PUBLIC:
1701
-                $scope          = 'public';
1702
-                $scopeSpecified = true;
1703
-                break;
1704
-            case T_PRIVATE:
1705
-                $scope          = 'private';
1706
-                $scopeSpecified = true;
1707
-                break;
1708
-            case T_PROTECTED:
1709
-                $scope          = 'protected';
1710
-                $scopeSpecified = true;
1711
-                break;
1712
-            case T_STATIC:
1713
-                $isStatic = true;
1714
-                break;
1715
-            }
1716
-        }//end for
1717
-
1718
-        return [
1719
-            'scope'           => $scope,
1720
-            'scope_specified' => $scopeSpecified,
1721
-            'is_static'       => $isStatic,
1722
-        ];
1723
-
1724
-    }//end getMemberProperties()
1725
-
1726
-
1727
-    /**
1728
-     * Returns the visibility and implementation properties of a class.
1729
-     *
1730
-     * The format of the array is:
1731
-     * <code>
1732
-     *   array(
1733
-     *    'is_abstract' => false, // true if the abstract keyword was found.
1734
-     *    'is_final'    => false, // true if the final keyword was found.
1735
-     *   );
1736
-     * </code>
1737
-     *
1738
-     * @param int $stackPtr The position in the stack of the T_CLASS token to
1739
-     *                      acquire the properties for.
1740
-     *
1741
-     * @return array
1742
-     * @throws \PHP_CodeSniffer\Exceptions\TokenizerException If the specified position is not a
1743
-     *                                                        T_CLASS token.
1744
-     */
1745
-    public function getClassProperties($stackPtr)
1746
-    {
1747
-        if ($this->tokens[$stackPtr]['code'] !== T_CLASS) {
1748
-            throw new TokenizerException('$stackPtr must be of type T_CLASS');
1749
-        }
1750
-
1751
-        $valid = [
1752
-            T_FINAL       => T_FINAL,
1753
-            T_ABSTRACT    => T_ABSTRACT,
1754
-            T_WHITESPACE  => T_WHITESPACE,
1755
-            T_COMMENT     => T_COMMENT,
1756
-            T_DOC_COMMENT => T_DOC_COMMENT,
1757
-        ];
1758
-
1759
-        $isAbstract = false;
1760
-        $isFinal    = false;
1761
-
1762
-        for ($i = ($stackPtr - 1); $i > 0; $i--) {
1763
-            if (isset($valid[$this->tokens[$i]['code']]) === false) {
1764
-                break;
1765
-            }
1766
-
1767
-            switch ($this->tokens[$i]['code']) {
1768
-            case T_ABSTRACT:
1769
-                $isAbstract = true;
1770
-                break;
1771
-
1772
-            case T_FINAL:
1773
-                $isFinal = true;
1774
-                break;
1775
-            }
1776
-        }//end for
1777
-
1778
-        return [
1779
-            'is_abstract' => $isAbstract,
1780
-            'is_final'    => $isFinal,
1781
-        ];
1782
-
1783
-    }//end getClassProperties()
1784
-
1785
-
1786
-    /**
1787
-     * Determine if the passed token is a reference operator.
1788
-     *
1789
-     * Returns true if the specified token position represents a reference.
1790
-     * Returns false if the token represents a bitwise operator.
1791
-     *
1792
-     * @param int $stackPtr The position of the T_BITWISE_AND token.
1793
-     *
1794
-     * @return boolean
1795
-     */
1796
-    public function isReference($stackPtr)
1797
-    {
1798
-        if ($this->tokens[$stackPtr]['code'] !== T_BITWISE_AND) {
1799
-            return false;
1800
-        }
1801
-
1802
-        $tokenBefore = $this->findPrevious(
1803
-            Util\Tokens::$emptyTokens,
1804
-            ($stackPtr - 1),
1805
-            null,
1806
-            true
1807
-        );
1808
-
1809
-        if ($this->tokens[$tokenBefore]['code'] === T_FUNCTION) {
1810
-            // Function returns a reference.
1811
-            return true;
1812
-        }
1813
-
1814
-        if ($this->tokens[$tokenBefore]['code'] === T_DOUBLE_ARROW) {
1815
-            // Inside a foreach loop or array assignment, this is a reference.
1816
-            return true;
1817
-        }
1818
-
1819
-        if ($this->tokens[$tokenBefore]['code'] === T_AS) {
1820
-            // Inside a foreach loop, this is a reference.
1821
-            return true;
1822
-        }
1823
-
1824
-        if (isset(Util\Tokens::$assignmentTokens[$this->tokens[$tokenBefore]['code']]) === true) {
1825
-            // This is directly after an assignment. It's a reference. Even if
1826
-            // it is part of an operation, the other tests will handle it.
1827
-            return true;
1828
-        }
1829
-
1830
-        $tokenAfter = $this->findNext(
1831
-            Util\Tokens::$emptyTokens,
1832
-            ($stackPtr + 1),
1833
-            null,
1834
-            true
1835
-        );
1836
-
1837
-        if ($this->tokens[$tokenAfter]['code'] === T_NEW) {
1838
-            return true;
1839
-        }
1840
-
1841
-        if (isset($this->tokens[$stackPtr]['nested_parenthesis']) === true) {
1842
-            $brackets    = $this->tokens[$stackPtr]['nested_parenthesis'];
1843
-            $lastBracket = array_pop($brackets);
1844
-            if (isset($this->tokens[$lastBracket]['parenthesis_owner']) === true) {
1845
-                $owner = $this->tokens[$this->tokens[$lastBracket]['parenthesis_owner']];
1846
-                if ($owner['code'] === T_FUNCTION
1847
-                    || $owner['code'] === T_CLOSURE
1848
-                ) {
1849
-                    $params = $this->getMethodParameters($this->tokens[$lastBracket]['parenthesis_owner']);
1850
-                    foreach ($params as $param) {
1851
-                        $varToken = $tokenAfter;
1852
-                        if ($param['variable_length'] === true) {
1853
-                            $varToken = $this->findNext(
1854
-                                (Util\Tokens::$emptyTokens + [T_ELLIPSIS]),
1855
-                                ($stackPtr + 1),
1856
-                                null,
1857
-                                true
1858
-                            );
1859
-                        }
1860
-
1861
-                        if ($param['token'] === $varToken
1862
-                            && $param['pass_by_reference'] === true
1863
-                        ) {
1864
-                            // Function parameter declared to be passed by reference.
1865
-                            return true;
1866
-                        }
1867
-                    }
1868
-                }//end if
1869
-            } else {
1870
-                $prev = false;
1871
-                for ($t = ($this->tokens[$lastBracket]['parenthesis_opener'] - 1); $t >= 0; $t--) {
1872
-                    if ($this->tokens[$t]['code'] !== T_WHITESPACE) {
1873
-                        $prev = $t;
1874
-                        break;
1875
-                    }
1876
-                }
1877
-
1878
-                if ($prev !== false && $this->tokens[$prev]['code'] === T_USE) {
1879
-                    // Closure use by reference.
1880
-                    return true;
1881
-                }
1882
-            }//end if
1883
-        }//end if
1884
-
1885
-        // Pass by reference in function calls and assign by reference in arrays.
1886
-        if ($this->tokens[$tokenBefore]['code'] === T_OPEN_PARENTHESIS
1887
-            || $this->tokens[$tokenBefore]['code'] === T_COMMA
1888
-            || $this->tokens[$tokenBefore]['code'] === T_OPEN_SHORT_ARRAY
1889
-        ) {
1890
-            if ($this->tokens[$tokenAfter]['code'] === T_VARIABLE) {
1891
-                return true;
1892
-            } else {
1893
-                $skip   = Util\Tokens::$emptyTokens;
1894
-                $skip[] = T_NS_SEPARATOR;
1895
-                $skip[] = T_SELF;
1896
-                $skip[] = T_PARENT;
1897
-                $skip[] = T_STATIC;
1898
-                $skip[] = T_STRING;
1899
-                $skip[] = T_NAMESPACE;
1900
-                $skip[] = T_DOUBLE_COLON;
1901
-
1902
-                $nextSignificantAfter = $this->findNext(
1903
-                    $skip,
1904
-                    ($stackPtr + 1),
1905
-                    null,
1906
-                    true
1907
-                );
1908
-                if ($this->tokens[$nextSignificantAfter]['code'] === T_VARIABLE) {
1909
-                    return true;
1910
-                }
1911
-            }//end if
1912
-        }//end if
1913
-
1914
-        return false;
1915
-
1916
-    }//end isReference()
1917
-
1918
-
1919
-    /**
1920
-     * Returns the content of the tokens from the specified start position in
1921
-     * the token stack for the specified length.
1922
-     *
1923
-     * @param int  $start       The position to start from in the token stack.
1924
-     * @param int  $length      The length of tokens to traverse from the start pos.
1925
-     * @param bool $origContent Whether the original content or the tab replaced
1926
-     *                          content should be used.
1927
-     *
1928
-     * @return string The token contents.
1929
-     */
1930
-    public function getTokensAsString($start, $length, $origContent=false)
1931
-    {
1932
-        if (is_int($start) === false || isset($this->tokens[$start]) === false) {
1933
-            throw new RuntimeException('The $start position for getTokensAsString() must exist in the token stack');
1934
-        }
1935
-
1936
-        if (is_int($length) === false || $length <= 0) {
1937
-            return '';
1938
-        }
1939
-
1940
-        $str = '';
1941
-        $end = ($start + $length);
1942
-        if ($end > $this->numTokens) {
1943
-            $end = $this->numTokens;
1944
-        }
1945
-
1946
-        for ($i = $start; $i < $end; $i++) {
1947
-            // If tabs are being converted to spaces by the tokeniser, the
1948
-            // original content should be used instead of the converted content.
1949
-            if ($origContent === true && isset($this->tokens[$i]['orig_content']) === true) {
1950
-                $str .= $this->tokens[$i]['orig_content'];
1951
-            } else {
1952
-                $str .= $this->tokens[$i]['content'];
1953
-            }
1954
-        }
1955
-
1956
-        return $str;
1957
-
1958
-    }//end getTokensAsString()
1959
-
1960
-
1961
-    /**
1962
-     * Returns the position of the previous specified token(s).
1963
-     *
1964
-     * If a value is specified, the previous token of the specified type(s)
1965
-     * containing the specified value will be returned.
1966
-     *
1967
-     * Returns false if no token can be found.
1968
-     *
1969
-     * @param int|string|array $types   The type(s) of tokens to search for.
1970
-     * @param int              $start   The position to start searching from in the
1971
-     *                                  token stack.
1972
-     * @param int              $end     The end position to fail if no token is found.
1973
-     *                                  if not specified or null, end will default to
1974
-     *                                  the start of the token stack.
1975
-     * @param bool             $exclude If true, find the previous token that is NOT of
1976
-     *                                  the types specified in $types.
1977
-     * @param string           $value   The value that the token(s) must be equal to.
1978
-     *                                  If value is omitted, tokens with any value will
1979
-     *                                  be returned.
1980
-     * @param bool             $local   If true, tokens outside the current statement
1981
-     *                                  will not be checked. IE. checking will stop
1982
-     *                                  at the previous semi-colon found.
1983
-     *
1984
-     * @return int|bool
1985
-     * @see    findNext()
1986
-     */
1987
-    public function findPrevious(
1988
-        $types,
1989
-        $start,
1990
-        $end=null,
1991
-        $exclude=false,
1992
-        $value=null,
1993
-        $local=false
1994
-    ) {
1995
-        $types = (array) $types;
1996
-
1997
-        if ($end === null) {
1998
-            $end = 0;
1999
-        }
2000
-
2001
-        for ($i = $start; $i >= $end; $i--) {
2002
-            $found = (bool) $exclude;
2003
-            foreach ($types as $type) {
2004
-                if ($this->tokens[$i]['code'] === $type) {
2005
-                    $found = !$exclude;
2006
-                    break;
2007
-                }
2008
-            }
2009
-
2010
-            if ($found === true) {
2011
-                if ($value === null) {
2012
-                    return $i;
2013
-                } else if ($this->tokens[$i]['content'] === $value) {
2014
-                    return $i;
2015
-                }
2016
-            }
2017
-
2018
-            if ($local === true) {
2019
-                if (isset($this->tokens[$i]['scope_opener']) === true
2020
-                    && $i === $this->tokens[$i]['scope_closer']
2021
-                ) {
2022
-                    $i = $this->tokens[$i]['scope_opener'];
2023
-                } else if (isset($this->tokens[$i]['bracket_opener']) === true
2024
-                    && $i === $this->tokens[$i]['bracket_closer']
2025
-                ) {
2026
-                    $i = $this->tokens[$i]['bracket_opener'];
2027
-                } else if (isset($this->tokens[$i]['parenthesis_opener']) === true
2028
-                    && $i === $this->tokens[$i]['parenthesis_closer']
2029
-                ) {
2030
-                    $i = $this->tokens[$i]['parenthesis_opener'];
2031
-                } else if ($this->tokens[$i]['code'] === T_SEMICOLON) {
2032
-                    break;
2033
-                }
2034
-            }
2035
-        }//end for
2036
-
2037
-        return false;
2038
-
2039
-    }//end findPrevious()
2040
-
2041
-
2042
-    /**
2043
-     * Returns the position of the next specified token(s).
2044
-     *
2045
-     * If a value is specified, the next token of the specified type(s)
2046
-     * containing the specified value will be returned.
2047
-     *
2048
-     * Returns false if no token can be found.
2049
-     *
2050
-     * @param int|string|array $types   The type(s) of tokens to search for.
2051
-     * @param int              $start   The position to start searching from in the
2052
-     *                                  token stack.
2053
-     * @param int              $end     The end position to fail if no token is found.
2054
-     *                                  if not specified or null, end will default to
2055
-     *                                  the end of the token stack.
2056
-     * @param bool             $exclude If true, find the next token that is NOT of
2057
-     *                                  a type specified in $types.
2058
-     * @param string           $value   The value that the token(s) must be equal to.
2059
-     *                                  If value is omitted, tokens with any value will
2060
-     *                                  be returned.
2061
-     * @param bool             $local   If true, tokens outside the current statement
2062
-     *                                  will not be checked. i.e., checking will stop
2063
-     *                                  at the next semi-colon found.
2064
-     *
2065
-     * @return int|bool
2066
-     * @see    findPrevious()
2067
-     */
2068
-    public function findNext(
2069
-        $types,
2070
-        $start,
2071
-        $end=null,
2072
-        $exclude=false,
2073
-        $value=null,
2074
-        $local=false
2075
-    ) {
2076
-        $types = (array) $types;
2077
-
2078
-        if ($end === null || $end > $this->numTokens) {
2079
-            $end = $this->numTokens;
2080
-        }
2081
-
2082
-        for ($i = $start; $i < $end; $i++) {
2083
-            $found = (bool) $exclude;
2084
-            foreach ($types as $type) {
2085
-                if ($this->tokens[$i]['code'] === $type) {
2086
-                    $found = !$exclude;
2087
-                    break;
2088
-                }
2089
-            }
2090
-
2091
-            if ($found === true) {
2092
-                if ($value === null) {
2093
-                    return $i;
2094
-                } else if ($this->tokens[$i]['content'] === $value) {
2095
-                    return $i;
2096
-                }
2097
-            }
2098
-
2099
-            if ($local === true && $this->tokens[$i]['code'] === T_SEMICOLON) {
2100
-                break;
2101
-            }
2102
-        }//end for
2103
-
2104
-        return false;
2105
-
2106
-    }//end findNext()
2107
-
2108
-
2109
-    /**
2110
-     * Returns the position of the first non-whitespace token in a statement.
2111
-     *
2112
-     * @param int       $start  The position to start searching from in the token stack.
2113
-     * @param int|array $ignore Token types that should not be considered stop points.
2114
-     *
2115
-     * @return int
2116
-     */
2117
-    public function findStartOfStatement($start, $ignore=null)
2118
-    {
2119
-        $endTokens = Util\Tokens::$blockOpeners;
2120
-
2121
-        $endTokens[T_COLON]            = true;
2122
-        $endTokens[T_COMMA]            = true;
2123
-        $endTokens[T_DOUBLE_ARROW]     = true;
2124
-        $endTokens[T_SEMICOLON]        = true;
2125
-        $endTokens[T_OPEN_TAG]         = true;
2126
-        $endTokens[T_CLOSE_TAG]        = true;
2127
-        $endTokens[T_OPEN_SHORT_ARRAY] = true;
2128
-
2129
-        if ($ignore !== null) {
2130
-            $ignore = (array) $ignore;
2131
-            foreach ($ignore as $code) {
2132
-                unset($endTokens[$code]);
2133
-            }
2134
-        }
2135
-
2136
-        $lastNotEmpty = $start;
2137
-
2138
-        for ($i = $start; $i >= 0; $i--) {
2139
-            if (isset($endTokens[$this->tokens[$i]['code']]) === true) {
2140
-                // Found the end of the previous statement.
2141
-                return $lastNotEmpty;
2142
-            }
2143
-
2144
-            if (isset($this->tokens[$i]['scope_opener']) === true
2145
-                && $i === $this->tokens[$i]['scope_closer']
2146
-            ) {
2147
-                // Found the end of the previous scope block.
2148
-                return $lastNotEmpty;
2149
-            }
2150
-
2151
-            // Skip nested statements.
2152
-            if (isset($this->tokens[$i]['bracket_opener']) === true
2153
-                && $i === $this->tokens[$i]['bracket_closer']
2154
-            ) {
2155
-                $i = $this->tokens[$i]['bracket_opener'];
2156
-            } else if (isset($this->tokens[$i]['parenthesis_opener']) === true
2157
-                && $i === $this->tokens[$i]['parenthesis_closer']
2158
-            ) {
2159
-                $i = $this->tokens[$i]['parenthesis_opener'];
2160
-            }
2161
-
2162
-            if (isset(Util\Tokens::$emptyTokens[$this->tokens[$i]['code']]) === false) {
2163
-                $lastNotEmpty = $i;
2164
-            }
2165
-        }//end for
2166
-
2167
-        return 0;
2168
-
2169
-    }//end findStartOfStatement()
2170
-
2171
-
2172
-    /**
2173
-     * Returns the position of the last non-whitespace token in a statement.
2174
-     *
2175
-     * @param int       $start  The position to start searching from in the token stack.
2176
-     * @param int|array $ignore Token types that should not be considered stop points.
2177
-     *
2178
-     * @return int
2179
-     */
2180
-    public function findEndOfStatement($start, $ignore=null)
2181
-    {
2182
-        $endTokens = [
2183
-            T_COLON                => true,
2184
-            T_COMMA                => true,
2185
-            T_DOUBLE_ARROW         => true,
2186
-            T_SEMICOLON            => true,
2187
-            T_CLOSE_PARENTHESIS    => true,
2188
-            T_CLOSE_SQUARE_BRACKET => true,
2189
-            T_CLOSE_CURLY_BRACKET  => true,
2190
-            T_CLOSE_SHORT_ARRAY    => true,
2191
-            T_OPEN_TAG             => true,
2192
-            T_CLOSE_TAG            => true,
2193
-        ];
2194
-
2195
-        if ($ignore !== null) {
2196
-            $ignore = (array) $ignore;
2197
-            foreach ($ignore as $code) {
2198
-                unset($endTokens[$code]);
2199
-            }
2200
-        }
2201
-
2202
-        $lastNotEmpty = $start;
2203
-
2204
-        for ($i = $start; $i < $this->numTokens; $i++) {
2205
-            if ($i !== $start && isset($endTokens[$this->tokens[$i]['code']]) === true) {
2206
-                // Found the end of the statement.
2207
-                if ($this->tokens[$i]['code'] === T_CLOSE_PARENTHESIS
2208
-                    || $this->tokens[$i]['code'] === T_CLOSE_SQUARE_BRACKET
2209
-                    || $this->tokens[$i]['code'] === T_CLOSE_CURLY_BRACKET
2210
-                    || $this->tokens[$i]['code'] === T_CLOSE_SHORT_ARRAY
2211
-                    || $this->tokens[$i]['code'] === T_OPEN_TAG
2212
-                    || $this->tokens[$i]['code'] === T_CLOSE_TAG
2213
-                ) {
2214
-                    return $lastNotEmpty;
2215
-                }
2216
-
2217
-                return $i;
2218
-            }
2219
-
2220
-            // Skip nested statements.
2221
-            if (isset($this->tokens[$i]['scope_closer']) === true
2222
-                && ($i === $this->tokens[$i]['scope_opener']
2223
-                || $i === $this->tokens[$i]['scope_condition'])
2224
-            ) {
2225
-                if ($i === $start && isset(Util\Tokens::$scopeOpeners[$this->tokens[$i]['code']]) === true) {
2226
-                    return $this->tokens[$i]['scope_closer'];
2227
-                }
2228
-
2229
-                $i = $this->tokens[$i]['scope_closer'];
2230
-            } else if (isset($this->tokens[$i]['bracket_closer']) === true
2231
-                && $i === $this->tokens[$i]['bracket_opener']
2232
-            ) {
2233
-                $i = $this->tokens[$i]['bracket_closer'];
2234
-            } else if (isset($this->tokens[$i]['parenthesis_closer']) === true
2235
-                && $i === $this->tokens[$i]['parenthesis_opener']
2236
-            ) {
2237
-                $i = $this->tokens[$i]['parenthesis_closer'];
2238
-            }
2239
-
2240
-            if (isset(Util\Tokens::$emptyTokens[$this->tokens[$i]['code']]) === false) {
2241
-                $lastNotEmpty = $i;
2242
-            }
2243
-        }//end for
2244
-
2245
-        return ($this->numTokens - 1);
2246
-
2247
-    }//end findEndOfStatement()
2248
-
2249
-
2250
-    /**
2251
-     * Returns the position of the first token on a line, matching given type.
2252
-     *
2253
-     * Returns false if no token can be found.
2254
-     *
2255
-     * @param int|string|array $types   The type(s) of tokens to search for.
2256
-     * @param int              $start   The position to start searching from in the
2257
-     *                                  token stack. The first token matching on
2258
-     *                                  this line before this token will be returned.
2259
-     * @param bool             $exclude If true, find the token that is NOT of
2260
-     *                                  the types specified in $types.
2261
-     * @param string           $value   The value that the token must be equal to.
2262
-     *                                  If value is omitted, tokens with any value will
2263
-     *                                  be returned.
2264
-     *
2265
-     * @return int | bool
2266
-     */
2267
-    public function findFirstOnLine($types, $start, $exclude=false, $value=null)
2268
-    {
2269
-        if (is_array($types) === false) {
2270
-            $types = [$types];
2271
-        }
2272
-
2273
-        $foundToken = false;
2274
-
2275
-        for ($i = $start; $i >= 0; $i--) {
2276
-            if ($this->tokens[$i]['line'] < $this->tokens[$start]['line']) {
2277
-                break;
2278
-            }
2279
-
2280
-            $found = $exclude;
2281
-            foreach ($types as $type) {
2282
-                if ($exclude === false) {
2283
-                    if ($this->tokens[$i]['code'] === $type) {
2284
-                        $found = true;
2285
-                        break;
2286
-                    }
2287
-                } else {
2288
-                    if ($this->tokens[$i]['code'] === $type) {
2289
-                        $found = false;
2290
-                        break;
2291
-                    }
2292
-                }
2293
-            }
2294
-
2295
-            if ($found === true) {
2296
-                if ($value === null) {
2297
-                    $foundToken = $i;
2298
-                } else if ($this->tokens[$i]['content'] === $value) {
2299
-                    $foundToken = $i;
2300
-                }
2301
-            }
2302
-        }//end for
2303
-
2304
-        return $foundToken;
2305
-
2306
-    }//end findFirstOnLine()
2307
-
2308
-
2309
-    /**
2310
-     * Determine if the passed token has a condition of one of the passed types.
2311
-     *
2312
-     * @param int              $stackPtr The position of the token we are checking.
2313
-     * @param int|string|array $types    The type(s) of tokens to search for.
2314
-     *
2315
-     * @return boolean
2316
-     */
2317
-    public function hasCondition($stackPtr, $types)
2318
-    {
2319
-        // Check for the existence of the token.
2320
-        if (isset($this->tokens[$stackPtr]) === false) {
2321
-            return false;
2322
-        }
2323
-
2324
-        // Make sure the token has conditions.
2325
-        if (isset($this->tokens[$stackPtr]['conditions']) === false) {
2326
-            return false;
2327
-        }
2328
-
2329
-        $types      = (array) $types;
2330
-        $conditions = $this->tokens[$stackPtr]['conditions'];
2331
-
2332
-        foreach ($types as $type) {
2333
-            if (in_array($type, $conditions, true) === true) {
2334
-                // We found a token with the required type.
2335
-                return true;
2336
-            }
2337
-        }
2338
-
2339
-        return false;
2340
-
2341
-    }//end hasCondition()
2342
-
2343
-
2344
-    /**
2345
-     * Return the position of the condition for the passed token.
2346
-     *
2347
-     * Returns FALSE if the token does not have the condition.
2348
-     *
2349
-     * @param int        $stackPtr The position of the token we are checking.
2350
-     * @param int|string $type     The type of token to search for.
2351
-     *
2352
-     * @return int
2353
-     */
2354
-    public function getCondition($stackPtr, $type)
2355
-    {
2356
-        // Check for the existence of the token.
2357
-        if (isset($this->tokens[$stackPtr]) === false) {
2358
-            return false;
2359
-        }
2360
-
2361
-        // Make sure the token has conditions.
2362
-        if (isset($this->tokens[$stackPtr]['conditions']) === false) {
2363
-            return false;
2364
-        }
2365
-
2366
-        $conditions = $this->tokens[$stackPtr]['conditions'];
2367
-        foreach ($conditions as $token => $condition) {
2368
-            if ($condition === $type) {
2369
-                return $token;
2370
-            }
2371
-        }
2372
-
2373
-        return false;
2374
-
2375
-    }//end getCondition()
2376
-
2377
-
2378
-    /**
2379
-     * Returns the name of the class that the specified class extends.
2380
-     * (works for classes, anonymous classes and interfaces)
2381
-     *
2382
-     * Returns FALSE on error or if there is no extended class name.
2383
-     *
2384
-     * @param int $stackPtr The stack position of the class.
2385
-     *
2386
-     * @return string|false
2387
-     */
2388
-    public function findExtendedClassName($stackPtr)
2389
-    {
2390
-        // Check for the existence of the token.
2391
-        if (isset($this->tokens[$stackPtr]) === false) {
2392
-            return false;
2393
-        }
2394
-
2395
-        if ($this->tokens[$stackPtr]['code'] !== T_CLASS
2396
-            && $this->tokens[$stackPtr]['code'] !== T_ANON_CLASS
2397
-            && $this->tokens[$stackPtr]['code'] !== T_INTERFACE
2398
-        ) {
2399
-            return false;
2400
-        }
2401
-
2402
-        if (isset($this->tokens[$stackPtr]['scope_opener']) === false) {
2403
-            return false;
2404
-        }
2405
-
2406
-        $classOpenerIndex = $this->tokens[$stackPtr]['scope_opener'];
2407
-        $extendsIndex     = $this->findNext(T_EXTENDS, $stackPtr, $classOpenerIndex);
2408
-        if (false === $extendsIndex) {
2409
-            return false;
2410
-        }
2411
-
2412
-        $find = [
2413
-            T_NS_SEPARATOR,
2414
-            T_STRING,
2415
-            T_WHITESPACE,
2416
-        ];
2417
-
2418
-        $end  = $this->findNext($find, ($extendsIndex + 1), ($classOpenerIndex + 1), true);
2419
-        $name = $this->getTokensAsString(($extendsIndex + 1), ($end - $extendsIndex - 1));
2420
-        $name = trim($name);
2421
-
2422
-        if ($name === '') {
2423
-            return false;
2424
-        }
2425
-
2426
-        return $name;
2427
-
2428
-    }//end findExtendedClassName()
2429
-
2430
-
2431
-    /**
2432
-     * Returns the names of the interfaces that the specified class implements.
2433
-     *
2434
-     * Returns FALSE on error or if there are no implemented interface names.
2435
-     *
2436
-     * @param int $stackPtr The stack position of the class.
2437
-     *
2438
-     * @return array|false
2439
-     */
2440
-    public function findImplementedInterfaceNames($stackPtr)
2441
-    {
2442
-        // Check for the existence of the token.
2443
-        if (isset($this->tokens[$stackPtr]) === false) {
2444
-            return false;
2445
-        }
2446
-
2447
-        if ($this->tokens[$stackPtr]['code'] !== T_CLASS
2448
-            && $this->tokens[$stackPtr]['code'] !== T_ANON_CLASS
2449
-        ) {
2450
-            return false;
2451
-        }
2452
-
2453
-        if (isset($this->tokens[$stackPtr]['scope_closer']) === false) {
2454
-            return false;
2455
-        }
2456
-
2457
-        $classOpenerIndex = $this->tokens[$stackPtr]['scope_opener'];
2458
-        $implementsIndex  = $this->findNext(T_IMPLEMENTS, $stackPtr, $classOpenerIndex);
2459
-        if ($implementsIndex === false) {
2460
-            return false;
2461
-        }
2462
-
2463
-        $find = [
2464
-            T_NS_SEPARATOR,
2465
-            T_STRING,
2466
-            T_WHITESPACE,
2467
-            T_COMMA,
2468
-        ];
2469
-
2470
-        $end  = $this->findNext($find, ($implementsIndex + 1), ($classOpenerIndex + 1), true);
2471
-        $name = $this->getTokensAsString(($implementsIndex + 1), ($end - $implementsIndex - 1));
2472
-        $name = trim($name);
2473
-
2474
-        if ($name === '') {
2475
-            return false;
2476
-        } else {
2477
-            $names = explode(',', $name);
2478
-            $names = array_map('trim', $names);
2479
-            return $names;
2480
-        }
2481
-
2482
-    }//end findImplementedInterfaceNames()
22
+	/**
23
+	 * The absolute path to the file associated with this object.
24
+	 *
25
+	 * @var string
26
+	 */
27
+	public $path = '';
28
+
29
+	/**
30
+	 * The content of the file.
31
+	 *
32
+	 * @var string
33
+	 */
34
+	protected $content = '';
35
+
36
+	/**
37
+	 * The config data for the run.
38
+	 *
39
+	 * @var \PHP_CodeSniffer\Config
40
+	 */
41
+	public $config = null;
42
+
43
+	/**
44
+	 * The ruleset used for the run.
45
+	 *
46
+	 * @var \PHP_CodeSniffer\Ruleset
47
+	 */
48
+	public $ruleset = null;
49
+
50
+	/**
51
+	 * If TRUE, the entire file is being ignored.
52
+	 *
53
+	 * @var boolean
54
+	 */
55
+	public $ignored = false;
56
+
57
+	/**
58
+	 * The EOL character this file uses.
59
+	 *
60
+	 * @var string
61
+	 */
62
+	public $eolChar = '';
63
+
64
+	/**
65
+	 * The Fixer object to control fixing errors.
66
+	 *
67
+	 * @var \PHP_CodeSniffer\Fixer
68
+	 */
69
+	public $fixer = null;
70
+
71
+	/**
72
+	 * The tokenizer being used for this file.
73
+	 *
74
+	 * @var \PHP_CodeSniffer\Tokenizers\Tokenizer
75
+	 */
76
+	public $tokenizer = null;
77
+
78
+	/**
79
+	 * The name of the tokenizer being used for this file.
80
+	 *
81
+	 * @var string
82
+	 */
83
+	public $tokenizerType = 'PHP';
84
+
85
+	/**
86
+	 * Was the file loaded from cache?
87
+	 *
88
+	 * If TRUE, the file was loaded from a local cache.
89
+	 * If FALSE, the file was tokenized and processed fully.
90
+	 *
91
+	 * @var boolean
92
+	 */
93
+	public $fromCache = false;
94
+
95
+	/**
96
+	 * The number of tokens in this file.
97
+	 *
98
+	 * Stored here to save calling count() everywhere.
99
+	 *
100
+	 * @var integer
101
+	 */
102
+	public $numTokens = 0;
103
+
104
+	/**
105
+	 * The tokens stack map.
106
+	 *
107
+	 * @var array
108
+	 */
109
+	protected $tokens = [];
110
+
111
+	/**
112
+	 * The errors raised from sniffs.
113
+	 *
114
+	 * @var array
115
+	 * @see getErrors()
116
+	 */
117
+	protected $errors = [];
118
+
119
+	/**
120
+	 * The warnings raised from sniffs.
121
+	 *
122
+	 * @var array
123
+	 * @see getWarnings()
124
+	 */
125
+	protected $warnings = [];
126
+
127
+	/**
128
+	 * The metrics recorded by sniffs.
129
+	 *
130
+	 * @var array
131
+	 * @see getMetrics()
132
+	 */
133
+	protected $metrics = [];
134
+
135
+	/**
136
+	 * The metrics recorded for each token.
137
+	 *
138
+	 * Stops the same metric being recorded for the same token twice.
139
+	 *
140
+	 * @var array
141
+	 * @see getMetrics()
142
+	 */
143
+	private $metricTokens = [];
144
+
145
+	/**
146
+	 * The total number of errors raised.
147
+	 *
148
+	 * @var integer
149
+	 */
150
+	protected $errorCount = 0;
151
+
152
+	/**
153
+	 * The total number of warnings raised.
154
+	 *
155
+	 * @var integer
156
+	 */
157
+	protected $warningCount = 0;
158
+
159
+	/**
160
+	 * The total number of errors and warnings that can be fixed.
161
+	 *
162
+	 * @var integer
163
+	 */
164
+	protected $fixableCount = 0;
165
+
166
+	/**
167
+	 * The total number of errors and warnings that were fixed.
168
+	 *
169
+	 * @var integer
170
+	 */
171
+	protected $fixedCount = 0;
172
+
173
+	/**
174
+	 * An array of sniffs that are being ignored.
175
+	 *
176
+	 * @var array
177
+	 */
178
+	protected $ignoredListeners = [];
179
+
180
+	/**
181
+	 * An array of message codes that are being ignored.
182
+	 *
183
+	 * @var array
184
+	 */
185
+	protected $ignoredCodes = [];
186
+
187
+	/**
188
+	 * An array of sniffs listening to this file's processing.
189
+	 *
190
+	 * @var \PHP_CodeSniffer\Sniffs\Sniff[]
191
+	 */
192
+	protected $listeners = [];
193
+
194
+	/**
195
+	 * The class name of the sniff currently processing the file.
196
+	 *
197
+	 * @var string
198
+	 */
199
+	protected $activeListener = '';
200
+
201
+	/**
202
+	 * An array of sniffs being processed and how long they took.
203
+	 *
204
+	 * @var array
205
+	 */
206
+	protected $listenerTimes = [];
207
+
208
+	/**
209
+	 * A cache of often used config settings to improve performance.
210
+	 *
211
+	 * Storing them here saves 10k+ calls to __get() in the Config class.
212
+	 *
213
+	 * @var array
214
+	 */
215
+	protected $configCache = [];
216
+
217
+
218
+	/**
219
+	 * Constructs a file.
220
+	 *
221
+	 * @param string                   $path    The absolute path to the file to process.
222
+	 * @param \PHP_CodeSniffer\Ruleset $ruleset The ruleset used for the run.
223
+	 * @param \PHP_CodeSniffer\Config  $config  The config data for the run.
224
+	 *
225
+	 * @return void
226
+	 */
227
+	public function __construct($path, Ruleset $ruleset, Config $config)
228
+	{
229
+		$this->path    = $path;
230
+		$this->ruleset = $ruleset;
231
+		$this->config  = $config;
232
+		$this->fixer   = new Fixer();
233
+
234
+		$parts     = explode('.', $path);
235
+		$extension = array_pop($parts);
236
+		if (isset($config->extensions[$extension]) === true) {
237
+			$this->tokenizerType = $config->extensions[$extension];
238
+		} else {
239
+			// Revert to default.
240
+			$this->tokenizerType = 'PHP';
241
+		}
242
+
243
+		$this->configCache['cache']           = $this->config->cache;
244
+		$this->configCache['sniffs']          = array_map('strtolower', $this->config->sniffs);
245
+		$this->configCache['exclude']         = array_map('strtolower', $this->config->exclude);
246
+		$this->configCache['errorSeverity']   = $this->config->errorSeverity;
247
+		$this->configCache['warningSeverity'] = $this->config->warningSeverity;
248
+		$this->configCache['recordErrors']    = $this->config->recordErrors;
249
+		$this->configCache['ignorePatterns']  = $this->ruleset->ignorePatterns;
250
+		$this->configCache['includePatterns'] = $this->ruleset->includePatterns;
251
+
252
+	}//end __construct()
253
+
254
+
255
+	/**
256
+	 * Set the content of the file.
257
+	 *
258
+	 * Setting the content also calculates the EOL char being used.
259
+	 *
260
+	 * @param string $content The file content.
261
+	 *
262
+	 * @return void
263
+	 */
264
+	public function setContent($content)
265
+	{
266
+		$this->content = $content;
267
+		$this->tokens  = [];
268
+
269
+		try {
270
+			$this->eolChar = Util\Common::detectLineEndings($content);
271
+		} catch (RuntimeException $e) {
272
+			$this->addWarningOnLine($e->getMessage(), 1, 'Internal.DetectLineEndings');
273
+			return;
274
+		}
275
+
276
+	}//end setContent()
277
+
278
+
279
+	/**
280
+	 * Reloads the content of the file.
281
+	 *
282
+	 * By default, we have no idea where our content comes from,
283
+	 * so we can't do anything.
284
+	 *
285
+	 * @return void
286
+	 */
287
+	public function reloadContent()
288
+	{
289
+
290
+	}//end reloadContent()
291
+
292
+
293
+	/**
294
+	 * Disables caching of this file.
295
+	 *
296
+	 * @return void
297
+	 */
298
+	public function disableCaching()
299
+	{
300
+		$this->configCache['cache'] = false;
301
+
302
+	}//end disableCaching()
303
+
304
+
305
+	/**
306
+	 * Starts the stack traversal and tells listeners when tokens are found.
307
+	 *
308
+	 * @return void
309
+	 */
310
+	public function process()
311
+	{
312
+		if ($this->ignored === true) {
313
+			return;
314
+		}
315
+
316
+		$this->errors       = [];
317
+		$this->warnings     = [];
318
+		$this->errorCount   = 0;
319
+		$this->warningCount = 0;
320
+		$this->fixableCount = 0;
321
+
322
+		$this->parse();
323
+
324
+		// Check if tokenizer errors cause this file to be ignored.
325
+		if ($this->ignored === true) {
326
+			return;
327
+		}
328
+
329
+		$this->fixer->startFile($this);
330
+
331
+		if (PHP_CODESNIFFER_VERBOSITY > 2) {
332
+			echo "\t*** START TOKEN PROCESSING ***".PHP_EOL;
333
+		}
334
+
335
+		$foundCode        = false;
336
+		$listenerIgnoreTo = [];
337
+		$inTests          = defined('PHP_CODESNIFFER_IN_TESTS');
338
+		$checkAnnotations = $this->config->annotations;
339
+
340
+		// Foreach of the listeners that have registered to listen for this
341
+		// token, get them to process it.
342
+		foreach ($this->tokens as $stackPtr => $token) {
343
+			// Check for ignored lines.
344
+			if ($checkAnnotations === true
345
+				&& ($token['code'] === T_COMMENT
346
+				|| $token['code'] === T_PHPCS_IGNORE_FILE
347
+				|| $token['code'] === T_PHPCS_SET
348
+				|| $token['code'] === T_DOC_COMMENT_STRING
349
+				|| $token['code'] === T_DOC_COMMENT_TAG
350
+				|| ($inTests === true && $token['code'] === T_INLINE_HTML))
351
+			) {
352
+				$commentText      = ltrim($this->tokens[$stackPtr]['content'], ' /*');
353
+				$commentTextLower = strtolower($commentText);
354
+				if (strpos($commentText, '@codingStandards') !== false) {
355
+					if (strpos($commentText, '@codingStandardsIgnoreFile') !== false) {
356
+						// Ignoring the whole file, just a little late.
357
+						$this->errors       = [];
358
+						$this->warnings     = [];
359
+						$this->errorCount   = 0;
360
+						$this->warningCount = 0;
361
+						$this->fixableCount = 0;
362
+						return;
363
+					} else if (strpos($commentText, '@codingStandardsChangeSetting') !== false) {
364
+						$start   = strpos($commentText, '@codingStandardsChangeSetting');
365
+						$comment = substr($commentText, ($start + 30));
366
+						$parts   = explode(' ', $comment);
367
+						if (count($parts) >= 2) {
368
+							$sniffParts = explode('.', $parts[0]);
369
+							if (count($sniffParts) >= 3) {
370
+								// If the sniff code is not known to us, it has not been registered in this run.
371
+								// But don't throw an error as it could be there for a different standard to use.
372
+								if (isset($this->ruleset->sniffCodes[$parts[0]]) === true) {
373
+									$listenerCode  = array_shift($parts);
374
+									$propertyCode  = array_shift($parts);
375
+									$propertyValue = rtrim(implode(' ', $parts), " */\r\n");
376
+									$listenerClass = $this->ruleset->sniffCodes[$listenerCode];
377
+									$this->ruleset->setSniffProperty($listenerClass, $propertyCode, $propertyValue);
378
+								}
379
+							}
380
+						}
381
+					}//end if
382
+				} else if (substr($commentTextLower, 0, 16) === 'phpcs:ignorefile'
383
+					|| substr($commentTextLower, 0, 17) === '@phpcs:ignorefile'
384
+				) {
385
+					// Ignoring the whole file, just a little late.
386
+					$this->errors       = [];
387
+					$this->warnings     = [];
388
+					$this->errorCount   = 0;
389
+					$this->warningCount = 0;
390
+					$this->fixableCount = 0;
391
+					return;
392
+				} else if (substr($commentTextLower, 0, 9) === 'phpcs:set'
393
+					|| substr($commentTextLower, 0, 10) === '@phpcs:set'
394
+				) {
395
+					if (isset($token['sniffCode']) === true) {
396
+						$listenerCode = $token['sniffCode'];
397
+						if (isset($this->ruleset->sniffCodes[$listenerCode]) === true) {
398
+							$propertyCode  = $token['sniffProperty'];
399
+							$propertyValue = $token['sniffPropertyValue'];
400
+							$listenerClass = $this->ruleset->sniffCodes[$listenerCode];
401
+							$this->ruleset->setSniffProperty($listenerClass, $propertyCode, $propertyValue);
402
+						}
403
+					}
404
+				}//end if
405
+			}//end if
406
+
407
+			if (PHP_CODESNIFFER_VERBOSITY > 2) {
408
+				$type    = $token['type'];
409
+				$content = Util\Common::prepareForOutput($token['content']);
410
+				echo "\t\tProcess token $stackPtr: $type => $content".PHP_EOL;
411
+			}
412
+
413
+			if ($token['code'] !== T_INLINE_HTML) {
414
+				$foundCode = true;
415
+			}
416
+
417
+			if (isset($this->ruleset->tokenListeners[$token['code']]) === false) {
418
+				continue;
419
+			}
420
+
421
+			foreach ($this->ruleset->tokenListeners[$token['code']] as $listenerData) {
422
+				if (isset($this->ignoredListeners[$listenerData['class']]) === true
423
+					|| (isset($listenerIgnoreTo[$listenerData['class']]) === true
424
+					&& $listenerIgnoreTo[$listenerData['class']] > $stackPtr)
425
+				) {
426
+					// This sniff is ignoring past this token, or the whole file.
427
+					continue;
428
+				}
429
+
430
+				// Make sure this sniff supports the tokenizer
431
+				// we are currently using.
432
+				$class = $listenerData['class'];
433
+
434
+				if (isset($listenerData['tokenizers'][$this->tokenizerType]) === false) {
435
+					continue;
436
+				}
437
+
438
+				// If the file path matches one of our ignore patterns, skip it.
439
+				// While there is support for a type of each pattern
440
+				// (absolute or relative) we don't actually support it here.
441
+				foreach ($listenerData['ignore'] as $pattern) {
442
+					// We assume a / directory separator, as do the exclude rules
443
+					// most developers write, so we need a special case for any system
444
+					// that is different.
445
+					if (DIRECTORY_SEPARATOR === '\\') {
446
+						$pattern = str_replace('/', '\\\\', $pattern);
447
+					}
448
+
449
+					$pattern = '`'.$pattern.'`i';
450
+					if (preg_match($pattern, $this->path) === 1) {
451
+						$this->ignoredListeners[$class] = true;
452
+						continue(2);
453
+					}
454
+				}
455
+
456
+				// If the file path does not match one of our include patterns, skip it.
457
+				// While there is support for a type of each pattern
458
+				// (absolute or relative) we don't actually support it here.
459
+				if (empty($listenerData['include']) === false) {
460
+					$included = false;
461
+					foreach ($listenerData['include'] as $pattern) {
462
+						// We assume a / directory separator, as do the exclude rules
463
+						// most developers write, so we need a special case for any system
464
+						// that is different.
465
+						if (DIRECTORY_SEPARATOR === '\\') {
466
+							$pattern = str_replace('/', '\\\\', $pattern);
467
+						}
468
+
469
+						$pattern = '`'.$pattern.'`i';
470
+						if (preg_match($pattern, $this->path) === 1) {
471
+							$included = true;
472
+							break;
473
+						}
474
+					}
475
+
476
+					if ($included === false) {
477
+						$this->ignoredListeners[$class] = true;
478
+						continue;
479
+					}
480
+				}//end if
481
+
482
+				$this->activeListener = $class;
483
+
484
+				if (PHP_CODESNIFFER_VERBOSITY > 2) {
485
+					$startTime = microtime(true);
486
+					echo "\t\t\tProcessing ".$this->activeListener.'... ';
487
+				}
488
+
489
+				$ignoreTo = $this->ruleset->sniffs[$class]->process($this, $stackPtr);
490
+				if ($ignoreTo !== null) {
491
+					$listenerIgnoreTo[$this->activeListener] = $ignoreTo;
492
+				}
493
+
494
+				if (PHP_CODESNIFFER_VERBOSITY > 2) {
495
+					$timeTaken = (microtime(true) - $startTime);
496
+					if (isset($this->listenerTimes[$this->activeListener]) === false) {
497
+						$this->listenerTimes[$this->activeListener] = 0;
498
+					}
499
+
500
+					$this->listenerTimes[$this->activeListener] += $timeTaken;
501
+
502
+					$timeTaken = round(($timeTaken), 4);
503
+					echo "DONE in $timeTaken seconds".PHP_EOL;
504
+				}
505
+
506
+				$this->activeListener = '';
507
+			}//end foreach
508
+		}//end foreach
509
+
510
+		// If short open tags are off but the file being checked uses
511
+		// short open tags, the whole content will be inline HTML
512
+		// and nothing will be checked. So try and handle this case.
513
+		// We don't show this error for STDIN because we can't be sure the content
514
+		// actually came directly from the user. It could be something like
515
+		// refs from a Git pre-push hook.
516
+		if ($foundCode === false && $this->tokenizerType === 'PHP' && $this->path !== 'STDIN') {
517
+			$shortTags = (bool) ini_get('short_open_tag');
518
+			if ($shortTags === false) {
519
+				$error = 'No PHP code was found in this file and short open tags are not allowed by this install of PHP. This file may be using short open tags but PHP does not allow them.';
520
+				$this->addWarning($error, null, 'Internal.NoCodeFound');
521
+			}
522
+		}
523
+
524
+		if (PHP_CODESNIFFER_VERBOSITY > 2) {
525
+			echo "\t*** END TOKEN PROCESSING ***".PHP_EOL;
526
+			echo "\t*** START SNIFF PROCESSING REPORT ***".PHP_EOL;
527
+
528
+			asort($this->listenerTimes, SORT_NUMERIC);
529
+			$this->listenerTimes = array_reverse($this->listenerTimes, true);
530
+			foreach ($this->listenerTimes as $listener => $timeTaken) {
531
+				echo "\t$listener: ".round(($timeTaken), 4).' secs'.PHP_EOL;
532
+			}
533
+
534
+			echo "\t*** END SNIFF PROCESSING REPORT ***".PHP_EOL;
535
+		}
536
+
537
+		$this->fixedCount += $this->fixer->getFixCount();
538
+
539
+	}//end process()
540
+
541
+
542
+	/**
543
+	 * Tokenizes the file and prepares it for the test run.
544
+	 *
545
+	 * @return void
546
+	 */
547
+	public function parse()
548
+	{
549
+		if (empty($this->tokens) === false) {
550
+			// File has already been parsed.
551
+			return;
552
+		}
553
+
554
+		try {
555
+			$tokenizerClass  = 'PHP_CodeSniffer\Tokenizers\\'.$this->tokenizerType;
556
+			$this->tokenizer = new $tokenizerClass($this->content, $this->config, $this->eolChar);
557
+			$this->tokens    = $this->tokenizer->getTokens();
558
+		} catch (TokenizerException $e) {
559
+			$this->ignored = true;
560
+			$this->addWarning($e->getMessage(), null, 'Internal.Tokenizer.Exception');
561
+			if (PHP_CODESNIFFER_VERBOSITY > 0) {
562
+				echo "[$this->tokenizerType => tokenizer error]... ";
563
+				if (PHP_CODESNIFFER_VERBOSITY > 1) {
564
+					echo PHP_EOL;
565
+				}
566
+			}
567
+
568
+			return;
569
+		}
570
+
571
+		$this->numTokens = count($this->tokens);
572
+
573
+		// Check for mixed line endings as these can cause tokenizer errors and we
574
+		// should let the user know that the results they get may be incorrect.
575
+		// This is done by removing all backslashes, removing the newline char we
576
+		// detected, then converting newlines chars into text. If any backslashes
577
+		// are left at the end, we have additional newline chars in use.
578
+		$contents = str_replace('\\', '', $this->content);
579
+		$contents = str_replace($this->eolChar, '', $contents);
580
+		$contents = str_replace("\n", '\n', $contents);
581
+		$contents = str_replace("\r", '\r', $contents);
582
+		if (strpos($contents, '\\') !== false) {
583
+			$error = 'File has mixed line endings; this may cause incorrect results';
584
+			$this->addWarningOnLine($error, 1, 'Internal.LineEndings.Mixed');
585
+		}
586
+
587
+		if (PHP_CODESNIFFER_VERBOSITY > 0) {
588
+			if ($this->numTokens === 0) {
589
+				$numLines = 0;
590
+			} else {
591
+				$numLines = $this->tokens[($this->numTokens - 1)]['line'];
592
+			}
593
+
594
+			echo "[$this->tokenizerType => $this->numTokens tokens in $numLines lines]... ";
595
+			if (PHP_CODESNIFFER_VERBOSITY > 1) {
596
+				echo PHP_EOL;
597
+			}
598
+		}
599
+
600
+	}//end parse()
601
+
602
+
603
+	/**
604
+	 * Returns the token stack for this file.
605
+	 *
606
+	 * @return array
607
+	 */
608
+	public function getTokens()
609
+	{
610
+		return $this->tokens;
611
+
612
+	}//end getTokens()
613
+
614
+
615
+	/**
616
+	 * Remove vars stored in this file that are no longer required.
617
+	 *
618
+	 * @return void
619
+	 */
620
+	public function cleanUp()
621
+	{
622
+		$this->listenerTimes = null;
623
+		$this->content       = null;
624
+		$this->tokens        = null;
625
+		$this->metricTokens  = null;
626
+		$this->tokenizer     = null;
627
+		$this->fixer         = null;
628
+		$this->config        = null;
629
+		$this->ruleset       = null;
630
+
631
+	}//end cleanUp()
632
+
633
+
634
+	/**
635
+	 * Records an error against a specific token in the file.
636
+	 *
637
+	 * @param string  $error    The error message.
638
+	 * @param int     $stackPtr The stack position where the error occurred.
639
+	 * @param string  $code     A violation code unique to the sniff message.
640
+	 * @param array   $data     Replacements for the error message.
641
+	 * @param int     $severity The severity level for this error. A value of 0
642
+	 *                          will be converted into the default severity level.
643
+	 * @param boolean $fixable  Can the error be fixed by the sniff?
644
+	 *
645
+	 * @return boolean
646
+	 */
647
+	public function addError(
648
+		$error,
649
+		$stackPtr,
650
+		$code,
651
+		$data=[],
652
+		$severity=0,
653
+		$fixable=false
654
+	) {
655
+		if ($stackPtr === null) {
656
+			$line   = 1;
657
+			$column = 1;
658
+		} else {
659
+			$line   = $this->tokens[$stackPtr]['line'];
660
+			$column = $this->tokens[$stackPtr]['column'];
661
+		}
662
+
663
+		return $this->addMessage(true, $error, $line, $column, $code, $data, $severity, $fixable);
664
+
665
+	}//end addError()
666
+
667
+
668
+	/**
669
+	 * Records a warning against a specific token in the file.
670
+	 *
671
+	 * @param string  $warning  The error message.
672
+	 * @param int     $stackPtr The stack position where the error occurred.
673
+	 * @param string  $code     A violation code unique to the sniff message.
674
+	 * @param array   $data     Replacements for the warning message.
675
+	 * @param int     $severity The severity level for this warning. A value of 0
676
+	 *                          will be converted into the default severity level.
677
+	 * @param boolean $fixable  Can the warning be fixed by the sniff?
678
+	 *
679
+	 * @return boolean
680
+	 */
681
+	public function addWarning(
682
+		$warning,
683
+		$stackPtr,
684
+		$code,
685
+		$data=[],
686
+		$severity=0,
687
+		$fixable=false
688
+	) {
689
+		if ($stackPtr === null) {
690
+			$line   = 1;
691
+			$column = 1;
692
+		} else {
693
+			$line   = $this->tokens[$stackPtr]['line'];
694
+			$column = $this->tokens[$stackPtr]['column'];
695
+		}
696
+
697
+		return $this->addMessage(false, $warning, $line, $column, $code, $data, $severity, $fixable);
698
+
699
+	}//end addWarning()
700
+
701
+
702
+	/**
703
+	 * Records an error against a specific line in the file.
704
+	 *
705
+	 * @param string $error    The error message.
706
+	 * @param int    $line     The line on which the error occurred.
707
+	 * @param string $code     A violation code unique to the sniff message.
708
+	 * @param array  $data     Replacements for the error message.
709
+	 * @param int    $severity The severity level for this error. A value of 0
710
+	 *                         will be converted into the default severity level.
711
+	 *
712
+	 * @return boolean
713
+	 */
714
+	public function addErrorOnLine(
715
+		$error,
716
+		$line,
717
+		$code,
718
+		$data=[],
719
+		$severity=0
720
+	) {
721
+		return $this->addMessage(true, $error, $line, 1, $code, $data, $severity, false);
722
+
723
+	}//end addErrorOnLine()
724
+
725
+
726
+	/**
727
+	 * Records a warning against a specific token in the file.
728
+	 *
729
+	 * @param string $warning  The error message.
730
+	 * @param int    $line     The line on which the warning occurred.
731
+	 * @param string $code     A violation code unique to the sniff message.
732
+	 * @param array  $data     Replacements for the warning message.
733
+	 * @param int    $severity The severity level for this warning. A value of 0 will
734
+	 *                         will be converted into the default severity level.
735
+	 *
736
+	 * @return boolean
737
+	 */
738
+	public function addWarningOnLine(
739
+		$warning,
740
+		$line,
741
+		$code,
742
+		$data=[],
743
+		$severity=0
744
+	) {
745
+		return $this->addMessage(false, $warning, $line, 1, $code, $data, $severity, false);
746
+
747
+	}//end addWarningOnLine()
748
+
749
+
750
+	/**
751
+	 * Records a fixable error against a specific token in the file.
752
+	 *
753
+	 * Returns true if the error was recorded and should be fixed.
754
+	 *
755
+	 * @param string $error    The error message.
756
+	 * @param int    $stackPtr The stack position where the error occurred.
757
+	 * @param string $code     A violation code unique to the sniff message.
758
+	 * @param array  $data     Replacements for the error message.
759
+	 * @param int    $severity The severity level for this error. A value of 0
760
+	 *                         will be converted into the default severity level.
761
+	 *
762
+	 * @return boolean
763
+	 */
764
+	public function addFixableError(
765
+		$error,
766
+		$stackPtr,
767
+		$code,
768
+		$data=[],
769
+		$severity=0
770
+	) {
771
+		$recorded = $this->addError($error, $stackPtr, $code, $data, $severity, true);
772
+		if ($recorded === true && $this->fixer->enabled === true) {
773
+			return true;
774
+		}
775
+
776
+		return false;
777
+
778
+	}//end addFixableError()
779
+
780
+
781
+	/**
782
+	 * Records a fixable warning against a specific token in the file.
783
+	 *
784
+	 * Returns true if the warning was recorded and should be fixed.
785
+	 *
786
+	 * @param string $warning  The error message.
787
+	 * @param int    $stackPtr The stack position where the error occurred.
788
+	 * @param string $code     A violation code unique to the sniff message.
789
+	 * @param array  $data     Replacements for the warning message.
790
+	 * @param int    $severity The severity level for this warning. A value of 0
791
+	 *                         will be converted into the default severity level.
792
+	 *
793
+	 * @return boolean
794
+	 */
795
+	public function addFixableWarning(
796
+		$warning,
797
+		$stackPtr,
798
+		$code,
799
+		$data=[],
800
+		$severity=0
801
+	) {
802
+		$recorded = $this->addWarning($warning, $stackPtr, $code, $data, $severity, true);
803
+		if ($recorded === true && $this->fixer->enabled === true) {
804
+			return true;
805
+		}
806
+
807
+		return false;
808
+
809
+	}//end addFixableWarning()
810
+
811
+
812
+	/**
813
+	 * Adds an error to the error stack.
814
+	 *
815
+	 * @param boolean $error    Is this an error message?
816
+	 * @param string  $message  The text of the message.
817
+	 * @param int     $line     The line on which the message occurred.
818
+	 * @param int     $column   The column at which the message occurred.
819
+	 * @param string  $code     A violation code unique to the sniff message.
820
+	 * @param array   $data     Replacements for the message.
821
+	 * @param int     $severity The severity level for this message. A value of 0
822
+	 *                          will be converted into the default severity level.
823
+	 * @param boolean $fixable  Can the problem be fixed by the sniff?
824
+	 *
825
+	 * @return boolean
826
+	 */
827
+	protected function addMessage($error, $message, $line, $column, $code, $data, $severity, $fixable)
828
+	{
829
+		// Check if this line is ignoring all message codes.
830
+		if (isset($this->tokenizer->ignoredLines[$line]['.all']) === true) {
831
+			return false;
832
+		}
833
+
834
+		// Work out which sniff generated the message.
835
+		$parts = explode('.', $code);
836
+		if ($parts[0] === 'Internal') {
837
+			// An internal message.
838
+			$listenerCode = Util\Common::getSniffCode($this->activeListener);
839
+			$sniffCode    = $code;
840
+			$checkCodes   = [$sniffCode];
841
+		} else {
842
+			if ($parts[0] !== $code) {
843
+				// The full message code has been passed in.
844
+				$sniffCode    = $code;
845
+				$listenerCode = substr($sniffCode, 0, strrpos($sniffCode, '.'));
846
+			} else {
847
+				$listenerCode = Util\Common::getSniffCode($this->activeListener);
848
+				$sniffCode    = $listenerCode.'.'.$code;
849
+				$parts        = explode('.', $sniffCode);
850
+			}
851
+
852
+			$checkCodes = [
853
+				$sniffCode,
854
+				$parts[0].'.'.$parts[1].'.'.$parts[2],
855
+				$parts[0].'.'.$parts[1],
856
+				$parts[0],
857
+			];
858
+		}//end if
859
+
860
+		if (isset($this->tokenizer->ignoredLines[$line]) === true) {
861
+			// Check if this line is ignoring this specific message.
862
+			$ignored = false;
863
+			foreach ($checkCodes as $checkCode) {
864
+				if (isset($this->tokenizer->ignoredLines[$line][$checkCode]) === true) {
865
+					$ignored = true;
866
+					break;
867
+				}
868
+			}
869
+
870
+			// If it is ignored, make sure it's not whitelisted.
871
+			if ($ignored === true
872
+				&& isset($this->tokenizer->ignoredLines[$line]['.except']) === true
873
+			) {
874
+				foreach ($checkCodes as $checkCode) {
875
+					if (isset($this->tokenizer->ignoredLines[$line]['.except'][$checkCode]) === true) {
876
+						$ignored = false;
877
+						break;
878
+					}
879
+				}
880
+			}
881
+
882
+			if ($ignored === true) {
883
+				return false;
884
+			}
885
+		}//end if
886
+
887
+		$includeAll = true;
888
+		if ($this->configCache['cache'] === false
889
+			|| $this->configCache['recordErrors'] === false
890
+		) {
891
+			$includeAll = false;
892
+		}
893
+
894
+		// Filter out any messages for sniffs that shouldn't have run
895
+		// due to the use of the --sniffs command line argument.
896
+		if ($includeAll === false
897
+			&& ((empty($this->configCache['sniffs']) === false
898
+			&& in_array(strtolower($listenerCode), $this->configCache['sniffs'], true) === false)
899
+			|| (empty($this->configCache['exclude']) === false
900
+			&& in_array(strtolower($listenerCode), $this->configCache['exclude'], true) === true))
901
+		) {
902
+			return false;
903
+		}
904
+
905
+		// If we know this sniff code is being ignored for this file, return early.
906
+		foreach ($checkCodes as $checkCode) {
907
+			if (isset($this->ignoredCodes[$checkCode]) === true) {
908
+				return false;
909
+			}
910
+		}
911
+
912
+		$oppositeType = 'warning';
913
+		if ($error === false) {
914
+			$oppositeType = 'error';
915
+		}
916
+
917
+		foreach ($checkCodes as $checkCode) {
918
+			// Make sure this message type has not been set to the opposite message type.
919
+			if (isset($this->ruleset->ruleset[$checkCode]['type']) === true
920
+				&& $this->ruleset->ruleset[$checkCode]['type'] === $oppositeType
921
+			) {
922
+				$error = !$error;
923
+				break;
924
+			}
925
+		}
926
+
927
+		if ($error === true) {
928
+			$configSeverity = $this->configCache['errorSeverity'];
929
+			$messageCount   = &$this->errorCount;
930
+			$messages       = &$this->errors;
931
+		} else {
932
+			$configSeverity = $this->configCache['warningSeverity'];
933
+			$messageCount   = &$this->warningCount;
934
+			$messages       = &$this->warnings;
935
+		}
936
+
937
+		if ($includeAll === false && $configSeverity === 0) {
938
+			// Don't bother doing any processing as these messages are just going to
939
+			// be hidden in the reports anyway.
940
+			return false;
941
+		}
942
+
943
+		if ($severity === 0) {
944
+			$severity = 5;
945
+		}
946
+
947
+		foreach ($checkCodes as $checkCode) {
948
+			// Make sure we are interested in this severity level.
949
+			if (isset($this->ruleset->ruleset[$checkCode]['severity']) === true) {
950
+				$severity = $this->ruleset->ruleset[$checkCode]['severity'];
951
+				break;
952
+			}
953
+		}
954
+
955
+		if ($includeAll === false && $configSeverity > $severity) {
956
+			return false;
957
+		}
958
+
959
+		// Make sure we are not ignoring this file.
960
+		$included = null;
961
+		foreach ($checkCodes as $checkCode) {
962
+			$patterns = null;
963
+
964
+			if (isset($this->configCache['includePatterns'][$checkCode]) === true) {
965
+				$patterns  = $this->configCache['includePatterns'][$checkCode];
966
+				$excluding = false;
967
+			} else if (isset($this->configCache['ignorePatterns'][$checkCode]) === true) {
968
+				$patterns  = $this->configCache['ignorePatterns'][$checkCode];
969
+				$excluding = true;
970
+			}
971
+
972
+			if ($patterns === null) {
973
+				continue;
974
+			}
975
+
976
+			foreach ($patterns as $pattern => $type) {
977
+				// While there is support for a type of each pattern
978
+				// (absolute or relative) we don't actually support it here.
979
+				$replacements = [
980
+					'\\,' => ',',
981
+					'*'   => '.*',
982
+				];
983
+
984
+				// We assume a / directory separator, as do the exclude rules
985
+				// most developers write, so we need a special case for any system
986
+				// that is different.
987
+				if (DIRECTORY_SEPARATOR === '\\') {
988
+					$replacements['/'] = '\\\\';
989
+				}
990
+
991
+				$pattern = '`'.strtr($pattern, $replacements).'`i';
992
+				$matched = preg_match($pattern, $this->path);
993
+
994
+				if ($matched === 0) {
995
+					if ($excluding === false && $included === null) {
996
+						// This file path is not being included.
997
+						$included = false;
998
+					}
999
+
1000
+					continue;
1001
+				}
1002
+
1003
+				if ($excluding === true) {
1004
+					// This file path is being excluded.
1005
+					$this->ignoredCodes[$checkCode] = true;
1006
+					return false;
1007
+				}
1008
+
1009
+				// This file path is being included.
1010
+				$included = true;
1011
+				break;
1012
+			}//end foreach
1013
+		}//end foreach
1014
+
1015
+		if ($included === false) {
1016
+			// There were include rules set, but this file
1017
+			// path didn't match any of them.
1018
+			return false;
1019
+		}
1020
+
1021
+		$messageCount++;
1022
+		if ($fixable === true) {
1023
+			$this->fixableCount++;
1024
+		}
1025
+
1026
+		if ($this->configCache['recordErrors'] === false
1027
+			&& $includeAll === false
1028
+		) {
1029
+			return true;
1030
+		}
1031
+
1032
+		// Work out the error message.
1033
+		if (isset($this->ruleset->ruleset[$sniffCode]['message']) === true) {
1034
+			$message = $this->ruleset->ruleset[$sniffCode]['message'];
1035
+		}
1036
+
1037
+		if (empty($data) === false) {
1038
+			$message = vsprintf($message, $data);
1039
+		}
1040
+
1041
+		if (isset($messages[$line]) === false) {
1042
+			$messages[$line] = [];
1043
+		}
1044
+
1045
+		if (isset($messages[$line][$column]) === false) {
1046
+			$messages[$line][$column] = [];
1047
+		}
1048
+
1049
+		$messages[$line][$column][] = [
1050
+			'message'  => $message,
1051
+			'source'   => $sniffCode,
1052
+			'listener' => $this->activeListener,
1053
+			'severity' => $severity,
1054
+			'fixable'  => $fixable,
1055
+		];
1056
+
1057
+		if (PHP_CODESNIFFER_VERBOSITY > 1
1058
+			&& $this->fixer->enabled === true
1059
+			&& $fixable === true
1060
+		) {
1061
+			@ob_end_clean();
1062
+			echo "\tE: [Line $line] $message ($sniffCode)".PHP_EOL;
1063
+			ob_start();
1064
+		}
1065
+
1066
+		return true;
1067
+
1068
+	}//end addMessage()
1069
+
1070
+
1071
+	/**
1072
+	 * Record a metric about the file being examined.
1073
+	 *
1074
+	 * @param int    $stackPtr The stack position where the metric was recorded.
1075
+	 * @param string $metric   The name of the metric being recorded.
1076
+	 * @param string $value    The value of the metric being recorded.
1077
+	 *
1078
+	 * @return boolean
1079
+	 */
1080
+	public function recordMetric($stackPtr, $metric, $value)
1081
+	{
1082
+		if (isset($this->metrics[$metric]) === false) {
1083
+			$this->metrics[$metric] = ['values' => [$value => 1]];
1084
+			$this->metricTokens[$metric][$stackPtr] = true;
1085
+		} else if (isset($this->metricTokens[$metric][$stackPtr]) === false) {
1086
+			$this->metricTokens[$metric][$stackPtr] = true;
1087
+			if (isset($this->metrics[$metric]['values'][$value]) === false) {
1088
+				$this->metrics[$metric]['values'][$value] = 1;
1089
+			} else {
1090
+				$this->metrics[$metric]['values'][$value]++;
1091
+			}
1092
+		}
1093
+
1094
+		return true;
1095
+
1096
+	}//end recordMetric()
1097
+
1098
+
1099
+	/**
1100
+	 * Returns the number of errors raised.
1101
+	 *
1102
+	 * @return int
1103
+	 */
1104
+	public function getErrorCount()
1105
+	{
1106
+		return $this->errorCount;
1107
+
1108
+	}//end getErrorCount()
1109
+
1110
+
1111
+	/**
1112
+	 * Returns the number of warnings raised.
1113
+	 *
1114
+	 * @return int
1115
+	 */
1116
+	public function getWarningCount()
1117
+	{
1118
+		return $this->warningCount;
1119
+
1120
+	}//end getWarningCount()
1121
+
1122
+
1123
+	/**
1124
+	 * Returns the number of fixable errors/warnings raised.
1125
+	 *
1126
+	 * @return int
1127
+	 */
1128
+	public function getFixableCount()
1129
+	{
1130
+		return $this->fixableCount;
1131
+
1132
+	}//end getFixableCount()
1133
+
1134
+
1135
+	/**
1136
+	 * Returns the number of fixed errors/warnings.
1137
+	 *
1138
+	 * @return int
1139
+	 */
1140
+	public function getFixedCount()
1141
+	{
1142
+		return $this->fixedCount;
1143
+
1144
+	}//end getFixedCount()
1145
+
1146
+
1147
+	/**
1148
+	 * Returns the list of ignored lines.
1149
+	 *
1150
+	 * @return array
1151
+	 */
1152
+	public function getIgnoredLines()
1153
+	{
1154
+		return $this->tokenizer->ignoredLines;
1155
+
1156
+	}//end getIgnoredLines()
1157
+
1158
+
1159
+	/**
1160
+	 * Returns the errors raised from processing this file.
1161
+	 *
1162
+	 * @return array
1163
+	 */
1164
+	public function getErrors()
1165
+	{
1166
+		return $this->errors;
1167
+
1168
+	}//end getErrors()
1169
+
1170
+
1171
+	/**
1172
+	 * Returns the warnings raised from processing this file.
1173
+	 *
1174
+	 * @return array
1175
+	 */
1176
+	public function getWarnings()
1177
+	{
1178
+		return $this->warnings;
1179
+
1180
+	}//end getWarnings()
1181
+
1182
+
1183
+	/**
1184
+	 * Returns the metrics found while processing this file.
1185
+	 *
1186
+	 * @return array
1187
+	 */
1188
+	public function getMetrics()
1189
+	{
1190
+		return $this->metrics;
1191
+
1192
+	}//end getMetrics()
1193
+
1194
+
1195
+	/**
1196
+	 * Returns the absolute filename of this file.
1197
+	 *
1198
+	 * @return string
1199
+	 */
1200
+	public function getFilename()
1201
+	{
1202
+		return $this->path;
1203
+
1204
+	}//end getFilename()
1205
+
1206
+
1207
+	/**
1208
+	 * Returns the declaration names for classes, interfaces, traits, and functions.
1209
+	 *
1210
+	 * @param int $stackPtr The position of the declaration token which
1211
+	 *                      declared the class, interface, trait, or function.
1212
+	 *
1213
+	 * @return string|null The name of the class, interface, trait, or function;
1214
+	 *                     or NULL if the function or class is anonymous.
1215
+	 * @throws \PHP_CodeSniffer\Exceptions\RuntimeException If the specified token is not of type
1216
+	 *                                                      T_FUNCTION, T_CLASS, T_ANON_CLASS,
1217
+	 *                                                      T_CLOSURE, T_TRAIT, or T_INTERFACE.
1218
+	 */
1219
+	public function getDeclarationName($stackPtr)
1220
+	{
1221
+		$tokenCode = $this->tokens[$stackPtr]['code'];
1222
+
1223
+		if ($tokenCode === T_ANON_CLASS || $tokenCode === T_CLOSURE) {
1224
+			return null;
1225
+		}
1226
+
1227
+		if ($tokenCode !== T_FUNCTION
1228
+			&& $tokenCode !== T_CLASS
1229
+			&& $tokenCode !== T_INTERFACE
1230
+			&& $tokenCode !== T_TRAIT
1231
+		) {
1232
+			throw new RuntimeException('Token type "'.$this->tokens[$stackPtr]['type'].'" is not T_FUNCTION, T_CLASS, T_INTERFACE or T_TRAIT');
1233
+		}
1234
+
1235
+		if ($tokenCode === T_FUNCTION
1236
+			&& strtolower($this->tokens[$stackPtr]['content']) !== 'function'
1237
+		) {
1238
+			// This is a function declared without the "function" keyword.
1239
+			// So this token is the function name.
1240
+			return $this->tokens[$stackPtr]['content'];
1241
+		}
1242
+
1243
+		$content = null;
1244
+		for ($i = $stackPtr; $i < $this->numTokens; $i++) {
1245
+			if ($this->tokens[$i]['code'] === T_STRING) {
1246
+				$content = $this->tokens[$i]['content'];
1247
+				break;
1248
+			}
1249
+		}
1250
+
1251
+		return $content;
1252
+
1253
+	}//end getDeclarationName()
1254
+
1255
+
1256
+	/**
1257
+	 * Returns the method parameters for the specified function token.
1258
+	 *
1259
+	 * Each parameter is in the following format:
1260
+	 *
1261
+	 * <code>
1262
+	 *   0 => array(
1263
+	 *         'name'              => '$var',  // The variable name.
1264
+	 *         'token'             => integer, // The stack pointer to the variable name.
1265
+	 *         'content'           => string,  // The full content of the variable definition.
1266
+	 *         'pass_by_reference' => boolean, // Is the variable passed by reference?
1267
+	 *         'variable_length'   => boolean, // Is the param of variable length through use of `...` ?
1268
+	 *         'type_hint'         => string,  // The type hint for the variable.
1269
+	 *         'type_hint_token'   => integer, // The stack pointer to the type hint
1270
+	 *                                         // or false if there is no type hint.
1271
+	 *         'nullable_type'     => boolean, // Is the variable using a nullable type?
1272
+	 *        )
1273
+	 * </code>
1274
+	 *
1275
+	 * Parameters with default values have an additional array index of
1276
+	 * 'default' with the value of the default as a string.
1277
+	 *
1278
+	 * @param int $stackPtr The position in the stack of the function token
1279
+	 *                      to acquire the parameters for.
1280
+	 *
1281
+	 * @return array
1282
+	 * @throws \PHP_CodeSniffer\Exceptions\TokenizerException If the specified $stackPtr is not of
1283
+	 *                                                        type T_FUNCTION or T_CLOSURE.
1284
+	 */
1285
+	public function getMethodParameters($stackPtr)
1286
+	{
1287
+		if ($this->tokens[$stackPtr]['code'] !== T_FUNCTION
1288
+			&& $this->tokens[$stackPtr]['code'] !== T_CLOSURE
1289
+		) {
1290
+			throw new TokenizerException('$stackPtr must be of type T_FUNCTION or T_CLOSURE');
1291
+		}
1292
+
1293
+		$opener = $this->tokens[$stackPtr]['parenthesis_opener'];
1294
+		$closer = $this->tokens[$stackPtr]['parenthesis_closer'];
1295
+
1296
+		$vars            = [];
1297
+		$currVar         = null;
1298
+		$paramStart      = ($opener + 1);
1299
+		$defaultStart    = null;
1300
+		$paramCount      = 0;
1301
+		$passByReference = false;
1302
+		$variableLength  = false;
1303
+		$typeHint        = '';
1304
+		$typeHintToken   = false;
1305
+		$nullableType    = false;
1306
+
1307
+		for ($i = $paramStart; $i <= $closer; $i++) {
1308
+			// Check to see if this token has a parenthesis or bracket opener. If it does
1309
+			// it's likely to be an array which might have arguments in it. This
1310
+			// could cause problems in our parsing below, so lets just skip to the
1311
+			// end of it.
1312
+			if (isset($this->tokens[$i]['parenthesis_opener']) === true) {
1313
+				// Don't do this if it's the close parenthesis for the method.
1314
+				if ($i !== $this->tokens[$i]['parenthesis_closer']) {
1315
+					$i = ($this->tokens[$i]['parenthesis_closer'] + 1);
1316
+				}
1317
+			}
1318
+
1319
+			if (isset($this->tokens[$i]['bracket_opener']) === true) {
1320
+				// Don't do this if it's the close parenthesis for the method.
1321
+				if ($i !== $this->tokens[$i]['bracket_closer']) {
1322
+					$i = ($this->tokens[$i]['bracket_closer'] + 1);
1323
+				}
1324
+			}
1325
+
1326
+			switch ($this->tokens[$i]['code']) {
1327
+			case T_BITWISE_AND:
1328
+				if ($defaultStart === null) {
1329
+					$passByReference = true;
1330
+				}
1331
+				break;
1332
+			case T_VARIABLE:
1333
+				$currVar = $i;
1334
+				break;
1335
+			case T_ELLIPSIS:
1336
+				$variableLength = true;
1337
+				break;
1338
+			case T_CALLABLE:
1339
+				if ($typeHintToken === false) {
1340
+					$typeHintToken = $i;
1341
+				}
1342
+
1343
+				$typeHint .= $this->tokens[$i]['content'];
1344
+				break;
1345
+			case T_SELF:
1346
+			case T_PARENT:
1347
+			case T_STATIC:
1348
+				// Self and parent are valid, static invalid, but was probably intended as type hint.
1349
+				if (isset($defaultStart) === false) {
1350
+					if ($typeHintToken === false) {
1351
+						$typeHintToken = $i;
1352
+					}
1353
+
1354
+					$typeHint .= $this->tokens[$i]['content'];
1355
+				}
1356
+				break;
1357
+			case T_STRING:
1358
+				// This is a string, so it may be a type hint, but it could
1359
+				// also be a constant used as a default value.
1360
+				$prevComma = false;
1361
+				for ($t = $i; $t >= $opener; $t--) {
1362
+					if ($this->tokens[$t]['code'] === T_COMMA) {
1363
+						$prevComma = $t;
1364
+						break;
1365
+					}
1366
+				}
1367
+
1368
+				if ($prevComma !== false) {
1369
+					$nextEquals = false;
1370
+					for ($t = $prevComma; $t < $i; $t++) {
1371
+						if ($this->tokens[$t]['code'] === T_EQUAL) {
1372
+							$nextEquals = $t;
1373
+							break;
1374
+						}
1375
+					}
1376
+
1377
+					if ($nextEquals !== false) {
1378
+						break;
1379
+					}
1380
+				}
1381
+
1382
+				if ($defaultStart === null) {
1383
+					if ($typeHintToken === false) {
1384
+						$typeHintToken = $i;
1385
+					}
1386
+
1387
+					$typeHint .= $this->tokens[$i]['content'];
1388
+				}
1389
+				break;
1390
+			case T_NS_SEPARATOR:
1391
+				// Part of a type hint or default value.
1392
+				if ($defaultStart === null) {
1393
+					if ($typeHintToken === false) {
1394
+						$typeHintToken = $i;
1395
+					}
1396
+
1397
+					$typeHint .= $this->tokens[$i]['content'];
1398
+				}
1399
+				break;
1400
+			case T_NULLABLE:
1401
+				if ($defaultStart === null) {
1402
+					$nullableType = true;
1403
+					$typeHint    .= $this->tokens[$i]['content'];
1404
+				}
1405
+				break;
1406
+			case T_CLOSE_PARENTHESIS:
1407
+			case T_COMMA:
1408
+				// If it's null, then there must be no parameters for this
1409
+				// method.
1410
+				if ($currVar === null) {
1411
+					continue 2;
1412
+				}
1413
+
1414
+				$vars[$paramCount]            = [];
1415
+				$vars[$paramCount]['token']   = $currVar;
1416
+				$vars[$paramCount]['name']    = $this->tokens[$currVar]['content'];
1417
+				$vars[$paramCount]['content'] = trim($this->getTokensAsString($paramStart, ($i - $paramStart)));
1418
+
1419
+				if ($defaultStart !== null) {
1420
+					$vars[$paramCount]['default'] = trim($this->getTokensAsString($defaultStart, ($i - $defaultStart)));
1421
+				}
1422
+
1423
+				$vars[$paramCount]['pass_by_reference'] = $passByReference;
1424
+				$vars[$paramCount]['variable_length']   = $variableLength;
1425
+				$vars[$paramCount]['type_hint']         = $typeHint;
1426
+				$vars[$paramCount]['type_hint_token']   = $typeHintToken;
1427
+				$vars[$paramCount]['nullable_type']     = $nullableType;
1428
+
1429
+				// Reset the vars, as we are about to process the next parameter.
1430
+				$defaultStart    = null;
1431
+				$paramStart      = ($i + 1);
1432
+				$passByReference = false;
1433
+				$variableLength  = false;
1434
+				$typeHint        = '';
1435
+				$typeHintToken   = false;
1436
+				$nullableType    = false;
1437
+
1438
+				$paramCount++;
1439
+				break;
1440
+			case T_EQUAL:
1441
+				$defaultStart = ($i + 1);
1442
+				break;
1443
+			}//end switch
1444
+		}//end for
1445
+
1446
+		return $vars;
1447
+
1448
+	}//end getMethodParameters()
1449
+
1450
+
1451
+	/**
1452
+	 * Returns the visibility and implementation properties of a method.
1453
+	 *
1454
+	 * The format of the array is:
1455
+	 * <code>
1456
+	 *   array(
1457
+	 *    'scope'                => 'public', // public protected or protected
1458
+	 *    'scope_specified'      => true,     // true is scope keyword was found.
1459
+	 *    'return_type'          => '',       // the return type of the method.
1460
+	 *    'return_type_token'    => integer,  // The stack pointer to the start of the return type
1461
+	 *                                        // or false if there is no return type.
1462
+	 *    'nullable_return_type' => false,    // true if the return type is nullable.
1463
+	 *    'is_abstract'          => false,    // true if the abstract keyword was found.
1464
+	 *    'is_final'             => false,    // true if the final keyword was found.
1465
+	 *    'is_static'            => false,    // true if the static keyword was found.
1466
+	 *    'has_body'             => false,    // true if the method has a body
1467
+	 *   );
1468
+	 * </code>
1469
+	 *
1470
+	 * @param int $stackPtr The position in the stack of the function token to
1471
+	 *                      acquire the properties for.
1472
+	 *
1473
+	 * @return array
1474
+	 * @throws \PHP_CodeSniffer\Exceptions\TokenizerException If the specified position is not a
1475
+	 *                                                        T_FUNCTION token.
1476
+	 */
1477
+	public function getMethodProperties($stackPtr)
1478
+	{
1479
+		if ($this->tokens[$stackPtr]['code'] !== T_FUNCTION
1480
+			&& $this->tokens[$stackPtr]['code'] !== T_CLOSURE
1481
+		) {
1482
+			throw new TokenizerException('$stackPtr must be of type T_FUNCTION or T_CLOSURE');
1483
+		}
1484
+
1485
+		if ($this->tokens[$stackPtr]['code'] === T_FUNCTION) {
1486
+			$valid = [
1487
+				T_PUBLIC      => T_PUBLIC,
1488
+				T_PRIVATE     => T_PRIVATE,
1489
+				T_PROTECTED   => T_PROTECTED,
1490
+				T_STATIC      => T_STATIC,
1491
+				T_FINAL       => T_FINAL,
1492
+				T_ABSTRACT    => T_ABSTRACT,
1493
+				T_WHITESPACE  => T_WHITESPACE,
1494
+				T_COMMENT     => T_COMMENT,
1495
+				T_DOC_COMMENT => T_DOC_COMMENT,
1496
+			];
1497
+		} else {
1498
+			$valid = [
1499
+				T_STATIC      => T_STATIC,
1500
+				T_WHITESPACE  => T_WHITESPACE,
1501
+				T_COMMENT     => T_COMMENT,
1502
+				T_DOC_COMMENT => T_DOC_COMMENT,
1503
+			];
1504
+		}
1505
+
1506
+		$scope          = 'public';
1507
+		$scopeSpecified = false;
1508
+		$isAbstract     = false;
1509
+		$isFinal        = false;
1510
+		$isStatic       = false;
1511
+
1512
+		for ($i = ($stackPtr - 1); $i > 0; $i--) {
1513
+			if (isset($valid[$this->tokens[$i]['code']]) === false) {
1514
+				break;
1515
+			}
1516
+
1517
+			switch ($this->tokens[$i]['code']) {
1518
+			case T_PUBLIC:
1519
+				$scope          = 'public';
1520
+				$scopeSpecified = true;
1521
+				break;
1522
+			case T_PRIVATE:
1523
+				$scope          = 'private';
1524
+				$scopeSpecified = true;
1525
+				break;
1526
+			case T_PROTECTED:
1527
+				$scope          = 'protected';
1528
+				$scopeSpecified = true;
1529
+				break;
1530
+			case T_ABSTRACT:
1531
+				$isAbstract = true;
1532
+				break;
1533
+			case T_FINAL:
1534
+				$isFinal = true;
1535
+				break;
1536
+			case T_STATIC:
1537
+				$isStatic = true;
1538
+				break;
1539
+			}//end switch
1540
+		}//end for
1541
+
1542
+		$returnType         = '';
1543
+		$returnTypeToken    = false;
1544
+		$nullableReturnType = false;
1545
+		$hasBody            = true;
1546
+
1547
+		if (isset($this->tokens[$stackPtr]['parenthesis_closer']) === true) {
1548
+			$scopeOpener = null;
1549
+			if (isset($this->tokens[$stackPtr]['scope_opener']) === true) {
1550
+				$scopeOpener = $this->tokens[$stackPtr]['scope_opener'];
1551
+			}
1552
+
1553
+			$valid = [
1554
+				T_STRING       => T_STRING,
1555
+				T_CALLABLE     => T_CALLABLE,
1556
+				T_SELF         => T_SELF,
1557
+				T_PARENT       => T_PARENT,
1558
+				T_NS_SEPARATOR => T_NS_SEPARATOR,
1559
+			];
1560
+
1561
+			for ($i = $this->tokens[$stackPtr]['parenthesis_closer']; $i < $this->numTokens; $i++) {
1562
+				if (($scopeOpener === null && $this->tokens[$i]['code'] === T_SEMICOLON)
1563
+					|| ($scopeOpener !== null && $i === $scopeOpener)
1564
+				) {
1565
+					// End of function definition.
1566
+					break;
1567
+				}
1568
+
1569
+				if ($this->tokens[$i]['code'] === T_NULLABLE) {
1570
+					$nullableReturnType = true;
1571
+				}
1572
+
1573
+				if (isset($valid[$this->tokens[$i]['code']]) === true) {
1574
+					if ($returnTypeToken === false) {
1575
+						$returnTypeToken = $i;
1576
+					}
1577
+
1578
+					$returnType .= $this->tokens[$i]['content'];
1579
+				}
1580
+			}
1581
+
1582
+			$end     = $this->findNext([T_OPEN_CURLY_BRACKET, T_SEMICOLON], $this->tokens[$stackPtr]['parenthesis_closer']);
1583
+			$hasBody = $this->tokens[$end]['code'] === T_OPEN_CURLY_BRACKET;
1584
+		}//end if
1585
+
1586
+		if ($returnType !== '' && $nullableReturnType === true) {
1587
+			$returnType = '?'.$returnType;
1588
+		}
1589
+
1590
+		return [
1591
+			'scope'                => $scope,
1592
+			'scope_specified'      => $scopeSpecified,
1593
+			'return_type'          => $returnType,
1594
+			'return_type_token'    => $returnTypeToken,
1595
+			'nullable_return_type' => $nullableReturnType,
1596
+			'is_abstract'          => $isAbstract,
1597
+			'is_final'             => $isFinal,
1598
+			'is_static'            => $isStatic,
1599
+			'has_body'             => $hasBody,
1600
+		];
1601
+
1602
+	}//end getMethodProperties()
1603
+
1604
+
1605
+	/**
1606
+	 * Returns the visibility and implementation properties of the class member
1607
+	 * variable found at the specified position in the stack.
1608
+	 *
1609
+	 * The format of the array is:
1610
+	 *
1611
+	 * <code>
1612
+	 *   array(
1613
+	 *    'scope'           => 'public', // public protected or protected.
1614
+	 *    'scope_specified' => false,    // true if the scope was explicitly specified.
1615
+	 *    'is_static'       => false,    // true if the static keyword was found.
1616
+	 *   );
1617
+	 * </code>
1618
+	 *
1619
+	 * @param int $stackPtr The position in the stack of the T_VARIABLE token to
1620
+	 *                      acquire the properties for.
1621
+	 *
1622
+	 * @return array
1623
+	 * @throws \PHP_CodeSniffer\Exceptions\TokenizerException If the specified position is not a
1624
+	 *                                                        T_VARIABLE token, or if the position is not
1625
+	 *                                                        a class member variable.
1626
+	 */
1627
+	public function getMemberProperties($stackPtr)
1628
+	{
1629
+		if ($this->tokens[$stackPtr]['code'] !== T_VARIABLE) {
1630
+			throw new TokenizerException('$stackPtr must be of type T_VARIABLE');
1631
+		}
1632
+
1633
+		$conditions = array_keys($this->tokens[$stackPtr]['conditions']);
1634
+		$ptr        = array_pop($conditions);
1635
+		if (isset($this->tokens[$ptr]) === false
1636
+			|| ($this->tokens[$ptr]['code'] !== T_CLASS
1637
+			&& $this->tokens[$ptr]['code'] !== T_ANON_CLASS
1638
+			&& $this->tokens[$ptr]['code'] !== T_TRAIT)
1639
+		) {
1640
+			if (isset($this->tokens[$ptr]) === true
1641
+				&& $this->tokens[$ptr]['code'] === T_INTERFACE
1642
+			) {
1643
+				// T_VARIABLEs in interfaces can actually be method arguments
1644
+				// but they wont be seen as being inside the method because there
1645
+				// are no scope openers and closers for abstract methods. If it is in
1646
+				// parentheses, we can be pretty sure it is a method argument.
1647
+				if (isset($this->tokens[$stackPtr]['nested_parenthesis']) === false
1648
+					|| empty($this->tokens[$stackPtr]['nested_parenthesis']) === true
1649
+				) {
1650
+					$error = 'Possible parse error: interfaces may not include member vars';
1651
+					$this->addWarning($error, $stackPtr, 'Internal.ParseError.InterfaceHasMemberVar');
1652
+					return [];
1653
+				}
1654
+			} else {
1655
+				throw new TokenizerException('$stackPtr is not a class member var');
1656
+			}
1657
+		}
1658
+
1659
+		// Make sure it's not a method parameter.
1660
+		if (empty($this->tokens[$stackPtr]['nested_parenthesis']) === false) {
1661
+			$parenthesis = array_keys($this->tokens[$stackPtr]['nested_parenthesis']);
1662
+			$deepestOpen = array_pop($parenthesis);
1663
+			if ($deepestOpen > $ptr
1664
+				&& isset($this->tokens[$deepestOpen]['parenthesis_owner']) === true
1665
+				&& $this->tokens[$this->tokens[$deepestOpen]['parenthesis_owner']]['code'] === T_FUNCTION
1666
+			) {
1667
+				throw new TokenizerException('$stackPtr is not a class member var');
1668
+			}
1669
+		}
1670
+
1671
+		$valid = [
1672
+			T_PUBLIC    => T_PUBLIC,
1673
+			T_PRIVATE   => T_PRIVATE,
1674
+			T_PROTECTED => T_PROTECTED,
1675
+			T_STATIC    => T_STATIC,
1676
+			T_VAR       => T_VAR,
1677
+		];
1678
+
1679
+		$valid += Util\Tokens::$emptyTokens;
1680
+
1681
+		$scope          = 'public';
1682
+		$scopeSpecified = false;
1683
+		$isStatic       = false;
1684
+
1685
+		$startOfStatement = $this->findPrevious(
1686
+			[
1687
+				T_SEMICOLON,
1688
+				T_OPEN_CURLY_BRACKET,
1689
+				T_CLOSE_CURLY_BRACKET,
1690
+			],
1691
+			($stackPtr - 1)
1692
+		);
1693
+
1694
+		for ($i = ($startOfStatement + 1); $i < $stackPtr; $i++) {
1695
+			if (isset($valid[$this->tokens[$i]['code']]) === false) {
1696
+				break;
1697
+			}
1698
+
1699
+			switch ($this->tokens[$i]['code']) {
1700
+			case T_PUBLIC:
1701
+				$scope          = 'public';
1702
+				$scopeSpecified = true;
1703
+				break;
1704
+			case T_PRIVATE:
1705
+				$scope          = 'private';
1706
+				$scopeSpecified = true;
1707
+				break;
1708
+			case T_PROTECTED:
1709
+				$scope          = 'protected';
1710
+				$scopeSpecified = true;
1711
+				break;
1712
+			case T_STATIC:
1713
+				$isStatic = true;
1714
+				break;
1715
+			}
1716
+		}//end for
1717
+
1718
+		return [
1719
+			'scope'           => $scope,
1720
+			'scope_specified' => $scopeSpecified,
1721
+			'is_static'       => $isStatic,
1722
+		];
1723
+
1724
+	}//end getMemberProperties()
1725
+
1726
+
1727
+	/**
1728
+	 * Returns the visibility and implementation properties of a class.
1729
+	 *
1730
+	 * The format of the array is:
1731
+	 * <code>
1732
+	 *   array(
1733
+	 *    'is_abstract' => false, // true if the abstract keyword was found.
1734
+	 *    'is_final'    => false, // true if the final keyword was found.
1735
+	 *   );
1736
+	 * </code>
1737
+	 *
1738
+	 * @param int $stackPtr The position in the stack of the T_CLASS token to
1739
+	 *                      acquire the properties for.
1740
+	 *
1741
+	 * @return array
1742
+	 * @throws \PHP_CodeSniffer\Exceptions\TokenizerException If the specified position is not a
1743
+	 *                                                        T_CLASS token.
1744
+	 */
1745
+	public function getClassProperties($stackPtr)
1746
+	{
1747
+		if ($this->tokens[$stackPtr]['code'] !== T_CLASS) {
1748
+			throw new TokenizerException('$stackPtr must be of type T_CLASS');
1749
+		}
1750
+
1751
+		$valid = [
1752
+			T_FINAL       => T_FINAL,
1753
+			T_ABSTRACT    => T_ABSTRACT,
1754
+			T_WHITESPACE  => T_WHITESPACE,
1755
+			T_COMMENT     => T_COMMENT,
1756
+			T_DOC_COMMENT => T_DOC_COMMENT,
1757
+		];
1758
+
1759
+		$isAbstract = false;
1760
+		$isFinal    = false;
1761
+
1762
+		for ($i = ($stackPtr - 1); $i > 0; $i--) {
1763
+			if (isset($valid[$this->tokens[$i]['code']]) === false) {
1764
+				break;
1765
+			}
1766
+
1767
+			switch ($this->tokens[$i]['code']) {
1768
+			case T_ABSTRACT:
1769
+				$isAbstract = true;
1770
+				break;
1771
+
1772
+			case T_FINAL:
1773
+				$isFinal = true;
1774
+				break;
1775
+			}
1776
+		}//end for
1777
+
1778
+		return [
1779
+			'is_abstract' => $isAbstract,
1780
+			'is_final'    => $isFinal,
1781
+		];
1782
+
1783
+	}//end getClassProperties()
1784
+
1785
+
1786
+	/**
1787
+	 * Determine if the passed token is a reference operator.
1788
+	 *
1789
+	 * Returns true if the specified token position represents a reference.
1790
+	 * Returns false if the token represents a bitwise operator.
1791
+	 *
1792
+	 * @param int $stackPtr The position of the T_BITWISE_AND token.
1793
+	 *
1794
+	 * @return boolean
1795
+	 */
1796
+	public function isReference($stackPtr)
1797
+	{
1798
+		if ($this->tokens[$stackPtr]['code'] !== T_BITWISE_AND) {
1799
+			return false;
1800
+		}
1801
+
1802
+		$tokenBefore = $this->findPrevious(
1803
+			Util\Tokens::$emptyTokens,
1804
+			($stackPtr - 1),
1805
+			null,
1806
+			true
1807
+		);
1808
+
1809
+		if ($this->tokens[$tokenBefore]['code'] === T_FUNCTION) {
1810
+			// Function returns a reference.
1811
+			return true;
1812
+		}
1813
+
1814
+		if ($this->tokens[$tokenBefore]['code'] === T_DOUBLE_ARROW) {
1815
+			// Inside a foreach loop or array assignment, this is a reference.
1816
+			return true;
1817
+		}
1818
+
1819
+		if ($this->tokens[$tokenBefore]['code'] === T_AS) {
1820
+			// Inside a foreach loop, this is a reference.
1821
+			return true;
1822
+		}
1823
+
1824
+		if (isset(Util\Tokens::$assignmentTokens[$this->tokens[$tokenBefore]['code']]) === true) {
1825
+			// This is directly after an assignment. It's a reference. Even if
1826
+			// it is part of an operation, the other tests will handle it.
1827
+			return true;
1828
+		}
1829
+
1830
+		$tokenAfter = $this->findNext(
1831
+			Util\Tokens::$emptyTokens,
1832
+			($stackPtr + 1),
1833
+			null,
1834
+			true
1835
+		);
1836
+
1837
+		if ($this->tokens[$tokenAfter]['code'] === T_NEW) {
1838
+			return true;
1839
+		}
1840
+
1841
+		if (isset($this->tokens[$stackPtr]['nested_parenthesis']) === true) {
1842
+			$brackets    = $this->tokens[$stackPtr]['nested_parenthesis'];
1843
+			$lastBracket = array_pop($brackets);
1844
+			if (isset($this->tokens[$lastBracket]['parenthesis_owner']) === true) {
1845
+				$owner = $this->tokens[$this->tokens[$lastBracket]['parenthesis_owner']];
1846
+				if ($owner['code'] === T_FUNCTION
1847
+					|| $owner['code'] === T_CLOSURE
1848
+				) {
1849
+					$params = $this->getMethodParameters($this->tokens[$lastBracket]['parenthesis_owner']);
1850
+					foreach ($params as $param) {
1851
+						$varToken = $tokenAfter;
1852
+						if ($param['variable_length'] === true) {
1853
+							$varToken = $this->findNext(
1854
+								(Util\Tokens::$emptyTokens + [T_ELLIPSIS]),
1855
+								($stackPtr + 1),
1856
+								null,
1857
+								true
1858
+							);
1859
+						}
1860
+
1861
+						if ($param['token'] === $varToken
1862
+							&& $param['pass_by_reference'] === true
1863
+						) {
1864
+							// Function parameter declared to be passed by reference.
1865
+							return true;
1866
+						}
1867
+					}
1868
+				}//end if
1869
+			} else {
1870
+				$prev = false;
1871
+				for ($t = ($this->tokens[$lastBracket]['parenthesis_opener'] - 1); $t >= 0; $t--) {
1872
+					if ($this->tokens[$t]['code'] !== T_WHITESPACE) {
1873
+						$prev = $t;
1874
+						break;
1875
+					}
1876
+				}
1877
+
1878
+				if ($prev !== false && $this->tokens[$prev]['code'] === T_USE) {
1879
+					// Closure use by reference.
1880
+					return true;
1881
+				}
1882
+			}//end if
1883
+		}//end if
1884
+
1885
+		// Pass by reference in function calls and assign by reference in arrays.
1886
+		if ($this->tokens[$tokenBefore]['code'] === T_OPEN_PARENTHESIS
1887
+			|| $this->tokens[$tokenBefore]['code'] === T_COMMA
1888
+			|| $this->tokens[$tokenBefore]['code'] === T_OPEN_SHORT_ARRAY
1889
+		) {
1890
+			if ($this->tokens[$tokenAfter]['code'] === T_VARIABLE) {
1891
+				return true;
1892
+			} else {
1893
+				$skip   = Util\Tokens::$emptyTokens;
1894
+				$skip[] = T_NS_SEPARATOR;
1895
+				$skip[] = T_SELF;
1896
+				$skip[] = T_PARENT;
1897
+				$skip[] = T_STATIC;
1898
+				$skip[] = T_STRING;
1899
+				$skip[] = T_NAMESPACE;
1900
+				$skip[] = T_DOUBLE_COLON;
1901
+
1902
+				$nextSignificantAfter = $this->findNext(
1903
+					$skip,
1904
+					($stackPtr + 1),
1905
+					null,
1906
+					true
1907
+				);
1908
+				if ($this->tokens[$nextSignificantAfter]['code'] === T_VARIABLE) {
1909
+					return true;
1910
+				}
1911
+			}//end if
1912
+		}//end if
1913
+
1914
+		return false;
1915
+
1916
+	}//end isReference()
1917
+
1918
+
1919
+	/**
1920
+	 * Returns the content of the tokens from the specified start position in
1921
+	 * the token stack for the specified length.
1922
+	 *
1923
+	 * @param int  $start       The position to start from in the token stack.
1924
+	 * @param int  $length      The length of tokens to traverse from the start pos.
1925
+	 * @param bool $origContent Whether the original content or the tab replaced
1926
+	 *                          content should be used.
1927
+	 *
1928
+	 * @return string The token contents.
1929
+	 */
1930
+	public function getTokensAsString($start, $length, $origContent=false)
1931
+	{
1932
+		if (is_int($start) === false || isset($this->tokens[$start]) === false) {
1933
+			throw new RuntimeException('The $start position for getTokensAsString() must exist in the token stack');
1934
+		}
1935
+
1936
+		if (is_int($length) === false || $length <= 0) {
1937
+			return '';
1938
+		}
1939
+
1940
+		$str = '';
1941
+		$end = ($start + $length);
1942
+		if ($end > $this->numTokens) {
1943
+			$end = $this->numTokens;
1944
+		}
1945
+
1946
+		for ($i = $start; $i < $end; $i++) {
1947
+			// If tabs are being converted to spaces by the tokeniser, the
1948
+			// original content should be used instead of the converted content.
1949
+			if ($origContent === true && isset($this->tokens[$i]['orig_content']) === true) {
1950
+				$str .= $this->tokens[$i]['orig_content'];
1951
+			} else {
1952
+				$str .= $this->tokens[$i]['content'];
1953
+			}
1954
+		}
1955
+
1956
+		return $str;
1957
+
1958
+	}//end getTokensAsString()
1959
+
1960
+
1961
+	/**
1962
+	 * Returns the position of the previous specified token(s).
1963
+	 *
1964
+	 * If a value is specified, the previous token of the specified type(s)
1965
+	 * containing the specified value will be returned.
1966
+	 *
1967
+	 * Returns false if no token can be found.
1968
+	 *
1969
+	 * @param int|string|array $types   The type(s) of tokens to search for.
1970
+	 * @param int              $start   The position to start searching from in the
1971
+	 *                                  token stack.
1972
+	 * @param int              $end     The end position to fail if no token is found.
1973
+	 *                                  if not specified or null, end will default to
1974
+	 *                                  the start of the token stack.
1975
+	 * @param bool             $exclude If true, find the previous token that is NOT of
1976
+	 *                                  the types specified in $types.
1977
+	 * @param string           $value   The value that the token(s) must be equal to.
1978
+	 *                                  If value is omitted, tokens with any value will
1979
+	 *                                  be returned.
1980
+	 * @param bool             $local   If true, tokens outside the current statement
1981
+	 *                                  will not be checked. IE. checking will stop
1982
+	 *                                  at the previous semi-colon found.
1983
+	 *
1984
+	 * @return int|bool
1985
+	 * @see    findNext()
1986
+	 */
1987
+	public function findPrevious(
1988
+		$types,
1989
+		$start,
1990
+		$end=null,
1991
+		$exclude=false,
1992
+		$value=null,
1993
+		$local=false
1994
+	) {
1995
+		$types = (array) $types;
1996
+
1997
+		if ($end === null) {
1998
+			$end = 0;
1999
+		}
2000
+
2001
+		for ($i = $start; $i >= $end; $i--) {
2002
+			$found = (bool) $exclude;
2003
+			foreach ($types as $type) {
2004
+				if ($this->tokens[$i]['code'] === $type) {
2005
+					$found = !$exclude;
2006
+					break;
2007
+				}
2008
+			}
2009
+
2010
+			if ($found === true) {
2011
+				if ($value === null) {
2012
+					return $i;
2013
+				} else if ($this->tokens[$i]['content'] === $value) {
2014
+					return $i;
2015
+				}
2016
+			}
2017
+
2018
+			if ($local === true) {
2019
+				if (isset($this->tokens[$i]['scope_opener']) === true
2020
+					&& $i === $this->tokens[$i]['scope_closer']
2021
+				) {
2022
+					$i = $this->tokens[$i]['scope_opener'];
2023
+				} else if (isset($this->tokens[$i]['bracket_opener']) === true
2024
+					&& $i === $this->tokens[$i]['bracket_closer']
2025
+				) {
2026
+					$i = $this->tokens[$i]['bracket_opener'];
2027
+				} else if (isset($this->tokens[$i]['parenthesis_opener']) === true
2028
+					&& $i === $this->tokens[$i]['parenthesis_closer']
2029
+				) {
2030
+					$i = $this->tokens[$i]['parenthesis_opener'];
2031
+				} else if ($this->tokens[$i]['code'] === T_SEMICOLON) {
2032
+					break;
2033
+				}
2034
+			}
2035
+		}//end for
2036
+
2037
+		return false;
2038
+
2039
+	}//end findPrevious()
2040
+
2041
+
2042
+	/**
2043
+	 * Returns the position of the next specified token(s).
2044
+	 *
2045
+	 * If a value is specified, the next token of the specified type(s)
2046
+	 * containing the specified value will be returned.
2047
+	 *
2048
+	 * Returns false if no token can be found.
2049
+	 *
2050
+	 * @param int|string|array $types   The type(s) of tokens to search for.
2051
+	 * @param int              $start   The position to start searching from in the
2052
+	 *                                  token stack.
2053
+	 * @param int              $end     The end position to fail if no token is found.
2054
+	 *                                  if not specified or null, end will default to
2055
+	 *                                  the end of the token stack.
2056
+	 * @param bool             $exclude If true, find the next token that is NOT of
2057
+	 *                                  a type specified in $types.
2058
+	 * @param string           $value   The value that the token(s) must be equal to.
2059
+	 *                                  If value is omitted, tokens with any value will
2060
+	 *                                  be returned.
2061
+	 * @param bool             $local   If true, tokens outside the current statement
2062
+	 *                                  will not be checked. i.e., checking will stop
2063
+	 *                                  at the next semi-colon found.
2064
+	 *
2065
+	 * @return int|bool
2066
+	 * @see    findPrevious()
2067
+	 */
2068
+	public function findNext(
2069
+		$types,
2070
+		$start,
2071
+		$end=null,
2072
+		$exclude=false,
2073
+		$value=null,
2074
+		$local=false
2075
+	) {
2076
+		$types = (array) $types;
2077
+
2078
+		if ($end === null || $end > $this->numTokens) {
2079
+			$end = $this->numTokens;
2080
+		}
2081
+
2082
+		for ($i = $start; $i < $end; $i++) {
2083
+			$found = (bool) $exclude;
2084
+			foreach ($types as $type) {
2085
+				if ($this->tokens[$i]['code'] === $type) {
2086
+					$found = !$exclude;
2087
+					break;
2088
+				}
2089
+			}
2090
+
2091
+			if ($found === true) {
2092
+				if ($value === null) {
2093
+					return $i;
2094
+				} else if ($this->tokens[$i]['content'] === $value) {
2095
+					return $i;
2096
+				}
2097
+			}
2098
+
2099
+			if ($local === true && $this->tokens[$i]['code'] === T_SEMICOLON) {
2100
+				break;
2101
+			}
2102
+		}//end for
2103
+
2104
+		return false;
2105
+
2106
+	}//end findNext()
2107
+
2108
+
2109
+	/**
2110
+	 * Returns the position of the first non-whitespace token in a statement.
2111
+	 *
2112
+	 * @param int       $start  The position to start searching from in the token stack.
2113
+	 * @param int|array $ignore Token types that should not be considered stop points.
2114
+	 *
2115
+	 * @return int
2116
+	 */
2117
+	public function findStartOfStatement($start, $ignore=null)
2118
+	{
2119
+		$endTokens = Util\Tokens::$blockOpeners;
2120
+
2121
+		$endTokens[T_COLON]            = true;
2122
+		$endTokens[T_COMMA]            = true;
2123
+		$endTokens[T_DOUBLE_ARROW]     = true;
2124
+		$endTokens[T_SEMICOLON]        = true;
2125
+		$endTokens[T_OPEN_TAG]         = true;
2126
+		$endTokens[T_CLOSE_TAG]        = true;
2127
+		$endTokens[T_OPEN_SHORT_ARRAY] = true;
2128
+
2129
+		if ($ignore !== null) {
2130
+			$ignore = (array) $ignore;
2131
+			foreach ($ignore as $code) {
2132
+				unset($endTokens[$code]);
2133
+			}
2134
+		}
2135
+
2136
+		$lastNotEmpty = $start;
2137
+
2138
+		for ($i = $start; $i >= 0; $i--) {
2139
+			if (isset($endTokens[$this->tokens[$i]['code']]) === true) {
2140
+				// Found the end of the previous statement.
2141
+				return $lastNotEmpty;
2142
+			}
2143
+
2144
+			if (isset($this->tokens[$i]['scope_opener']) === true
2145
+				&& $i === $this->tokens[$i]['scope_closer']
2146
+			) {
2147
+				// Found the end of the previous scope block.
2148
+				return $lastNotEmpty;
2149
+			}
2150
+
2151
+			// Skip nested statements.
2152
+			if (isset($this->tokens[$i]['bracket_opener']) === true
2153
+				&& $i === $this->tokens[$i]['bracket_closer']
2154
+			) {
2155
+				$i = $this->tokens[$i]['bracket_opener'];
2156
+			} else if (isset($this->tokens[$i]['parenthesis_opener']) === true
2157
+				&& $i === $this->tokens[$i]['parenthesis_closer']
2158
+			) {
2159
+				$i = $this->tokens[$i]['parenthesis_opener'];
2160
+			}
2161
+
2162
+			if (isset(Util\Tokens::$emptyTokens[$this->tokens[$i]['code']]) === false) {
2163
+				$lastNotEmpty = $i;
2164
+			}
2165
+		}//end for
2166
+
2167
+		return 0;
2168
+
2169
+	}//end findStartOfStatement()
2170
+
2171
+
2172
+	/**
2173
+	 * Returns the position of the last non-whitespace token in a statement.
2174
+	 *
2175
+	 * @param int       $start  The position to start searching from in the token stack.
2176
+	 * @param int|array $ignore Token types that should not be considered stop points.
2177
+	 *
2178
+	 * @return int
2179
+	 */
2180
+	public function findEndOfStatement($start, $ignore=null)
2181
+	{
2182
+		$endTokens = [
2183
+			T_COLON                => true,
2184
+			T_COMMA                => true,
2185
+			T_DOUBLE_ARROW         => true,
2186
+			T_SEMICOLON            => true,
2187
+			T_CLOSE_PARENTHESIS    => true,
2188
+			T_CLOSE_SQUARE_BRACKET => true,
2189
+			T_CLOSE_CURLY_BRACKET  => true,
2190
+			T_CLOSE_SHORT_ARRAY    => true,
2191
+			T_OPEN_TAG             => true,
2192
+			T_CLOSE_TAG            => true,
2193
+		];
2194
+
2195
+		if ($ignore !== null) {
2196
+			$ignore = (array) $ignore;
2197
+			foreach ($ignore as $code) {
2198
+				unset($endTokens[$code]);
2199
+			}
2200
+		}
2201
+
2202
+		$lastNotEmpty = $start;
2203
+
2204
+		for ($i = $start; $i < $this->numTokens; $i++) {
2205
+			if ($i !== $start && isset($endTokens[$this->tokens[$i]['code']]) === true) {
2206
+				// Found the end of the statement.
2207
+				if ($this->tokens[$i]['code'] === T_CLOSE_PARENTHESIS
2208
+					|| $this->tokens[$i]['code'] === T_CLOSE_SQUARE_BRACKET
2209
+					|| $this->tokens[$i]['code'] === T_CLOSE_CURLY_BRACKET
2210
+					|| $this->tokens[$i]['code'] === T_CLOSE_SHORT_ARRAY
2211
+					|| $this->tokens[$i]['code'] === T_OPEN_TAG
2212
+					|| $this->tokens[$i]['code'] === T_CLOSE_TAG
2213
+				) {
2214
+					return $lastNotEmpty;
2215
+				}
2216
+
2217
+				return $i;
2218
+			}
2219
+
2220
+			// Skip nested statements.
2221
+			if (isset($this->tokens[$i]['scope_closer']) === true
2222
+				&& ($i === $this->tokens[$i]['scope_opener']
2223
+				|| $i === $this->tokens[$i]['scope_condition'])
2224
+			) {
2225
+				if ($i === $start && isset(Util\Tokens::$scopeOpeners[$this->tokens[$i]['code']]) === true) {
2226
+					return $this->tokens[$i]['scope_closer'];
2227
+				}
2228
+
2229
+				$i = $this->tokens[$i]['scope_closer'];
2230
+			} else if (isset($this->tokens[$i]['bracket_closer']) === true
2231
+				&& $i === $this->tokens[$i]['bracket_opener']
2232
+			) {
2233
+				$i = $this->tokens[$i]['bracket_closer'];
2234
+			} else if (isset($this->tokens[$i]['parenthesis_closer']) === true
2235
+				&& $i === $this->tokens[$i]['parenthesis_opener']
2236
+			) {
2237
+				$i = $this->tokens[$i]['parenthesis_closer'];
2238
+			}
2239
+
2240
+			if (isset(Util\Tokens::$emptyTokens[$this->tokens[$i]['code']]) === false) {
2241
+				$lastNotEmpty = $i;
2242
+			}
2243
+		}//end for
2244
+
2245
+		return ($this->numTokens - 1);
2246
+
2247
+	}//end findEndOfStatement()
2248
+
2249
+
2250
+	/**
2251
+	 * Returns the position of the first token on a line, matching given type.
2252
+	 *
2253
+	 * Returns false if no token can be found.
2254
+	 *
2255
+	 * @param int|string|array $types   The type(s) of tokens to search for.
2256
+	 * @param int              $start   The position to start searching from in the
2257
+	 *                                  token stack. The first token matching on
2258
+	 *                                  this line before this token will be returned.
2259
+	 * @param bool             $exclude If true, find the token that is NOT of
2260
+	 *                                  the types specified in $types.
2261
+	 * @param string           $value   The value that the token must be equal to.
2262
+	 *                                  If value is omitted, tokens with any value will
2263
+	 *                                  be returned.
2264
+	 *
2265
+	 * @return int | bool
2266
+	 */
2267
+	public function findFirstOnLine($types, $start, $exclude=false, $value=null)
2268
+	{
2269
+		if (is_array($types) === false) {
2270
+			$types = [$types];
2271
+		}
2272
+
2273
+		$foundToken = false;
2274
+
2275
+		for ($i = $start; $i >= 0; $i--) {
2276
+			if ($this->tokens[$i]['line'] < $this->tokens[$start]['line']) {
2277
+				break;
2278
+			}
2279
+
2280
+			$found = $exclude;
2281
+			foreach ($types as $type) {
2282
+				if ($exclude === false) {
2283
+					if ($this->tokens[$i]['code'] === $type) {
2284
+						$found = true;
2285
+						break;
2286
+					}
2287
+				} else {
2288
+					if ($this->tokens[$i]['code'] === $type) {
2289
+						$found = false;
2290
+						break;
2291
+					}
2292
+				}
2293
+			}
2294
+
2295
+			if ($found === true) {
2296
+				if ($value === null) {
2297
+					$foundToken = $i;
2298
+				} else if ($this->tokens[$i]['content'] === $value) {
2299
+					$foundToken = $i;
2300
+				}
2301
+			}
2302
+		}//end for
2303
+
2304
+		return $foundToken;
2305
+
2306
+	}//end findFirstOnLine()
2307
+
2308
+
2309
+	/**
2310
+	 * Determine if the passed token has a condition of one of the passed types.
2311
+	 *
2312
+	 * @param int              $stackPtr The position of the token we are checking.
2313
+	 * @param int|string|array $types    The type(s) of tokens to search for.
2314
+	 *
2315
+	 * @return boolean
2316
+	 */
2317
+	public function hasCondition($stackPtr, $types)
2318
+	{
2319
+		// Check for the existence of the token.
2320
+		if (isset($this->tokens[$stackPtr]) === false) {
2321
+			return false;
2322
+		}
2323
+
2324
+		// Make sure the token has conditions.
2325
+		if (isset($this->tokens[$stackPtr]['conditions']) === false) {
2326
+			return false;
2327
+		}
2328
+
2329
+		$types      = (array) $types;
2330
+		$conditions = $this->tokens[$stackPtr]['conditions'];
2331
+
2332
+		foreach ($types as $type) {
2333
+			if (in_array($type, $conditions, true) === true) {
2334
+				// We found a token with the required type.
2335
+				return true;
2336
+			}
2337
+		}
2338
+
2339
+		return false;
2340
+
2341
+	}//end hasCondition()
2342
+
2343
+
2344
+	/**
2345
+	 * Return the position of the condition for the passed token.
2346
+	 *
2347
+	 * Returns FALSE if the token does not have the condition.
2348
+	 *
2349
+	 * @param int        $stackPtr The position of the token we are checking.
2350
+	 * @param int|string $type     The type of token to search for.
2351
+	 *
2352
+	 * @return int
2353
+	 */
2354
+	public function getCondition($stackPtr, $type)
2355
+	{
2356
+		// Check for the existence of the token.
2357
+		if (isset($this->tokens[$stackPtr]) === false) {
2358
+			return false;
2359
+		}
2360
+
2361
+		// Make sure the token has conditions.
2362
+		if (isset($this->tokens[$stackPtr]['conditions']) === false) {
2363
+			return false;
2364
+		}
2365
+
2366
+		$conditions = $this->tokens[$stackPtr]['conditions'];
2367
+		foreach ($conditions as $token => $condition) {
2368
+			if ($condition === $type) {
2369
+				return $token;
2370
+			}
2371
+		}
2372
+
2373
+		return false;
2374
+
2375
+	}//end getCondition()
2376
+
2377
+
2378
+	/**
2379
+	 * Returns the name of the class that the specified class extends.
2380
+	 * (works for classes, anonymous classes and interfaces)
2381
+	 *
2382
+	 * Returns FALSE on error or if there is no extended class name.
2383
+	 *
2384
+	 * @param int $stackPtr The stack position of the class.
2385
+	 *
2386
+	 * @return string|false
2387
+	 */
2388
+	public function findExtendedClassName($stackPtr)
2389
+	{
2390
+		// Check for the existence of the token.
2391
+		if (isset($this->tokens[$stackPtr]) === false) {
2392
+			return false;
2393
+		}
2394
+
2395
+		if ($this->tokens[$stackPtr]['code'] !== T_CLASS
2396
+			&& $this->tokens[$stackPtr]['code'] !== T_ANON_CLASS
2397
+			&& $this->tokens[$stackPtr]['code'] !== T_INTERFACE
2398
+		) {
2399
+			return false;
2400
+		}
2401
+
2402
+		if (isset($this->tokens[$stackPtr]['scope_opener']) === false) {
2403
+			return false;
2404
+		}
2405
+
2406
+		$classOpenerIndex = $this->tokens[$stackPtr]['scope_opener'];
2407
+		$extendsIndex     = $this->findNext(T_EXTENDS, $stackPtr, $classOpenerIndex);
2408
+		if (false === $extendsIndex) {
2409
+			return false;
2410
+		}
2411
+
2412
+		$find = [
2413
+			T_NS_SEPARATOR,
2414
+			T_STRING,
2415
+			T_WHITESPACE,
2416
+		];
2417
+
2418
+		$end  = $this->findNext($find, ($extendsIndex + 1), ($classOpenerIndex + 1), true);
2419
+		$name = $this->getTokensAsString(($extendsIndex + 1), ($end - $extendsIndex - 1));
2420
+		$name = trim($name);
2421
+
2422
+		if ($name === '') {
2423
+			return false;
2424
+		}
2425
+
2426
+		return $name;
2427
+
2428
+	}//end findExtendedClassName()
2429
+
2430
+
2431
+	/**
2432
+	 * Returns the names of the interfaces that the specified class implements.
2433
+	 *
2434
+	 * Returns FALSE on error or if there are no implemented interface names.
2435
+	 *
2436
+	 * @param int $stackPtr The stack position of the class.
2437
+	 *
2438
+	 * @return array|false
2439
+	 */
2440
+	public function findImplementedInterfaceNames($stackPtr)
2441
+	{
2442
+		// Check for the existence of the token.
2443
+		if (isset($this->tokens[$stackPtr]) === false) {
2444
+			return false;
2445
+		}
2446
+
2447
+		if ($this->tokens[$stackPtr]['code'] !== T_CLASS
2448
+			&& $this->tokens[$stackPtr]['code'] !== T_ANON_CLASS
2449
+		) {
2450
+			return false;
2451
+		}
2452
+
2453
+		if (isset($this->tokens[$stackPtr]['scope_closer']) === false) {
2454
+			return false;
2455
+		}
2456
+
2457
+		$classOpenerIndex = $this->tokens[$stackPtr]['scope_opener'];
2458
+		$implementsIndex  = $this->findNext(T_IMPLEMENTS, $stackPtr, $classOpenerIndex);
2459
+		if ($implementsIndex === false) {
2460
+			return false;
2461
+		}
2462
+
2463
+		$find = [
2464
+			T_NS_SEPARATOR,
2465
+			T_STRING,
2466
+			T_WHITESPACE,
2467
+			T_COMMA,
2468
+		];
2469
+
2470
+		$end  = $this->findNext($find, ($implementsIndex + 1), ($classOpenerIndex + 1), true);
2471
+		$name = $this->getTokensAsString(($implementsIndex + 1), ($end - $implementsIndex - 1));
2472
+		$name = trim($name);
2473
+
2474
+		if ($name === '') {
2475
+			return false;
2476
+		} else {
2477
+			$names = explode(',', $name);
2478
+			$names = array_map('trim', $names);
2479
+			return $names;
2480
+		}
2481
+
2482
+	}//end findImplementedInterfaceNames()
2483 2483
 
2484 2484
 
2485 2485
 }//end class
Please login to merge, or discard this patch.
Switch Indentation   +158 added lines, -158 removed lines patch added patch discarded remove patch
@@ -1324,122 +1324,122 @@  discard block
 block discarded – undo
1324 1324
             }
1325 1325
 
1326 1326
             switch ($this->tokens[$i]['code']) {
1327
-            case T_BITWISE_AND:
1328
-                if ($defaultStart === null) {
1329
-                    $passByReference = true;
1330
-                }
1331
-                break;
1332
-            case T_VARIABLE:
1333
-                $currVar = $i;
1334
-                break;
1335
-            case T_ELLIPSIS:
1336
-                $variableLength = true;
1337
-                break;
1338
-            case T_CALLABLE:
1339
-                if ($typeHintToken === false) {
1340
-                    $typeHintToken = $i;
1341
-                }
1342
-
1343
-                $typeHint .= $this->tokens[$i]['content'];
1344
-                break;
1345
-            case T_SELF:
1346
-            case T_PARENT:
1347
-            case T_STATIC:
1348
-                // Self and parent are valid, static invalid, but was probably intended as type hint.
1349
-                if (isset($defaultStart) === false) {
1350
-                    if ($typeHintToken === false) {
1351
-                        $typeHintToken = $i;
1352
-                    }
1353
-
1354
-                    $typeHint .= $this->tokens[$i]['content'];
1355
-                }
1356
-                break;
1357
-            case T_STRING:
1358
-                // This is a string, so it may be a type hint, but it could
1359
-                // also be a constant used as a default value.
1360
-                $prevComma = false;
1361
-                for ($t = $i; $t >= $opener; $t--) {
1362
-                    if ($this->tokens[$t]['code'] === T_COMMA) {
1363
-                        $prevComma = $t;
1364
-                        break;
1365
-                    }
1366
-                }
1367
-
1368
-                if ($prevComma !== false) {
1369
-                    $nextEquals = false;
1370
-                    for ($t = $prevComma; $t < $i; $t++) {
1371
-                        if ($this->tokens[$t]['code'] === T_EQUAL) {
1372
-                            $nextEquals = $t;
1373
-                            break;
1374
-                        }
1375
-                    }
1376
-
1377
-                    if ($nextEquals !== false) {
1378
-                        break;
1379
-                    }
1380
-                }
1381
-
1382
-                if ($defaultStart === null) {
1383
-                    if ($typeHintToken === false) {
1384
-                        $typeHintToken = $i;
1385
-                    }
1386
-
1387
-                    $typeHint .= $this->tokens[$i]['content'];
1388
-                }
1389
-                break;
1390
-            case T_NS_SEPARATOR:
1391
-                // Part of a type hint or default value.
1392
-                if ($defaultStart === null) {
1393
-                    if ($typeHintToken === false) {
1394
-                        $typeHintToken = $i;
1395
-                    }
1396
-
1397
-                    $typeHint .= $this->tokens[$i]['content'];
1398
-                }
1399
-                break;
1400
-            case T_NULLABLE:
1401
-                if ($defaultStart === null) {
1402
-                    $nullableType = true;
1403
-                    $typeHint    .= $this->tokens[$i]['content'];
1404
-                }
1405
-                break;
1406
-            case T_CLOSE_PARENTHESIS:
1407
-            case T_COMMA:
1408
-                // If it's null, then there must be no parameters for this
1409
-                // method.
1410
-                if ($currVar === null) {
1411
-                    continue 2;
1412
-                }
1413
-
1414
-                $vars[$paramCount]            = [];
1415
-                $vars[$paramCount]['token']   = $currVar;
1416
-                $vars[$paramCount]['name']    = $this->tokens[$currVar]['content'];
1417
-                $vars[$paramCount]['content'] = trim($this->getTokensAsString($paramStart, ($i - $paramStart)));
1418
-
1419
-                if ($defaultStart !== null) {
1420
-                    $vars[$paramCount]['default'] = trim($this->getTokensAsString($defaultStart, ($i - $defaultStart)));
1421
-                }
1422
-
1423
-                $vars[$paramCount]['pass_by_reference'] = $passByReference;
1424
-                $vars[$paramCount]['variable_length']   = $variableLength;
1425
-                $vars[$paramCount]['type_hint']         = $typeHint;
1426
-                $vars[$paramCount]['type_hint_token']   = $typeHintToken;
1427
-                $vars[$paramCount]['nullable_type']     = $nullableType;
1428
-
1429
-                // Reset the vars, as we are about to process the next parameter.
1430
-                $defaultStart    = null;
1431
-                $paramStart      = ($i + 1);
1432
-                $passByReference = false;
1433
-                $variableLength  = false;
1434
-                $typeHint        = '';
1435
-                $typeHintToken   = false;
1436
-                $nullableType    = false;
1437
-
1438
-                $paramCount++;
1439
-                break;
1440
-            case T_EQUAL:
1441
-                $defaultStart = ($i + 1);
1442
-                break;
1327
+            	case T_BITWISE_AND:
1328
+                	if ($defaultStart === null) {
1329
+                    	$passByReference = true;
1330
+                	}
1331
+                	break;
1332
+            	case T_VARIABLE:
1333
+                	$currVar = $i;
1334
+                	break;
1335
+            	case T_ELLIPSIS:
1336
+                	$variableLength = true;
1337
+                	break;
1338
+            	case T_CALLABLE:
1339
+                	if ($typeHintToken === false) {
1340
+                    	$typeHintToken = $i;
1341
+                	}
1342
+
1343
+                	$typeHint .= $this->tokens[$i]['content'];
1344
+                	break;
1345
+            	case T_SELF:
1346
+            	case T_PARENT:
1347
+            	case T_STATIC:
1348
+                	// Self and parent are valid, static invalid, but was probably intended as type hint.
1349
+                	if (isset($defaultStart) === false) {
1350
+                    	if ($typeHintToken === false) {
1351
+                        	$typeHintToken = $i;
1352
+                    	}
1353
+
1354
+                    	$typeHint .= $this->tokens[$i]['content'];
1355
+                	}
1356
+                	break;
1357
+            	case T_STRING:
1358
+                	// This is a string, so it may be a type hint, but it could
1359
+                	// also be a constant used as a default value.
1360
+                	$prevComma = false;
1361
+                	for ($t = $i; $t >= $opener; $t--) {
1362
+                    	if ($this->tokens[$t]['code'] === T_COMMA) {
1363
+                        	$prevComma = $t;
1364
+                        	break;
1365
+                    	}
1366
+                	}
1367
+
1368
+                	if ($prevComma !== false) {
1369
+                    	$nextEquals = false;
1370
+                    	for ($t = $prevComma; $t < $i; $t++) {
1371
+                        	if ($this->tokens[$t]['code'] === T_EQUAL) {
1372
+                            	$nextEquals = $t;
1373
+                            	break;
1374
+                        	}
1375
+                    	}
1376
+
1377
+                    	if ($nextEquals !== false) {
1378
+                        	break;
1379
+                    	}
1380
+                	}
1381
+
1382
+                	if ($defaultStart === null) {
1383
+                    	if ($typeHintToken === false) {
1384
+                        	$typeHintToken = $i;
1385
+                    	}
1386
+
1387
+                    	$typeHint .= $this->tokens[$i]['content'];
1388
+                	}
1389
+                	break;
1390
+            	case T_NS_SEPARATOR:
1391
+                	// Part of a type hint or default value.
1392
+                	if ($defaultStart === null) {
1393
+                    	if ($typeHintToken === false) {
1394
+                        	$typeHintToken = $i;
1395
+                    	}
1396
+
1397
+                    	$typeHint .= $this->tokens[$i]['content'];
1398
+                	}
1399
+                	break;
1400
+            	case T_NULLABLE:
1401
+                	if ($defaultStart === null) {
1402
+                    	$nullableType = true;
1403
+                    	$typeHint    .= $this->tokens[$i]['content'];
1404
+                	}
1405
+                	break;
1406
+            	case T_CLOSE_PARENTHESIS:
1407
+            	case T_COMMA:
1408
+                	// If it's null, then there must be no parameters for this
1409
+                	// method.
1410
+                	if ($currVar === null) {
1411
+                    	continue 2;
1412
+                	}
1413
+
1414
+                	$vars[$paramCount]            = [];
1415
+                	$vars[$paramCount]['token']   = $currVar;
1416
+                	$vars[$paramCount]['name']    = $this->tokens[$currVar]['content'];
1417
+                	$vars[$paramCount]['content'] = trim($this->getTokensAsString($paramStart, ($i - $paramStart)));
1418
+
1419
+                	if ($defaultStart !== null) {
1420
+                    	$vars[$paramCount]['default'] = trim($this->getTokensAsString($defaultStart, ($i - $defaultStart)));
1421
+                	}
1422
+
1423
+                	$vars[$paramCount]['pass_by_reference'] = $passByReference;
1424
+                	$vars[$paramCount]['variable_length']   = $variableLength;
1425
+                	$vars[$paramCount]['type_hint']         = $typeHint;
1426
+                	$vars[$paramCount]['type_hint_token']   = $typeHintToken;
1427
+                	$vars[$paramCount]['nullable_type']     = $nullableType;
1428
+
1429
+                	// Reset the vars, as we are about to process the next parameter.
1430
+                	$defaultStart    = null;
1431
+                	$paramStart      = ($i + 1);
1432
+                	$passByReference = false;
1433
+                	$variableLength  = false;
1434
+                	$typeHint        = '';
1435
+                	$typeHintToken   = false;
1436
+                	$nullableType    = false;
1437
+
1438
+                	$paramCount++;
1439
+                	break;
1440
+            	case T_EQUAL:
1441
+                	$defaultStart = ($i + 1);
1442
+                	break;
1443 1443
             }//end switch
1444 1444
         }//end for
1445 1445
 
@@ -1515,27 +1515,27 @@  discard block
 block discarded – undo
1515 1515
             }
1516 1516
 
1517 1517
             switch ($this->tokens[$i]['code']) {
1518
-            case T_PUBLIC:
1519
-                $scope          = 'public';
1520
-                $scopeSpecified = true;
1521
-                break;
1522
-            case T_PRIVATE:
1523
-                $scope          = 'private';
1524
-                $scopeSpecified = true;
1525
-                break;
1526
-            case T_PROTECTED:
1527
-                $scope          = 'protected';
1528
-                $scopeSpecified = true;
1529
-                break;
1530
-            case T_ABSTRACT:
1531
-                $isAbstract = true;
1532
-                break;
1533
-            case T_FINAL:
1534
-                $isFinal = true;
1535
-                break;
1536
-            case T_STATIC:
1537
-                $isStatic = true;
1538
-                break;
1518
+            	case T_PUBLIC:
1519
+                	$scope          = 'public';
1520
+                	$scopeSpecified = true;
1521
+                	break;
1522
+            	case T_PRIVATE:
1523
+                	$scope          = 'private';
1524
+                	$scopeSpecified = true;
1525
+                	break;
1526
+            	case T_PROTECTED:
1527
+                	$scope          = 'protected';
1528
+                	$scopeSpecified = true;
1529
+                	break;
1530
+            	case T_ABSTRACT:
1531
+                	$isAbstract = true;
1532
+                	break;
1533
+            	case T_FINAL:
1534
+                	$isFinal = true;
1535
+                	break;
1536
+            	case T_STATIC:
1537
+                	$isStatic = true;
1538
+                	break;
1539 1539
             }//end switch
1540 1540
         }//end for
1541 1541
 
@@ -1697,21 +1697,21 @@  discard block
 block discarded – undo
1697 1697
             }
1698 1698
 
1699 1699
             switch ($this->tokens[$i]['code']) {
1700
-            case T_PUBLIC:
1701
-                $scope          = 'public';
1702
-                $scopeSpecified = true;
1703
-                break;
1704
-            case T_PRIVATE:
1705
-                $scope          = 'private';
1706
-                $scopeSpecified = true;
1707
-                break;
1708
-            case T_PROTECTED:
1709
-                $scope          = 'protected';
1710
-                $scopeSpecified = true;
1711
-                break;
1712
-            case T_STATIC:
1713
-                $isStatic = true;
1714
-                break;
1700
+            	case T_PUBLIC:
1701
+                	$scope          = 'public';
1702
+                	$scopeSpecified = true;
1703
+                	break;
1704
+            	case T_PRIVATE:
1705
+                	$scope          = 'private';
1706
+                	$scopeSpecified = true;
1707
+                	break;
1708
+            	case T_PROTECTED:
1709
+                	$scope          = 'protected';
1710
+                	$scopeSpecified = true;
1711
+                	break;
1712
+            	case T_STATIC:
1713
+                	$isStatic = true;
1714
+                	break;
1715 1715
             }
1716 1716
         }//end for
1717 1717
 
@@ -1765,13 +1765,13 @@  discard block
 block discarded – undo
1765 1765
             }
1766 1766
 
1767 1767
             switch ($this->tokens[$i]['code']) {
1768
-            case T_ABSTRACT:
1769
-                $isAbstract = true;
1770
-                break;
1768
+            	case T_ABSTRACT:
1769
+                	$isAbstract = true;
1770
+                	break;
1771 1771
 
1772
-            case T_FINAL:
1773
-                $isFinal = true;
1774
-                break;
1772
+            	case T_FINAL:
1773
+                	$isFinal = true;
1774
+                	break;
1775 1775
             }
1776 1776
         }//end for
1777 1777
 
Please login to merge, or discard this patch.
Spacing   +567 added lines, -567 removed lines patch added patch discarded remove patch
@@ -106,7 +106,7 @@  discard block
 block discarded – undo
106 106
      *
107 107
      * @var array
108 108
      */
109
-    protected $tokens = [];
109
+    protected $tokens = [ ];
110 110
 
111 111
     /**
112 112
      * The errors raised from sniffs.
@@ -114,7 +114,7 @@  discard block
 block discarded – undo
114 114
      * @var array
115 115
      * @see getErrors()
116 116
      */
117
-    protected $errors = [];
117
+    protected $errors = [ ];
118 118
 
119 119
     /**
120 120
      * The warnings raised from sniffs.
@@ -122,7 +122,7 @@  discard block
 block discarded – undo
122 122
      * @var array
123 123
      * @see getWarnings()
124 124
      */
125
-    protected $warnings = [];
125
+    protected $warnings = [ ];
126 126
 
127 127
     /**
128 128
      * The metrics recorded by sniffs.
@@ -130,7 +130,7 @@  discard block
 block discarded – undo
130 130
      * @var array
131 131
      * @see getMetrics()
132 132
      */
133
-    protected $metrics = [];
133
+    protected $metrics = [ ];
134 134
 
135 135
     /**
136 136
      * The metrics recorded for each token.
@@ -140,7 +140,7 @@  discard block
 block discarded – undo
140 140
      * @var array
141 141
      * @see getMetrics()
142 142
      */
143
-    private $metricTokens = [];
143
+    private $metricTokens = [ ];
144 144
 
145 145
     /**
146 146
      * The total number of errors raised.
@@ -175,21 +175,21 @@  discard block
 block discarded – undo
175 175
      *
176 176
      * @var array
177 177
      */
178
-    protected $ignoredListeners = [];
178
+    protected $ignoredListeners = [ ];
179 179
 
180 180
     /**
181 181
      * An array of message codes that are being ignored.
182 182
      *
183 183
      * @var array
184 184
      */
185
-    protected $ignoredCodes = [];
185
+    protected $ignoredCodes = [ ];
186 186
 
187 187
     /**
188 188
      * An array of sniffs listening to this file's processing.
189 189
      *
190 190
      * @var \PHP_CodeSniffer\Sniffs\Sniff[]
191 191
      */
192
-    protected $listeners = [];
192
+    protected $listeners = [ ];
193 193
 
194 194
     /**
195 195
      * The class name of the sniff currently processing the file.
@@ -203,7 +203,7 @@  discard block
 block discarded – undo
203 203
      *
204 204
      * @var array
205 205
      */
206
-    protected $listenerTimes = [];
206
+    protected $listenerTimes = [ ];
207 207
 
208 208
     /**
209 209
      * A cache of often used config settings to improve performance.
@@ -212,7 +212,7 @@  discard block
 block discarded – undo
212 212
      *
213 213
      * @var array
214 214
      */
215
-    protected $configCache = [];
215
+    protected $configCache = [ ];
216 216
 
217 217
 
218 218
     /**
@@ -224,30 +224,30 @@  discard block
 block discarded – undo
224 224
      *
225 225
      * @return void
226 226
      */
227
-    public function __construct($path, Ruleset $ruleset, Config $config)
227
+    public function __construct( $path, Ruleset $ruleset, Config $config )
228 228
     {
229 229
         $this->path    = $path;
230 230
         $this->ruleset = $ruleset;
231 231
         $this->config  = $config;
232 232
         $this->fixer   = new Fixer();
233 233
 
234
-        $parts     = explode('.', $path);
235
-        $extension = array_pop($parts);
236
-        if (isset($config->extensions[$extension]) === true) {
237
-            $this->tokenizerType = $config->extensions[$extension];
234
+        $parts     = explode( '.', $path );
235
+        $extension = array_pop( $parts );
236
+        if ( isset( $config->extensions[ $extension ] ) === true ) {
237
+            $this->tokenizerType = $config->extensions[ $extension ];
238 238
         } else {
239 239
             // Revert to default.
240 240
             $this->tokenizerType = 'PHP';
241 241
         }
242 242
 
243
-        $this->configCache['cache']           = $this->config->cache;
244
-        $this->configCache['sniffs']          = array_map('strtolower', $this->config->sniffs);
245
-        $this->configCache['exclude']         = array_map('strtolower', $this->config->exclude);
246
-        $this->configCache['errorSeverity']   = $this->config->errorSeverity;
247
-        $this->configCache['warningSeverity'] = $this->config->warningSeverity;
248
-        $this->configCache['recordErrors']    = $this->config->recordErrors;
249
-        $this->configCache['ignorePatterns']  = $this->ruleset->ignorePatterns;
250
-        $this->configCache['includePatterns'] = $this->ruleset->includePatterns;
243
+        $this->configCache[ 'cache' ]           = $this->config->cache;
244
+        $this->configCache[ 'sniffs' ]          = array_map( 'strtolower', $this->config->sniffs );
245
+        $this->configCache[ 'exclude' ]         = array_map( 'strtolower', $this->config->exclude );
246
+        $this->configCache[ 'errorSeverity' ]   = $this->config->errorSeverity;
247
+        $this->configCache[ 'warningSeverity' ] = $this->config->warningSeverity;
248
+        $this->configCache[ 'recordErrors' ]    = $this->config->recordErrors;
249
+        $this->configCache[ 'ignorePatterns' ]  = $this->ruleset->ignorePatterns;
250
+        $this->configCache[ 'includePatterns' ] = $this->ruleset->includePatterns;
251 251
 
252 252
     }//end __construct()
253 253
 
@@ -261,15 +261,15 @@  discard block
 block discarded – undo
261 261
      *
262 262
      * @return void
263 263
      */
264
-    public function setContent($content)
264
+    public function setContent( $content )
265 265
     {
266 266
         $this->content = $content;
267
-        $this->tokens  = [];
267
+        $this->tokens  = [ ];
268 268
 
269 269
         try {
270
-            $this->eolChar = Util\Common::detectLineEndings($content);
271
-        } catch (RuntimeException $e) {
272
-            $this->addWarningOnLine($e->getMessage(), 1, 'Internal.DetectLineEndings');
270
+            $this->eolChar = Util\Common::detectLineEndings( $content );
271
+        } catch ( RuntimeException $e ) {
272
+            $this->addWarningOnLine( $e->getMessage(), 1, 'Internal.DetectLineEndings' );
273 273
             return;
274 274
         }
275 275
 
@@ -297,7 +297,7 @@  discard block
 block discarded – undo
297 297
      */
298 298
     public function disableCaching()
299 299
     {
300
-        $this->configCache['cache'] = false;
300
+        $this->configCache[ 'cache' ] = false;
301 301
 
302 302
     }//end disableCaching()
303 303
 
@@ -309,12 +309,12 @@  discard block
 block discarded – undo
309 309
      */
310 310
     public function process()
311 311
     {
312
-        if ($this->ignored === true) {
312
+        if ( $this->ignored === true ) {
313 313
             return;
314 314
         }
315 315
 
316
-        $this->errors       = [];
317
-        $this->warnings     = [];
316
+        $this->errors       = [ ];
317
+        $this->warnings     = [ ];
318 318
         $this->errorCount   = 0;
319 319
         $this->warningCount = 0;
320 320
         $this->fixableCount = 0;
@@ -322,106 +322,106 @@  discard block
 block discarded – undo
322 322
         $this->parse();
323 323
 
324 324
         // Check if tokenizer errors cause this file to be ignored.
325
-        if ($this->ignored === true) {
325
+        if ( $this->ignored === true ) {
326 326
             return;
327 327
         }
328 328
 
329
-        $this->fixer->startFile($this);
329
+        $this->fixer->startFile( $this );
330 330
 
331
-        if (PHP_CODESNIFFER_VERBOSITY > 2) {
332
-            echo "\t*** START TOKEN PROCESSING ***".PHP_EOL;
331
+        if ( PHP_CODESNIFFER_VERBOSITY > 2 ) {
332
+            echo "\t*** START TOKEN PROCESSING ***" . PHP_EOL;
333 333
         }
334 334
 
335 335
         $foundCode        = false;
336
-        $listenerIgnoreTo = [];
337
-        $inTests          = defined('PHP_CODESNIFFER_IN_TESTS');
336
+        $listenerIgnoreTo = [ ];
337
+        $inTests          = defined( 'PHP_CODESNIFFER_IN_TESTS' );
338 338
         $checkAnnotations = $this->config->annotations;
339 339
 
340 340
         // Foreach of the listeners that have registered to listen for this
341 341
         // token, get them to process it.
342
-        foreach ($this->tokens as $stackPtr => $token) {
342
+        foreach ( $this->tokens as $stackPtr => $token ) {
343 343
             // Check for ignored lines.
344
-            if ($checkAnnotations === true
345
-                && ($token['code'] === T_COMMENT
346
-                || $token['code'] === T_PHPCS_IGNORE_FILE
347
-                || $token['code'] === T_PHPCS_SET
348
-                || $token['code'] === T_DOC_COMMENT_STRING
349
-                || $token['code'] === T_DOC_COMMENT_TAG
350
-                || ($inTests === true && $token['code'] === T_INLINE_HTML))
344
+            if ( $checkAnnotations === true
345
+                && ( $token[ 'code' ] === T_COMMENT
346
+                || $token[ 'code' ] === T_PHPCS_IGNORE_FILE
347
+                || $token[ 'code' ] === T_PHPCS_SET
348
+                || $token[ 'code' ] === T_DOC_COMMENT_STRING
349
+                || $token[ 'code' ] === T_DOC_COMMENT_TAG
350
+                || ( $inTests === true && $token[ 'code' ] === T_INLINE_HTML ) )
351 351
             ) {
352
-                $commentText      = ltrim($this->tokens[$stackPtr]['content'], ' /*');
353
-                $commentTextLower = strtolower($commentText);
354
-                if (strpos($commentText, '@codingStandards') !== false) {
355
-                    if (strpos($commentText, '@codingStandardsIgnoreFile') !== false) {
352
+                $commentText      = ltrim( $this->tokens[ $stackPtr ][ 'content' ], ' /*' );
353
+                $commentTextLower = strtolower( $commentText );
354
+                if ( strpos( $commentText, '@codingStandards' ) !== false ) {
355
+                    if ( strpos( $commentText, '@codingStandardsIgnoreFile' ) !== false ) {
356 356
                         // Ignoring the whole file, just a little late.
357
-                        $this->errors       = [];
358
-                        $this->warnings     = [];
357
+                        $this->errors       = [ ];
358
+                        $this->warnings     = [ ];
359 359
                         $this->errorCount   = 0;
360 360
                         $this->warningCount = 0;
361 361
                         $this->fixableCount = 0;
362 362
                         return;
363
-                    } else if (strpos($commentText, '@codingStandardsChangeSetting') !== false) {
364
-                        $start   = strpos($commentText, '@codingStandardsChangeSetting');
365
-                        $comment = substr($commentText, ($start + 30));
366
-                        $parts   = explode(' ', $comment);
367
-                        if (count($parts) >= 2) {
368
-                            $sniffParts = explode('.', $parts[0]);
369
-                            if (count($sniffParts) >= 3) {
363
+                    } else if ( strpos( $commentText, '@codingStandardsChangeSetting' ) !== false ) {
364
+                        $start   = strpos( $commentText, '@codingStandardsChangeSetting' );
365
+                        $comment = substr( $commentText, ( $start + 30 ) );
366
+                        $parts   = explode( ' ', $comment );
367
+                        if ( count( $parts ) >= 2 ) {
368
+                            $sniffParts = explode( '.', $parts[ 0 ] );
369
+                            if ( count( $sniffParts ) >= 3 ) {
370 370
                                 // If the sniff code is not known to us, it has not been registered in this run.
371 371
                                 // But don't throw an error as it could be there for a different standard to use.
372
-                                if (isset($this->ruleset->sniffCodes[$parts[0]]) === true) {
373
-                                    $listenerCode  = array_shift($parts);
374
-                                    $propertyCode  = array_shift($parts);
375
-                                    $propertyValue = rtrim(implode(' ', $parts), " */\r\n");
376
-                                    $listenerClass = $this->ruleset->sniffCodes[$listenerCode];
377
-                                    $this->ruleset->setSniffProperty($listenerClass, $propertyCode, $propertyValue);
372
+                                if ( isset( $this->ruleset->sniffCodes[ $parts[ 0 ] ] ) === true ) {
373
+                                    $listenerCode  = array_shift( $parts );
374
+                                    $propertyCode  = array_shift( $parts );
375
+                                    $propertyValue = rtrim( implode( ' ', $parts ), " */\r\n" );
376
+                                    $listenerClass = $this->ruleset->sniffCodes[ $listenerCode ];
377
+                                    $this->ruleset->setSniffProperty( $listenerClass, $propertyCode, $propertyValue );
378 378
                                 }
379 379
                             }
380 380
                         }
381 381
                     }//end if
382
-                } else if (substr($commentTextLower, 0, 16) === 'phpcs:ignorefile'
383
-                    || substr($commentTextLower, 0, 17) === '@phpcs:ignorefile'
382
+                } else if ( substr( $commentTextLower, 0, 16 ) === 'phpcs:ignorefile'
383
+                    || substr( $commentTextLower, 0, 17 ) === '@phpcs:ignorefile'
384 384
                 ) {
385 385
                     // Ignoring the whole file, just a little late.
386
-                    $this->errors       = [];
387
-                    $this->warnings     = [];
386
+                    $this->errors       = [ ];
387
+                    $this->warnings     = [ ];
388 388
                     $this->errorCount   = 0;
389 389
                     $this->warningCount = 0;
390 390
                     $this->fixableCount = 0;
391 391
                     return;
392
-                } else if (substr($commentTextLower, 0, 9) === 'phpcs:set'
393
-                    || substr($commentTextLower, 0, 10) === '@phpcs:set'
392
+                } else if ( substr( $commentTextLower, 0, 9 ) === 'phpcs:set'
393
+                    || substr( $commentTextLower, 0, 10 ) === '@phpcs:set'
394 394
                 ) {
395
-                    if (isset($token['sniffCode']) === true) {
396
-                        $listenerCode = $token['sniffCode'];
397
-                        if (isset($this->ruleset->sniffCodes[$listenerCode]) === true) {
398
-                            $propertyCode  = $token['sniffProperty'];
399
-                            $propertyValue = $token['sniffPropertyValue'];
400
-                            $listenerClass = $this->ruleset->sniffCodes[$listenerCode];
401
-                            $this->ruleset->setSniffProperty($listenerClass, $propertyCode, $propertyValue);
395
+                    if ( isset( $token[ 'sniffCode' ] ) === true ) {
396
+                        $listenerCode = $token[ 'sniffCode' ];
397
+                        if ( isset( $this->ruleset->sniffCodes[ $listenerCode ] ) === true ) {
398
+                            $propertyCode  = $token[ 'sniffProperty' ];
399
+                            $propertyValue = $token[ 'sniffPropertyValue' ];
400
+                            $listenerClass = $this->ruleset->sniffCodes[ $listenerCode ];
401
+                            $this->ruleset->setSniffProperty( $listenerClass, $propertyCode, $propertyValue );
402 402
                         }
403 403
                     }
404 404
                 }//end if
405 405
             }//end if
406 406
 
407
-            if (PHP_CODESNIFFER_VERBOSITY > 2) {
408
-                $type    = $token['type'];
409
-                $content = Util\Common::prepareForOutput($token['content']);
410
-                echo "\t\tProcess token $stackPtr: $type => $content".PHP_EOL;
407
+            if ( PHP_CODESNIFFER_VERBOSITY > 2 ) {
408
+                $type    = $token[ 'type' ];
409
+                $content = Util\Common::prepareForOutput( $token[ 'content' ] );
410
+                echo "\t\tProcess token $stackPtr: $type => $content" . PHP_EOL;
411 411
             }
412 412
 
413
-            if ($token['code'] !== T_INLINE_HTML) {
413
+            if ( $token[ 'code' ] !== T_INLINE_HTML ) {
414 414
                 $foundCode = true;
415 415
             }
416 416
 
417
-            if (isset($this->ruleset->tokenListeners[$token['code']]) === false) {
417
+            if ( isset( $this->ruleset->tokenListeners[ $token[ 'code' ] ] ) === false ) {
418 418
                 continue;
419 419
             }
420 420
 
421
-            foreach ($this->ruleset->tokenListeners[$token['code']] as $listenerData) {
422
-                if (isset($this->ignoredListeners[$listenerData['class']]) === true
423
-                    || (isset($listenerIgnoreTo[$listenerData['class']]) === true
424
-                    && $listenerIgnoreTo[$listenerData['class']] > $stackPtr)
421
+            foreach ( $this->ruleset->tokenListeners[ $token[ 'code' ] ] as $listenerData ) {
422
+                if ( isset( $this->ignoredListeners[ $listenerData[ 'class' ] ] ) === true
423
+                    || ( isset( $listenerIgnoreTo[ $listenerData[ 'class' ] ] ) === true
424
+                    && $listenerIgnoreTo[ $listenerData[ 'class' ] ] > $stackPtr )
425 425
                 ) {
426 426
                     // This sniff is ignoring past this token, or the whole file.
427 427
                     continue;
@@ -429,78 +429,78 @@  discard block
 block discarded – undo
429 429
 
430 430
                 // Make sure this sniff supports the tokenizer
431 431
                 // we are currently using.
432
-                $class = $listenerData['class'];
432
+                $class = $listenerData[ 'class' ];
433 433
 
434
-                if (isset($listenerData['tokenizers'][$this->tokenizerType]) === false) {
434
+                if ( isset( $listenerData[ 'tokenizers' ][ $this->tokenizerType ] ) === false ) {
435 435
                     continue;
436 436
                 }
437 437
 
438 438
                 // If the file path matches one of our ignore patterns, skip it.
439 439
                 // While there is support for a type of each pattern
440 440
                 // (absolute or relative) we don't actually support it here.
441
-                foreach ($listenerData['ignore'] as $pattern) {
441
+                foreach ( $listenerData[ 'ignore' ] as $pattern ) {
442 442
                     // We assume a / directory separator, as do the exclude rules
443 443
                     // most developers write, so we need a special case for any system
444 444
                     // that is different.
445
-                    if (DIRECTORY_SEPARATOR === '\\') {
446
-                        $pattern = str_replace('/', '\\\\', $pattern);
445
+                    if ( DIRECTORY_SEPARATOR === '\\' ) {
446
+                        $pattern = str_replace( '/', '\\\\', $pattern );
447 447
                     }
448 448
 
449
-                    $pattern = '`'.$pattern.'`i';
450
-                    if (preg_match($pattern, $this->path) === 1) {
451
-                        $this->ignoredListeners[$class] = true;
452
-                        continue(2);
449
+                    $pattern = '`' . $pattern . '`i';
450
+                    if ( preg_match( $pattern, $this->path ) === 1 ) {
451
+                        $this->ignoredListeners[ $class ] = true;
452
+                        continue( 2 );
453 453
                     }
454 454
                 }
455 455
 
456 456
                 // If the file path does not match one of our include patterns, skip it.
457 457
                 // While there is support for a type of each pattern
458 458
                 // (absolute or relative) we don't actually support it here.
459
-                if (empty($listenerData['include']) === false) {
459
+                if ( empty( $listenerData[ 'include' ] ) === false ) {
460 460
                     $included = false;
461
-                    foreach ($listenerData['include'] as $pattern) {
461
+                    foreach ( $listenerData[ 'include' ] as $pattern ) {
462 462
                         // We assume a / directory separator, as do the exclude rules
463 463
                         // most developers write, so we need a special case for any system
464 464
                         // that is different.
465
-                        if (DIRECTORY_SEPARATOR === '\\') {
466
-                            $pattern = str_replace('/', '\\\\', $pattern);
465
+                        if ( DIRECTORY_SEPARATOR === '\\' ) {
466
+                            $pattern = str_replace( '/', '\\\\', $pattern );
467 467
                         }
468 468
 
469
-                        $pattern = '`'.$pattern.'`i';
470
-                        if (preg_match($pattern, $this->path) === 1) {
469
+                        $pattern = '`' . $pattern . '`i';
470
+                        if ( preg_match( $pattern, $this->path ) === 1 ) {
471 471
                             $included = true;
472 472
                             break;
473 473
                         }
474 474
                     }
475 475
 
476
-                    if ($included === false) {
477
-                        $this->ignoredListeners[$class] = true;
476
+                    if ( $included === false ) {
477
+                        $this->ignoredListeners[ $class ] = true;
478 478
                         continue;
479 479
                     }
480 480
                 }//end if
481 481
 
482 482
                 $this->activeListener = $class;
483 483
 
484
-                if (PHP_CODESNIFFER_VERBOSITY > 2) {
485
-                    $startTime = microtime(true);
486
-                    echo "\t\t\tProcessing ".$this->activeListener.'... ';
484
+                if ( PHP_CODESNIFFER_VERBOSITY > 2 ) {
485
+                    $startTime = microtime( true );
486
+                    echo "\t\t\tProcessing " . $this->activeListener . '... ';
487 487
                 }
488 488
 
489
-                $ignoreTo = $this->ruleset->sniffs[$class]->process($this, $stackPtr);
490
-                if ($ignoreTo !== null) {
491
-                    $listenerIgnoreTo[$this->activeListener] = $ignoreTo;
489
+                $ignoreTo = $this->ruleset->sniffs[ $class ]->process( $this, $stackPtr );
490
+                if ( $ignoreTo !== null ) {
491
+                    $listenerIgnoreTo[ $this->activeListener ] = $ignoreTo;
492 492
                 }
493 493
 
494
-                if (PHP_CODESNIFFER_VERBOSITY > 2) {
495
-                    $timeTaken = (microtime(true) - $startTime);
496
-                    if (isset($this->listenerTimes[$this->activeListener]) === false) {
497
-                        $this->listenerTimes[$this->activeListener] = 0;
494
+                if ( PHP_CODESNIFFER_VERBOSITY > 2 ) {
495
+                    $timeTaken = ( microtime( true ) - $startTime );
496
+                    if ( isset( $this->listenerTimes[ $this->activeListener ] ) === false ) {
497
+                        $this->listenerTimes[ $this->activeListener ] = 0;
498 498
                     }
499 499
 
500
-                    $this->listenerTimes[$this->activeListener] += $timeTaken;
500
+                    $this->listenerTimes[ $this->activeListener ] += $timeTaken;
501 501
 
502
-                    $timeTaken = round(($timeTaken), 4);
503
-                    echo "DONE in $timeTaken seconds".PHP_EOL;
502
+                    $timeTaken = round( ( $timeTaken ), 4 );
503
+                    echo "DONE in $timeTaken seconds" . PHP_EOL;
504 504
                 }
505 505
 
506 506
                 $this->activeListener = '';
@@ -513,25 +513,25 @@  discard block
 block discarded – undo
513 513
         // We don't show this error for STDIN because we can't be sure the content
514 514
         // actually came directly from the user. It could be something like
515 515
         // refs from a Git pre-push hook.
516
-        if ($foundCode === false && $this->tokenizerType === 'PHP' && $this->path !== 'STDIN') {
517
-            $shortTags = (bool) ini_get('short_open_tag');
518
-            if ($shortTags === false) {
516
+        if ( $foundCode === false && $this->tokenizerType === 'PHP' && $this->path !== 'STDIN' ) {
517
+            $shortTags = (bool)ini_get( 'short_open_tag' );
518
+            if ( $shortTags === false ) {
519 519
                 $error = 'No PHP code was found in this file and short open tags are not allowed by this install of PHP. This file may be using short open tags but PHP does not allow them.';
520
-                $this->addWarning($error, null, 'Internal.NoCodeFound');
520
+                $this->addWarning( $error, null, 'Internal.NoCodeFound' );
521 521
             }
522 522
         }
523 523
 
524
-        if (PHP_CODESNIFFER_VERBOSITY > 2) {
525
-            echo "\t*** END TOKEN PROCESSING ***".PHP_EOL;
526
-            echo "\t*** START SNIFF PROCESSING REPORT ***".PHP_EOL;
524
+        if ( PHP_CODESNIFFER_VERBOSITY > 2 ) {
525
+            echo "\t*** END TOKEN PROCESSING ***" . PHP_EOL;
526
+            echo "\t*** START SNIFF PROCESSING REPORT ***" . PHP_EOL;
527 527
 
528
-            asort($this->listenerTimes, SORT_NUMERIC);
529
-            $this->listenerTimes = array_reverse($this->listenerTimes, true);
530
-            foreach ($this->listenerTimes as $listener => $timeTaken) {
531
-                echo "\t$listener: ".round(($timeTaken), 4).' secs'.PHP_EOL;
528
+            asort( $this->listenerTimes, SORT_NUMERIC );
529
+            $this->listenerTimes = array_reverse( $this->listenerTimes, true );
530
+            foreach ( $this->listenerTimes as $listener => $timeTaken ) {
531
+                echo "\t$listener: " . round( ( $timeTaken ), 4 ) . ' secs' . PHP_EOL;
532 532
             }
533 533
 
534
-            echo "\t*** END SNIFF PROCESSING REPORT ***".PHP_EOL;
534
+            echo "\t*** END SNIFF PROCESSING REPORT ***" . PHP_EOL;
535 535
         }
536 536
 
537 537
         $this->fixedCount += $this->fixer->getFixCount();
@@ -546,21 +546,21 @@  discard block
 block discarded – undo
546 546
      */
547 547
     public function parse()
548 548
     {
549
-        if (empty($this->tokens) === false) {
549
+        if ( empty( $this->tokens ) === false ) {
550 550
             // File has already been parsed.
551 551
             return;
552 552
         }
553 553
 
554 554
         try {
555
-            $tokenizerClass  = 'PHP_CodeSniffer\Tokenizers\\'.$this->tokenizerType;
556
-            $this->tokenizer = new $tokenizerClass($this->content, $this->config, $this->eolChar);
555
+            $tokenizerClass  = 'PHP_CodeSniffer\Tokenizers\\' . $this->tokenizerType;
556
+            $this->tokenizer = new $tokenizerClass( $this->content, $this->config, $this->eolChar );
557 557
             $this->tokens    = $this->tokenizer->getTokens();
558
-        } catch (TokenizerException $e) {
558
+        } catch ( TokenizerException $e ) {
559 559
             $this->ignored = true;
560
-            $this->addWarning($e->getMessage(), null, 'Internal.Tokenizer.Exception');
561
-            if (PHP_CODESNIFFER_VERBOSITY > 0) {
560
+            $this->addWarning( $e->getMessage(), null, 'Internal.Tokenizer.Exception' );
561
+            if ( PHP_CODESNIFFER_VERBOSITY > 0 ) {
562 562
                 echo "[$this->tokenizerType => tokenizer error]... ";
563
-                if (PHP_CODESNIFFER_VERBOSITY > 1) {
563
+                if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
564 564
                     echo PHP_EOL;
565 565
                 }
566 566
             }
@@ -568,31 +568,31 @@  discard block
 block discarded – undo
568 568
             return;
569 569
         }
570 570
 
571
-        $this->numTokens = count($this->tokens);
571
+        $this->numTokens = count( $this->tokens );
572 572
 
573 573
         // Check for mixed line endings as these can cause tokenizer errors and we
574 574
         // should let the user know that the results they get may be incorrect.
575 575
         // This is done by removing all backslashes, removing the newline char we
576 576
         // detected, then converting newlines chars into text. If any backslashes
577 577
         // are left at the end, we have additional newline chars in use.
578
-        $contents = str_replace('\\', '', $this->content);
579
-        $contents = str_replace($this->eolChar, '', $contents);
580
-        $contents = str_replace("\n", '\n', $contents);
581
-        $contents = str_replace("\r", '\r', $contents);
582
-        if (strpos($contents, '\\') !== false) {
578
+        $contents = str_replace( '\\', '', $this->content );
579
+        $contents = str_replace( $this->eolChar, '', $contents );
580
+        $contents = str_replace( "\n", '\n', $contents );
581
+        $contents = str_replace( "\r", '\r', $contents );
582
+        if ( strpos( $contents, '\\' ) !== false ) {
583 583
             $error = 'File has mixed line endings; this may cause incorrect results';
584
-            $this->addWarningOnLine($error, 1, 'Internal.LineEndings.Mixed');
584
+            $this->addWarningOnLine( $error, 1, 'Internal.LineEndings.Mixed' );
585 585
         }
586 586
 
587
-        if (PHP_CODESNIFFER_VERBOSITY > 0) {
588
-            if ($this->numTokens === 0) {
587
+        if ( PHP_CODESNIFFER_VERBOSITY > 0 ) {
588
+            if ( $this->numTokens === 0 ) {
589 589
                 $numLines = 0;
590 590
             } else {
591
-                $numLines = $this->tokens[($this->numTokens - 1)]['line'];
591
+                $numLines = $this->tokens[ ( $this->numTokens - 1 ) ][ 'line' ];
592 592
             }
593 593
 
594 594
             echo "[$this->tokenizerType => $this->numTokens tokens in $numLines lines]... ";
595
-            if (PHP_CODESNIFFER_VERBOSITY > 1) {
595
+            if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
596 596
                 echo PHP_EOL;
597 597
             }
598 598
         }
@@ -648,19 +648,19 @@  discard block
 block discarded – undo
648 648
         $error,
649 649
         $stackPtr,
650 650
         $code,
651
-        $data=[],
652
-        $severity=0,
653
-        $fixable=false
651
+        $data = [ ],
652
+        $severity = 0,
653
+        $fixable = false
654 654
     ) {
655
-        if ($stackPtr === null) {
655
+        if ( $stackPtr === null ) {
656 656
             $line   = 1;
657 657
             $column = 1;
658 658
         } else {
659
-            $line   = $this->tokens[$stackPtr]['line'];
660
-            $column = $this->tokens[$stackPtr]['column'];
659
+            $line   = $this->tokens[ $stackPtr ][ 'line' ];
660
+            $column = $this->tokens[ $stackPtr ][ 'column' ];
661 661
         }
662 662
 
663
-        return $this->addMessage(true, $error, $line, $column, $code, $data, $severity, $fixable);
663
+        return $this->addMessage( true, $error, $line, $column, $code, $data, $severity, $fixable );
664 664
 
665 665
     }//end addError()
666 666
 
@@ -682,19 +682,19 @@  discard block
 block discarded – undo
682 682
         $warning,
683 683
         $stackPtr,
684 684
         $code,
685
-        $data=[],
686
-        $severity=0,
687
-        $fixable=false
685
+        $data = [ ],
686
+        $severity = 0,
687
+        $fixable = false
688 688
     ) {
689
-        if ($stackPtr === null) {
689
+        if ( $stackPtr === null ) {
690 690
             $line   = 1;
691 691
             $column = 1;
692 692
         } else {
693
-            $line   = $this->tokens[$stackPtr]['line'];
694
-            $column = $this->tokens[$stackPtr]['column'];
693
+            $line   = $this->tokens[ $stackPtr ][ 'line' ];
694
+            $column = $this->tokens[ $stackPtr ][ 'column' ];
695 695
         }
696 696
 
697
-        return $this->addMessage(false, $warning, $line, $column, $code, $data, $severity, $fixable);
697
+        return $this->addMessage( false, $warning, $line, $column, $code, $data, $severity, $fixable );
698 698
 
699 699
     }//end addWarning()
700 700
 
@@ -715,10 +715,10 @@  discard block
 block discarded – undo
715 715
         $error,
716 716
         $line,
717 717
         $code,
718
-        $data=[],
719
-        $severity=0
718
+        $data = [ ],
719
+        $severity = 0
720 720
     ) {
721
-        return $this->addMessage(true, $error, $line, 1, $code, $data, $severity, false);
721
+        return $this->addMessage( true, $error, $line, 1, $code, $data, $severity, false );
722 722
 
723 723
     }//end addErrorOnLine()
724 724
 
@@ -739,10 +739,10 @@  discard block
 block discarded – undo
739 739
         $warning,
740 740
         $line,
741 741
         $code,
742
-        $data=[],
743
-        $severity=0
742
+        $data = [ ],
743
+        $severity = 0
744 744
     ) {
745
-        return $this->addMessage(false, $warning, $line, 1, $code, $data, $severity, false);
745
+        return $this->addMessage( false, $warning, $line, 1, $code, $data, $severity, false );
746 746
 
747 747
     }//end addWarningOnLine()
748 748
 
@@ -765,11 +765,11 @@  discard block
 block discarded – undo
765 765
         $error,
766 766
         $stackPtr,
767 767
         $code,
768
-        $data=[],
769
-        $severity=0
768
+        $data = [ ],
769
+        $severity = 0
770 770
     ) {
771
-        $recorded = $this->addError($error, $stackPtr, $code, $data, $severity, true);
772
-        if ($recorded === true && $this->fixer->enabled === true) {
771
+        $recorded = $this->addError( $error, $stackPtr, $code, $data, $severity, true );
772
+        if ( $recorded === true && $this->fixer->enabled === true ) {
773 773
             return true;
774 774
         }
775 775
 
@@ -796,11 +796,11 @@  discard block
 block discarded – undo
796 796
         $warning,
797 797
         $stackPtr,
798 798
         $code,
799
-        $data=[],
800
-        $severity=0
799
+        $data = [ ],
800
+        $severity = 0
801 801
     ) {
802
-        $recorded = $this->addWarning($warning, $stackPtr, $code, $data, $severity, true);
803
-        if ($recorded === true && $this->fixer->enabled === true) {
802
+        $recorded = $this->addWarning( $warning, $stackPtr, $code, $data, $severity, true );
803
+        if ( $recorded === true && $this->fixer->enabled === true ) {
804 804
             return true;
805 805
         }
806 806
 
@@ -824,156 +824,156 @@  discard block
 block discarded – undo
824 824
      *
825 825
      * @return boolean
826 826
      */
827
-    protected function addMessage($error, $message, $line, $column, $code, $data, $severity, $fixable)
827
+    protected function addMessage( $error, $message, $line, $column, $code, $data, $severity, $fixable )
828 828
     {
829 829
         // Check if this line is ignoring all message codes.
830
-        if (isset($this->tokenizer->ignoredLines[$line]['.all']) === true) {
830
+        if ( isset( $this->tokenizer->ignoredLines[ $line ][ '.all' ] ) === true ) {
831 831
             return false;
832 832
         }
833 833
 
834 834
         // Work out which sniff generated the message.
835
-        $parts = explode('.', $code);
836
-        if ($parts[0] === 'Internal') {
835
+        $parts = explode( '.', $code );
836
+        if ( $parts[ 0 ] === 'Internal' ) {
837 837
             // An internal message.
838
-            $listenerCode = Util\Common::getSniffCode($this->activeListener);
838
+            $listenerCode = Util\Common::getSniffCode( $this->activeListener );
839 839
             $sniffCode    = $code;
840
-            $checkCodes   = [$sniffCode];
840
+            $checkCodes   = [ $sniffCode ];
841 841
         } else {
842
-            if ($parts[0] !== $code) {
842
+            if ( $parts[ 0 ] !== $code ) {
843 843
                 // The full message code has been passed in.
844 844
                 $sniffCode    = $code;
845
-                $listenerCode = substr($sniffCode, 0, strrpos($sniffCode, '.'));
845
+                $listenerCode = substr( $sniffCode, 0, strrpos( $sniffCode, '.' ) );
846 846
             } else {
847
-                $listenerCode = Util\Common::getSniffCode($this->activeListener);
848
-                $sniffCode    = $listenerCode.'.'.$code;
849
-                $parts        = explode('.', $sniffCode);
847
+                $listenerCode = Util\Common::getSniffCode( $this->activeListener );
848
+                $sniffCode    = $listenerCode . '.' . $code;
849
+                $parts        = explode( '.', $sniffCode );
850 850
             }
851 851
 
852 852
             $checkCodes = [
853 853
                 $sniffCode,
854
-                $parts[0].'.'.$parts[1].'.'.$parts[2],
855
-                $parts[0].'.'.$parts[1],
856
-                $parts[0],
854
+                $parts[ 0 ] . '.' . $parts[ 1 ] . '.' . $parts[ 2 ],
855
+                $parts[ 0 ] . '.' . $parts[ 1 ],
856
+                $parts[ 0 ],
857 857
             ];
858 858
         }//end if
859 859
 
860
-        if (isset($this->tokenizer->ignoredLines[$line]) === true) {
860
+        if ( isset( $this->tokenizer->ignoredLines[ $line ] ) === true ) {
861 861
             // Check if this line is ignoring this specific message.
862 862
             $ignored = false;
863
-            foreach ($checkCodes as $checkCode) {
864
-                if (isset($this->tokenizer->ignoredLines[$line][$checkCode]) === true) {
863
+            foreach ( $checkCodes as $checkCode ) {
864
+                if ( isset( $this->tokenizer->ignoredLines[ $line ][ $checkCode ] ) === true ) {
865 865
                     $ignored = true;
866 866
                     break;
867 867
                 }
868 868
             }
869 869
 
870 870
             // If it is ignored, make sure it's not whitelisted.
871
-            if ($ignored === true
872
-                && isset($this->tokenizer->ignoredLines[$line]['.except']) === true
871
+            if ( $ignored === true
872
+                && isset( $this->tokenizer->ignoredLines[ $line ][ '.except' ] ) === true
873 873
             ) {
874
-                foreach ($checkCodes as $checkCode) {
875
-                    if (isset($this->tokenizer->ignoredLines[$line]['.except'][$checkCode]) === true) {
874
+                foreach ( $checkCodes as $checkCode ) {
875
+                    if ( isset( $this->tokenizer->ignoredLines[ $line ][ '.except' ][ $checkCode ] ) === true ) {
876 876
                         $ignored = false;
877 877
                         break;
878 878
                     }
879 879
                 }
880 880
             }
881 881
 
882
-            if ($ignored === true) {
882
+            if ( $ignored === true ) {
883 883
                 return false;
884 884
             }
885 885
         }//end if
886 886
 
887 887
         $includeAll = true;
888
-        if ($this->configCache['cache'] === false
889
-            || $this->configCache['recordErrors'] === false
888
+        if ( $this->configCache[ 'cache' ] === false
889
+            || $this->configCache[ 'recordErrors' ] === false
890 890
         ) {
891 891
             $includeAll = false;
892 892
         }
893 893
 
894 894
         // Filter out any messages for sniffs that shouldn't have run
895 895
         // due to the use of the --sniffs command line argument.
896
-        if ($includeAll === false
897
-            && ((empty($this->configCache['sniffs']) === false
898
-            && in_array(strtolower($listenerCode), $this->configCache['sniffs'], true) === false)
899
-            || (empty($this->configCache['exclude']) === false
900
-            && in_array(strtolower($listenerCode), $this->configCache['exclude'], true) === true))
896
+        if ( $includeAll === false
897
+            && ( ( empty( $this->configCache[ 'sniffs' ] ) === false
898
+            && in_array( strtolower( $listenerCode ), $this->configCache[ 'sniffs' ], true ) === false )
899
+            || ( empty( $this->configCache[ 'exclude' ] ) === false
900
+            && in_array( strtolower( $listenerCode ), $this->configCache[ 'exclude' ], true ) === true ) )
901 901
         ) {
902 902
             return false;
903 903
         }
904 904
 
905 905
         // If we know this sniff code is being ignored for this file, return early.
906
-        foreach ($checkCodes as $checkCode) {
907
-            if (isset($this->ignoredCodes[$checkCode]) === true) {
906
+        foreach ( $checkCodes as $checkCode ) {
907
+            if ( isset( $this->ignoredCodes[ $checkCode ] ) === true ) {
908 908
                 return false;
909 909
             }
910 910
         }
911 911
 
912 912
         $oppositeType = 'warning';
913
-        if ($error === false) {
913
+        if ( $error === false ) {
914 914
             $oppositeType = 'error';
915 915
         }
916 916
 
917
-        foreach ($checkCodes as $checkCode) {
917
+        foreach ( $checkCodes as $checkCode ) {
918 918
             // Make sure this message type has not been set to the opposite message type.
919
-            if (isset($this->ruleset->ruleset[$checkCode]['type']) === true
920
-                && $this->ruleset->ruleset[$checkCode]['type'] === $oppositeType
919
+            if ( isset( $this->ruleset->ruleset[ $checkCode ][ 'type' ] ) === true
920
+                && $this->ruleset->ruleset[ $checkCode ][ 'type' ] === $oppositeType
921 921
             ) {
922
-                $error = !$error;
922
+                $error = ! $error;
923 923
                 break;
924 924
             }
925 925
         }
926 926
 
927
-        if ($error === true) {
928
-            $configSeverity = $this->configCache['errorSeverity'];
927
+        if ( $error === true ) {
928
+            $configSeverity = $this->configCache[ 'errorSeverity' ];
929 929
             $messageCount   = &$this->errorCount;
930 930
             $messages       = &$this->errors;
931 931
         } else {
932
-            $configSeverity = $this->configCache['warningSeverity'];
932
+            $configSeverity = $this->configCache[ 'warningSeverity' ];
933 933
             $messageCount   = &$this->warningCount;
934 934
             $messages       = &$this->warnings;
935 935
         }
936 936
 
937
-        if ($includeAll === false && $configSeverity === 0) {
937
+        if ( $includeAll === false && $configSeverity === 0 ) {
938 938
             // Don't bother doing any processing as these messages are just going to
939 939
             // be hidden in the reports anyway.
940 940
             return false;
941 941
         }
942 942
 
943
-        if ($severity === 0) {
943
+        if ( $severity === 0 ) {
944 944
             $severity = 5;
945 945
         }
946 946
 
947
-        foreach ($checkCodes as $checkCode) {
947
+        foreach ( $checkCodes as $checkCode ) {
948 948
             // Make sure we are interested in this severity level.
949
-            if (isset($this->ruleset->ruleset[$checkCode]['severity']) === true) {
950
-                $severity = $this->ruleset->ruleset[$checkCode]['severity'];
949
+            if ( isset( $this->ruleset->ruleset[ $checkCode ][ 'severity' ] ) === true ) {
950
+                $severity = $this->ruleset->ruleset[ $checkCode ][ 'severity' ];
951 951
                 break;
952 952
             }
953 953
         }
954 954
 
955
-        if ($includeAll === false && $configSeverity > $severity) {
955
+        if ( $includeAll === false && $configSeverity > $severity ) {
956 956
             return false;
957 957
         }
958 958
 
959 959
         // Make sure we are not ignoring this file.
960 960
         $included = null;
961
-        foreach ($checkCodes as $checkCode) {
961
+        foreach ( $checkCodes as $checkCode ) {
962 962
             $patterns = null;
963 963
 
964
-            if (isset($this->configCache['includePatterns'][$checkCode]) === true) {
965
-                $patterns  = $this->configCache['includePatterns'][$checkCode];
964
+            if ( isset( $this->configCache[ 'includePatterns' ][ $checkCode ] ) === true ) {
965
+                $patterns  = $this->configCache[ 'includePatterns' ][ $checkCode ];
966 966
                 $excluding = false;
967
-            } else if (isset($this->configCache['ignorePatterns'][$checkCode]) === true) {
968
-                $patterns  = $this->configCache['ignorePatterns'][$checkCode];
967
+            } else if ( isset( $this->configCache[ 'ignorePatterns' ][ $checkCode ] ) === true ) {
968
+                $patterns  = $this->configCache[ 'ignorePatterns' ][ $checkCode ];
969 969
                 $excluding = true;
970 970
             }
971 971
 
972
-            if ($patterns === null) {
972
+            if ( $patterns === null ) {
973 973
                 continue;
974 974
             }
975 975
 
976
-            foreach ($patterns as $pattern => $type) {
976
+            foreach ( $patterns as $pattern => $type ) {
977 977
                 // While there is support for a type of each pattern
978 978
                 // (absolute or relative) we don't actually support it here.
979 979
                 $replacements = [
@@ -984,15 +984,15 @@  discard block
 block discarded – undo
984 984
                 // We assume a / directory separator, as do the exclude rules
985 985
                 // most developers write, so we need a special case for any system
986 986
                 // that is different.
987
-                if (DIRECTORY_SEPARATOR === '\\') {
988
-                    $replacements['/'] = '\\\\';
987
+                if ( DIRECTORY_SEPARATOR === '\\' ) {
988
+                    $replacements[ '/' ] = '\\\\';
989 989
                 }
990 990
 
991
-                $pattern = '`'.strtr($pattern, $replacements).'`i';
992
-                $matched = preg_match($pattern, $this->path);
991
+                $pattern = '`' . strtr( $pattern, $replacements ) . '`i';
992
+                $matched = preg_match( $pattern, $this->path );
993 993
 
994
-                if ($matched === 0) {
995
-                    if ($excluding === false && $included === null) {
994
+                if ( $matched === 0 ) {
995
+                    if ( $excluding === false && $included === null ) {
996 996
                         // This file path is not being included.
997 997
                         $included = false;
998 998
                     }
@@ -1000,9 +1000,9 @@  discard block
 block discarded – undo
1000 1000
                     continue;
1001 1001
                 }
1002 1002
 
1003
-                if ($excluding === true) {
1003
+                if ( $excluding === true ) {
1004 1004
                     // This file path is being excluded.
1005
-                    $this->ignoredCodes[$checkCode] = true;
1005
+                    $this->ignoredCodes[ $checkCode ] = true;
1006 1006
                     return false;
1007 1007
                 }
1008 1008
 
@@ -1012,41 +1012,41 @@  discard block
 block discarded – undo
1012 1012
             }//end foreach
1013 1013
         }//end foreach
1014 1014
 
1015
-        if ($included === false) {
1015
+        if ( $included === false ) {
1016 1016
             // There were include rules set, but this file
1017 1017
             // path didn't match any of them.
1018 1018
             return false;
1019 1019
         }
1020 1020
 
1021 1021
         $messageCount++;
1022
-        if ($fixable === true) {
1022
+        if ( $fixable === true ) {
1023 1023
             $this->fixableCount++;
1024 1024
         }
1025 1025
 
1026
-        if ($this->configCache['recordErrors'] === false
1026
+        if ( $this->configCache[ 'recordErrors' ] === false
1027 1027
             && $includeAll === false
1028 1028
         ) {
1029 1029
             return true;
1030 1030
         }
1031 1031
 
1032 1032
         // Work out the error message.
1033
-        if (isset($this->ruleset->ruleset[$sniffCode]['message']) === true) {
1034
-            $message = $this->ruleset->ruleset[$sniffCode]['message'];
1033
+        if ( isset( $this->ruleset->ruleset[ $sniffCode ][ 'message' ] ) === true ) {
1034
+            $message = $this->ruleset->ruleset[ $sniffCode ][ 'message' ];
1035 1035
         }
1036 1036
 
1037
-        if (empty($data) === false) {
1038
-            $message = vsprintf($message, $data);
1037
+        if ( empty( $data ) === false ) {
1038
+            $message = vsprintf( $message, $data );
1039 1039
         }
1040 1040
 
1041
-        if (isset($messages[$line]) === false) {
1042
-            $messages[$line] = [];
1041
+        if ( isset( $messages[ $line ] ) === false ) {
1042
+            $messages[ $line ] = [ ];
1043 1043
         }
1044 1044
 
1045
-        if (isset($messages[$line][$column]) === false) {
1046
-            $messages[$line][$column] = [];
1045
+        if ( isset( $messages[ $line ][ $column ] ) === false ) {
1046
+            $messages[ $line ][ $column ] = [ ];
1047 1047
         }
1048 1048
 
1049
-        $messages[$line][$column][] = [
1049
+        $messages[ $line ][ $column ][ ] = [
1050 1050
             'message'  => $message,
1051 1051
             'source'   => $sniffCode,
1052 1052
             'listener' => $this->activeListener,
@@ -1054,12 +1054,12 @@  discard block
 block discarded – undo
1054 1054
             'fixable'  => $fixable,
1055 1055
         ];
1056 1056
 
1057
-        if (PHP_CODESNIFFER_VERBOSITY > 1
1057
+        if ( PHP_CODESNIFFER_VERBOSITY > 1
1058 1058
             && $this->fixer->enabled === true
1059 1059
             && $fixable === true
1060 1060
         ) {
1061 1061
             @ob_end_clean();
1062
-            echo "\tE: [Line $line] $message ($sniffCode)".PHP_EOL;
1062
+            echo "\tE: [Line $line] $message ($sniffCode)" . PHP_EOL;
1063 1063
             ob_start();
1064 1064
         }
1065 1065
 
@@ -1077,17 +1077,17 @@  discard block
 block discarded – undo
1077 1077
      *
1078 1078
      * @return boolean
1079 1079
      */
1080
-    public function recordMetric($stackPtr, $metric, $value)
1080
+    public function recordMetric( $stackPtr, $metric, $value )
1081 1081
     {
1082
-        if (isset($this->metrics[$metric]) === false) {
1083
-            $this->metrics[$metric] = ['values' => [$value => 1]];
1084
-            $this->metricTokens[$metric][$stackPtr] = true;
1085
-        } else if (isset($this->metricTokens[$metric][$stackPtr]) === false) {
1086
-            $this->metricTokens[$metric][$stackPtr] = true;
1087
-            if (isset($this->metrics[$metric]['values'][$value]) === false) {
1088
-                $this->metrics[$metric]['values'][$value] = 1;
1082
+        if ( isset( $this->metrics[ $metric ] ) === false ) {
1083
+            $this->metrics[ $metric ] = [ 'values' => [ $value => 1 ] ];
1084
+            $this->metricTokens[ $metric ][ $stackPtr ] = true;
1085
+        } else if ( isset( $this->metricTokens[ $metric ][ $stackPtr ] ) === false ) {
1086
+            $this->metricTokens[ $metric ][ $stackPtr ] = true;
1087
+            if ( isset( $this->metrics[ $metric ][ 'values' ][ $value ] ) === false ) {
1088
+                $this->metrics[ $metric ][ 'values' ][ $value ] = 1;
1089 1089
             } else {
1090
-                $this->metrics[$metric]['values'][$value]++;
1090
+                $this->metrics[ $metric ][ 'values' ][ $value ]++;
1091 1091
             }
1092 1092
         }
1093 1093
 
@@ -1216,34 +1216,34 @@  discard block
 block discarded – undo
1216 1216
      *                                                      T_FUNCTION, T_CLASS, T_ANON_CLASS,
1217 1217
      *                                                      T_CLOSURE, T_TRAIT, or T_INTERFACE.
1218 1218
      */
1219
-    public function getDeclarationName($stackPtr)
1219
+    public function getDeclarationName( $stackPtr )
1220 1220
     {
1221
-        $tokenCode = $this->tokens[$stackPtr]['code'];
1221
+        $tokenCode = $this->tokens[ $stackPtr ][ 'code' ];
1222 1222
 
1223
-        if ($tokenCode === T_ANON_CLASS || $tokenCode === T_CLOSURE) {
1223
+        if ( $tokenCode === T_ANON_CLASS || $tokenCode === T_CLOSURE ) {
1224 1224
             return null;
1225 1225
         }
1226 1226
 
1227
-        if ($tokenCode !== T_FUNCTION
1227
+        if ( $tokenCode !== T_FUNCTION
1228 1228
             && $tokenCode !== T_CLASS
1229 1229
             && $tokenCode !== T_INTERFACE
1230 1230
             && $tokenCode !== T_TRAIT
1231 1231
         ) {
1232
-            throw new RuntimeException('Token type "'.$this->tokens[$stackPtr]['type'].'" is not T_FUNCTION, T_CLASS, T_INTERFACE or T_TRAIT');
1232
+            throw new RuntimeException( 'Token type "' . $this->tokens[ $stackPtr ][ 'type' ] . '" is not T_FUNCTION, T_CLASS, T_INTERFACE or T_TRAIT' );
1233 1233
         }
1234 1234
 
1235
-        if ($tokenCode === T_FUNCTION
1236
-            && strtolower($this->tokens[$stackPtr]['content']) !== 'function'
1235
+        if ( $tokenCode === T_FUNCTION
1236
+            && strtolower( $this->tokens[ $stackPtr ][ 'content' ] ) !== 'function'
1237 1237
         ) {
1238 1238
             // This is a function declared without the "function" keyword.
1239 1239
             // So this token is the function name.
1240
-            return $this->tokens[$stackPtr]['content'];
1240
+            return $this->tokens[ $stackPtr ][ 'content' ];
1241 1241
         }
1242 1242
 
1243 1243
         $content = null;
1244
-        for ($i = $stackPtr; $i < $this->numTokens; $i++) {
1245
-            if ($this->tokens[$i]['code'] === T_STRING) {
1246
-                $content = $this->tokens[$i]['content'];
1244
+        for ( $i = $stackPtr; $i < $this->numTokens; $i++ ) {
1245
+            if ( $this->tokens[ $i ][ 'code' ] === T_STRING ) {
1246
+                $content = $this->tokens[ $i ][ 'content' ];
1247 1247
                 break;
1248 1248
             }
1249 1249
         }
@@ -1282,20 +1282,20 @@  discard block
 block discarded – undo
1282 1282
      * @throws \PHP_CodeSniffer\Exceptions\TokenizerException If the specified $stackPtr is not of
1283 1283
      *                                                        type T_FUNCTION or T_CLOSURE.
1284 1284
      */
1285
-    public function getMethodParameters($stackPtr)
1285
+    public function getMethodParameters( $stackPtr )
1286 1286
     {
1287
-        if ($this->tokens[$stackPtr]['code'] !== T_FUNCTION
1288
-            && $this->tokens[$stackPtr]['code'] !== T_CLOSURE
1287
+        if ( $this->tokens[ $stackPtr ][ 'code' ] !== T_FUNCTION
1288
+            && $this->tokens[ $stackPtr ][ 'code' ] !== T_CLOSURE
1289 1289
         ) {
1290
-            throw new TokenizerException('$stackPtr must be of type T_FUNCTION or T_CLOSURE');
1290
+            throw new TokenizerException( '$stackPtr must be of type T_FUNCTION or T_CLOSURE' );
1291 1291
         }
1292 1292
 
1293
-        $opener = $this->tokens[$stackPtr]['parenthesis_opener'];
1294
-        $closer = $this->tokens[$stackPtr]['parenthesis_closer'];
1293
+        $opener = $this->tokens[ $stackPtr ][ 'parenthesis_opener' ];
1294
+        $closer = $this->tokens[ $stackPtr ][ 'parenthesis_closer' ];
1295 1295
 
1296
-        $vars            = [];
1296
+        $vars            = [ ];
1297 1297
         $currVar         = null;
1298
-        $paramStart      = ($opener + 1);
1298
+        $paramStart      = ( $opener + 1 );
1299 1299
         $defaultStart    = null;
1300 1300
         $paramCount      = 0;
1301 1301
         $passByReference = false;
@@ -1304,28 +1304,28 @@  discard block
 block discarded – undo
1304 1304
         $typeHintToken   = false;
1305 1305
         $nullableType    = false;
1306 1306
 
1307
-        for ($i = $paramStart; $i <= $closer; $i++) {
1307
+        for ( $i = $paramStart; $i <= $closer; $i++ ) {
1308 1308
             // Check to see if this token has a parenthesis or bracket opener. If it does
1309 1309
             // it's likely to be an array which might have arguments in it. This
1310 1310
             // could cause problems in our parsing below, so lets just skip to the
1311 1311
             // end of it.
1312
-            if (isset($this->tokens[$i]['parenthesis_opener']) === true) {
1312
+            if ( isset( $this->tokens[ $i ][ 'parenthesis_opener' ] ) === true ) {
1313 1313
                 // Don't do this if it's the close parenthesis for the method.
1314
-                if ($i !== $this->tokens[$i]['parenthesis_closer']) {
1315
-                    $i = ($this->tokens[$i]['parenthesis_closer'] + 1);
1314
+                if ( $i !== $this->tokens[ $i ][ 'parenthesis_closer' ] ) {
1315
+                    $i = ( $this->tokens[ $i ][ 'parenthesis_closer' ] + 1 );
1316 1316
                 }
1317 1317
             }
1318 1318
 
1319
-            if (isset($this->tokens[$i]['bracket_opener']) === true) {
1319
+            if ( isset( $this->tokens[ $i ][ 'bracket_opener' ] ) === true ) {
1320 1320
                 // Don't do this if it's the close parenthesis for the method.
1321
-                if ($i !== $this->tokens[$i]['bracket_closer']) {
1322
-                    $i = ($this->tokens[$i]['bracket_closer'] + 1);
1321
+                if ( $i !== $this->tokens[ $i ][ 'bracket_closer' ] ) {
1322
+                    $i = ( $this->tokens[ $i ][ 'bracket_closer' ] + 1 );
1323 1323
                 }
1324 1324
             }
1325 1325
 
1326
-            switch ($this->tokens[$i]['code']) {
1326
+            switch ( $this->tokens[ $i ][ 'code' ] ) {
1327 1327
             case T_BITWISE_AND:
1328
-                if ($defaultStart === null) {
1328
+                if ( $defaultStart === null ) {
1329 1329
                     $passByReference = true;
1330 1330
                 }
1331 1331
                 break;
@@ -1336,99 +1336,99 @@  discard block
 block discarded – undo
1336 1336
                 $variableLength = true;
1337 1337
                 break;
1338 1338
             case T_CALLABLE:
1339
-                if ($typeHintToken === false) {
1339
+                if ( $typeHintToken === false ) {
1340 1340
                     $typeHintToken = $i;
1341 1341
                 }
1342 1342
 
1343
-                $typeHint .= $this->tokens[$i]['content'];
1343
+                $typeHint .= $this->tokens[ $i ][ 'content' ];
1344 1344
                 break;
1345 1345
             case T_SELF:
1346 1346
             case T_PARENT:
1347 1347
             case T_STATIC:
1348 1348
                 // Self and parent are valid, static invalid, but was probably intended as type hint.
1349
-                if (isset($defaultStart) === false) {
1350
-                    if ($typeHintToken === false) {
1349
+                if ( isset( $defaultStart ) === false ) {
1350
+                    if ( $typeHintToken === false ) {
1351 1351
                         $typeHintToken = $i;
1352 1352
                     }
1353 1353
 
1354
-                    $typeHint .= $this->tokens[$i]['content'];
1354
+                    $typeHint .= $this->tokens[ $i ][ 'content' ];
1355 1355
                 }
1356 1356
                 break;
1357 1357
             case T_STRING:
1358 1358
                 // This is a string, so it may be a type hint, but it could
1359 1359
                 // also be a constant used as a default value.
1360 1360
                 $prevComma = false;
1361
-                for ($t = $i; $t >= $opener; $t--) {
1362
-                    if ($this->tokens[$t]['code'] === T_COMMA) {
1361
+                for ( $t = $i; $t >= $opener; $t-- ) {
1362
+                    if ( $this->tokens[ $t ][ 'code' ] === T_COMMA ) {
1363 1363
                         $prevComma = $t;
1364 1364
                         break;
1365 1365
                     }
1366 1366
                 }
1367 1367
 
1368
-                if ($prevComma !== false) {
1368
+                if ( $prevComma !== false ) {
1369 1369
                     $nextEquals = false;
1370
-                    for ($t = $prevComma; $t < $i; $t++) {
1371
-                        if ($this->tokens[$t]['code'] === T_EQUAL) {
1370
+                    for ( $t = $prevComma; $t < $i; $t++ ) {
1371
+                        if ( $this->tokens[ $t ][ 'code' ] === T_EQUAL ) {
1372 1372
                             $nextEquals = $t;
1373 1373
                             break;
1374 1374
                         }
1375 1375
                     }
1376 1376
 
1377
-                    if ($nextEquals !== false) {
1377
+                    if ( $nextEquals !== false ) {
1378 1378
                         break;
1379 1379
                     }
1380 1380
                 }
1381 1381
 
1382
-                if ($defaultStart === null) {
1383
-                    if ($typeHintToken === false) {
1382
+                if ( $defaultStart === null ) {
1383
+                    if ( $typeHintToken === false ) {
1384 1384
                         $typeHintToken = $i;
1385 1385
                     }
1386 1386
 
1387
-                    $typeHint .= $this->tokens[$i]['content'];
1387
+                    $typeHint .= $this->tokens[ $i ][ 'content' ];
1388 1388
                 }
1389 1389
                 break;
1390 1390
             case T_NS_SEPARATOR:
1391 1391
                 // Part of a type hint or default value.
1392
-                if ($defaultStart === null) {
1393
-                    if ($typeHintToken === false) {
1392
+                if ( $defaultStart === null ) {
1393
+                    if ( $typeHintToken === false ) {
1394 1394
                         $typeHintToken = $i;
1395 1395
                     }
1396 1396
 
1397
-                    $typeHint .= $this->tokens[$i]['content'];
1397
+                    $typeHint .= $this->tokens[ $i ][ 'content' ];
1398 1398
                 }
1399 1399
                 break;
1400 1400
             case T_NULLABLE:
1401
-                if ($defaultStart === null) {
1401
+                if ( $defaultStart === null ) {
1402 1402
                     $nullableType = true;
1403
-                    $typeHint    .= $this->tokens[$i]['content'];
1403
+                    $typeHint    .= $this->tokens[ $i ][ 'content' ];
1404 1404
                 }
1405 1405
                 break;
1406 1406
             case T_CLOSE_PARENTHESIS:
1407 1407
             case T_COMMA:
1408 1408
                 // If it's null, then there must be no parameters for this
1409 1409
                 // method.
1410
-                if ($currVar === null) {
1410
+                if ( $currVar === null ) {
1411 1411
                     continue 2;
1412 1412
                 }
1413 1413
 
1414
-                $vars[$paramCount]            = [];
1415
-                $vars[$paramCount]['token']   = $currVar;
1416
-                $vars[$paramCount]['name']    = $this->tokens[$currVar]['content'];
1417
-                $vars[$paramCount]['content'] = trim($this->getTokensAsString($paramStart, ($i - $paramStart)));
1414
+                $vars[ $paramCount ]            = [ ];
1415
+                $vars[ $paramCount ][ 'token' ]   = $currVar;
1416
+                $vars[ $paramCount ][ 'name' ]    = $this->tokens[ $currVar ][ 'content' ];
1417
+                $vars[ $paramCount ][ 'content' ] = trim( $this->getTokensAsString( $paramStart, ( $i - $paramStart ) ) );
1418 1418
 
1419
-                if ($defaultStart !== null) {
1420
-                    $vars[$paramCount]['default'] = trim($this->getTokensAsString($defaultStart, ($i - $defaultStart)));
1419
+                if ( $defaultStart !== null ) {
1420
+                    $vars[ $paramCount ][ 'default' ] = trim( $this->getTokensAsString( $defaultStart, ( $i - $defaultStart ) ) );
1421 1421
                 }
1422 1422
 
1423
-                $vars[$paramCount]['pass_by_reference'] = $passByReference;
1424
-                $vars[$paramCount]['variable_length']   = $variableLength;
1425
-                $vars[$paramCount]['type_hint']         = $typeHint;
1426
-                $vars[$paramCount]['type_hint_token']   = $typeHintToken;
1427
-                $vars[$paramCount]['nullable_type']     = $nullableType;
1423
+                $vars[ $paramCount ][ 'pass_by_reference' ] = $passByReference;
1424
+                $vars[ $paramCount ][ 'variable_length' ]   = $variableLength;
1425
+                $vars[ $paramCount ][ 'type_hint' ]         = $typeHint;
1426
+                $vars[ $paramCount ][ 'type_hint_token' ]   = $typeHintToken;
1427
+                $vars[ $paramCount ][ 'nullable_type' ]     = $nullableType;
1428 1428
 
1429 1429
                 // Reset the vars, as we are about to process the next parameter.
1430 1430
                 $defaultStart    = null;
1431
-                $paramStart      = ($i + 1);
1431
+                $paramStart      = ( $i + 1 );
1432 1432
                 $passByReference = false;
1433 1433
                 $variableLength  = false;
1434 1434
                 $typeHint        = '';
@@ -1438,7 +1438,7 @@  discard block
 block discarded – undo
1438 1438
                 $paramCount++;
1439 1439
                 break;
1440 1440
             case T_EQUAL:
1441
-                $defaultStart = ($i + 1);
1441
+                $defaultStart = ( $i + 1 );
1442 1442
                 break;
1443 1443
             }//end switch
1444 1444
         }//end for
@@ -1474,15 +1474,15 @@  discard block
 block discarded – undo
1474 1474
      * @throws \PHP_CodeSniffer\Exceptions\TokenizerException If the specified position is not a
1475 1475
      *                                                        T_FUNCTION token.
1476 1476
      */
1477
-    public function getMethodProperties($stackPtr)
1477
+    public function getMethodProperties( $stackPtr )
1478 1478
     {
1479
-        if ($this->tokens[$stackPtr]['code'] !== T_FUNCTION
1480
-            && $this->tokens[$stackPtr]['code'] !== T_CLOSURE
1479
+        if ( $this->tokens[ $stackPtr ][ 'code' ] !== T_FUNCTION
1480
+            && $this->tokens[ $stackPtr ][ 'code' ] !== T_CLOSURE
1481 1481
         ) {
1482
-            throw new TokenizerException('$stackPtr must be of type T_FUNCTION or T_CLOSURE');
1482
+            throw new TokenizerException( '$stackPtr must be of type T_FUNCTION or T_CLOSURE' );
1483 1483
         }
1484 1484
 
1485
-        if ($this->tokens[$stackPtr]['code'] === T_FUNCTION) {
1485
+        if ( $this->tokens[ $stackPtr ][ 'code' ] === T_FUNCTION ) {
1486 1486
             $valid = [
1487 1487
                 T_PUBLIC      => T_PUBLIC,
1488 1488
                 T_PRIVATE     => T_PRIVATE,
@@ -1509,12 +1509,12 @@  discard block
 block discarded – undo
1509 1509
         $isFinal        = false;
1510 1510
         $isStatic       = false;
1511 1511
 
1512
-        for ($i = ($stackPtr - 1); $i > 0; $i--) {
1513
-            if (isset($valid[$this->tokens[$i]['code']]) === false) {
1512
+        for ( $i = ( $stackPtr - 1 ); $i > 0; $i-- ) {
1513
+            if ( isset( $valid[ $this->tokens[ $i ][ 'code' ] ] ) === false ) {
1514 1514
                 break;
1515 1515
             }
1516 1516
 
1517
-            switch ($this->tokens[$i]['code']) {
1517
+            switch ( $this->tokens[ $i ][ 'code' ] ) {
1518 1518
             case T_PUBLIC:
1519 1519
                 $scope          = 'public';
1520 1520
                 $scopeSpecified = true;
@@ -1544,10 +1544,10 @@  discard block
 block discarded – undo
1544 1544
         $nullableReturnType = false;
1545 1545
         $hasBody            = true;
1546 1546
 
1547
-        if (isset($this->tokens[$stackPtr]['parenthesis_closer']) === true) {
1547
+        if ( isset( $this->tokens[ $stackPtr ][ 'parenthesis_closer' ] ) === true ) {
1548 1548
             $scopeOpener = null;
1549
-            if (isset($this->tokens[$stackPtr]['scope_opener']) === true) {
1550
-                $scopeOpener = $this->tokens[$stackPtr]['scope_opener'];
1549
+            if ( isset( $this->tokens[ $stackPtr ][ 'scope_opener' ] ) === true ) {
1550
+                $scopeOpener = $this->tokens[ $stackPtr ][ 'scope_opener' ];
1551 1551
             }
1552 1552
 
1553 1553
             $valid = [
@@ -1558,33 +1558,33 @@  discard block
 block discarded – undo
1558 1558
                 T_NS_SEPARATOR => T_NS_SEPARATOR,
1559 1559
             ];
1560 1560
 
1561
-            for ($i = $this->tokens[$stackPtr]['parenthesis_closer']; $i < $this->numTokens; $i++) {
1562
-                if (($scopeOpener === null && $this->tokens[$i]['code'] === T_SEMICOLON)
1563
-                    || ($scopeOpener !== null && $i === $scopeOpener)
1561
+            for ( $i = $this->tokens[ $stackPtr ][ 'parenthesis_closer' ]; $i < $this->numTokens; $i++ ) {
1562
+                if ( ( $scopeOpener === null && $this->tokens[ $i ][ 'code' ] === T_SEMICOLON )
1563
+                    || ( $scopeOpener !== null && $i === $scopeOpener )
1564 1564
                 ) {
1565 1565
                     // End of function definition.
1566 1566
                     break;
1567 1567
                 }
1568 1568
 
1569
-                if ($this->tokens[$i]['code'] === T_NULLABLE) {
1569
+                if ( $this->tokens[ $i ][ 'code' ] === T_NULLABLE ) {
1570 1570
                     $nullableReturnType = true;
1571 1571
                 }
1572 1572
 
1573
-                if (isset($valid[$this->tokens[$i]['code']]) === true) {
1574
-                    if ($returnTypeToken === false) {
1573
+                if ( isset( $valid[ $this->tokens[ $i ][ 'code' ] ] ) === true ) {
1574
+                    if ( $returnTypeToken === false ) {
1575 1575
                         $returnTypeToken = $i;
1576 1576
                     }
1577 1577
 
1578
-                    $returnType .= $this->tokens[$i]['content'];
1578
+                    $returnType .= $this->tokens[ $i ][ 'content' ];
1579 1579
                 }
1580 1580
             }
1581 1581
 
1582
-            $end     = $this->findNext([T_OPEN_CURLY_BRACKET, T_SEMICOLON], $this->tokens[$stackPtr]['parenthesis_closer']);
1583
-            $hasBody = $this->tokens[$end]['code'] === T_OPEN_CURLY_BRACKET;
1582
+            $end     = $this->findNext( [ T_OPEN_CURLY_BRACKET, T_SEMICOLON ], $this->tokens[ $stackPtr ][ 'parenthesis_closer' ] );
1583
+            $hasBody = $this->tokens[ $end ][ 'code' ] === T_OPEN_CURLY_BRACKET;
1584 1584
         }//end if
1585 1585
 
1586
-        if ($returnType !== '' && $nullableReturnType === true) {
1587
-            $returnType = '?'.$returnType;
1586
+        if ( $returnType !== '' && $nullableReturnType === true ) {
1587
+            $returnType = '?' . $returnType;
1588 1588
         }
1589 1589
 
1590 1590
         return [
@@ -1624,47 +1624,47 @@  discard block
 block discarded – undo
1624 1624
      *                                                        T_VARIABLE token, or if the position is not
1625 1625
      *                                                        a class member variable.
1626 1626
      */
1627
-    public function getMemberProperties($stackPtr)
1627
+    public function getMemberProperties( $stackPtr )
1628 1628
     {
1629
-        if ($this->tokens[$stackPtr]['code'] !== T_VARIABLE) {
1630
-            throw new TokenizerException('$stackPtr must be of type T_VARIABLE');
1629
+        if ( $this->tokens[ $stackPtr ][ 'code' ] !== T_VARIABLE ) {
1630
+            throw new TokenizerException( '$stackPtr must be of type T_VARIABLE' );
1631 1631
         }
1632 1632
 
1633
-        $conditions = array_keys($this->tokens[$stackPtr]['conditions']);
1634
-        $ptr        = array_pop($conditions);
1635
-        if (isset($this->tokens[$ptr]) === false
1636
-            || ($this->tokens[$ptr]['code'] !== T_CLASS
1637
-            && $this->tokens[$ptr]['code'] !== T_ANON_CLASS
1638
-            && $this->tokens[$ptr]['code'] !== T_TRAIT)
1633
+        $conditions = array_keys( $this->tokens[ $stackPtr ][ 'conditions' ] );
1634
+        $ptr        = array_pop( $conditions );
1635
+        if ( isset( $this->tokens[ $ptr ] ) === false
1636
+            || ( $this->tokens[ $ptr ][ 'code' ] !== T_CLASS
1637
+            && $this->tokens[ $ptr ][ 'code' ] !== T_ANON_CLASS
1638
+            && $this->tokens[ $ptr ][ 'code' ] !== T_TRAIT )
1639 1639
         ) {
1640
-            if (isset($this->tokens[$ptr]) === true
1641
-                && $this->tokens[$ptr]['code'] === T_INTERFACE
1640
+            if ( isset( $this->tokens[ $ptr ] ) === true
1641
+                && $this->tokens[ $ptr ][ 'code' ] === T_INTERFACE
1642 1642
             ) {
1643 1643
                 // T_VARIABLEs in interfaces can actually be method arguments
1644 1644
                 // but they wont be seen as being inside the method because there
1645 1645
                 // are no scope openers and closers for abstract methods. If it is in
1646 1646
                 // parentheses, we can be pretty sure it is a method argument.
1647
-                if (isset($this->tokens[$stackPtr]['nested_parenthesis']) === false
1648
-                    || empty($this->tokens[$stackPtr]['nested_parenthesis']) === true
1647
+                if ( isset( $this->tokens[ $stackPtr ][ 'nested_parenthesis' ] ) === false
1648
+                    || empty( $this->tokens[ $stackPtr ][ 'nested_parenthesis' ] ) === true
1649 1649
                 ) {
1650 1650
                     $error = 'Possible parse error: interfaces may not include member vars';
1651
-                    $this->addWarning($error, $stackPtr, 'Internal.ParseError.InterfaceHasMemberVar');
1652
-                    return [];
1651
+                    $this->addWarning( $error, $stackPtr, 'Internal.ParseError.InterfaceHasMemberVar' );
1652
+                    return [ ];
1653 1653
                 }
1654 1654
             } else {
1655
-                throw new TokenizerException('$stackPtr is not a class member var');
1655
+                throw new TokenizerException( '$stackPtr is not a class member var' );
1656 1656
             }
1657 1657
         }
1658 1658
 
1659 1659
         // Make sure it's not a method parameter.
1660
-        if (empty($this->tokens[$stackPtr]['nested_parenthesis']) === false) {
1661
-            $parenthesis = array_keys($this->tokens[$stackPtr]['nested_parenthesis']);
1662
-            $deepestOpen = array_pop($parenthesis);
1663
-            if ($deepestOpen > $ptr
1664
-                && isset($this->tokens[$deepestOpen]['parenthesis_owner']) === true
1665
-                && $this->tokens[$this->tokens[$deepestOpen]['parenthesis_owner']]['code'] === T_FUNCTION
1660
+        if ( empty( $this->tokens[ $stackPtr ][ 'nested_parenthesis' ] ) === false ) {
1661
+            $parenthesis = array_keys( $this->tokens[ $stackPtr ][ 'nested_parenthesis' ] );
1662
+            $deepestOpen = array_pop( $parenthesis );
1663
+            if ( $deepestOpen > $ptr
1664
+                && isset( $this->tokens[ $deepestOpen ][ 'parenthesis_owner' ] ) === true
1665
+                && $this->tokens[ $this->tokens[ $deepestOpen ][ 'parenthesis_owner' ] ][ 'code' ] === T_FUNCTION
1666 1666
             ) {
1667
-                throw new TokenizerException('$stackPtr is not a class member var');
1667
+                throw new TokenizerException( '$stackPtr is not a class member var' );
1668 1668
             }
1669 1669
         }
1670 1670
 
@@ -1688,15 +1688,15 @@  discard block
 block discarded – undo
1688 1688
                 T_OPEN_CURLY_BRACKET,
1689 1689
                 T_CLOSE_CURLY_BRACKET,
1690 1690
             ],
1691
-            ($stackPtr - 1)
1691
+            ( $stackPtr - 1 )
1692 1692
         );
1693 1693
 
1694
-        for ($i = ($startOfStatement + 1); $i < $stackPtr; $i++) {
1695
-            if (isset($valid[$this->tokens[$i]['code']]) === false) {
1694
+        for ( $i = ( $startOfStatement + 1 ); $i < $stackPtr; $i++ ) {
1695
+            if ( isset( $valid[ $this->tokens[ $i ][ 'code' ] ] ) === false ) {
1696 1696
                 break;
1697 1697
             }
1698 1698
 
1699
-            switch ($this->tokens[$i]['code']) {
1699
+            switch ( $this->tokens[ $i ][ 'code' ] ) {
1700 1700
             case T_PUBLIC:
1701 1701
                 $scope          = 'public';
1702 1702
                 $scopeSpecified = true;
@@ -1742,10 +1742,10 @@  discard block
 block discarded – undo
1742 1742
      * @throws \PHP_CodeSniffer\Exceptions\TokenizerException If the specified position is not a
1743 1743
      *                                                        T_CLASS token.
1744 1744
      */
1745
-    public function getClassProperties($stackPtr)
1745
+    public function getClassProperties( $stackPtr )
1746 1746
     {
1747
-        if ($this->tokens[$stackPtr]['code'] !== T_CLASS) {
1748
-            throw new TokenizerException('$stackPtr must be of type T_CLASS');
1747
+        if ( $this->tokens[ $stackPtr ][ 'code' ] !== T_CLASS ) {
1748
+            throw new TokenizerException( '$stackPtr must be of type T_CLASS' );
1749 1749
         }
1750 1750
 
1751 1751
         $valid = [
@@ -1759,12 +1759,12 @@  discard block
 block discarded – undo
1759 1759
         $isAbstract = false;
1760 1760
         $isFinal    = false;
1761 1761
 
1762
-        for ($i = ($stackPtr - 1); $i > 0; $i--) {
1763
-            if (isset($valid[$this->tokens[$i]['code']]) === false) {
1762
+        for ( $i = ( $stackPtr - 1 ); $i > 0; $i-- ) {
1763
+            if ( isset( $valid[ $this->tokens[ $i ][ 'code' ] ] ) === false ) {
1764 1764
                 break;
1765 1765
             }
1766 1766
 
1767
-            switch ($this->tokens[$i]['code']) {
1767
+            switch ( $this->tokens[ $i ][ 'code' ] ) {
1768 1768
             case T_ABSTRACT:
1769 1769
                 $isAbstract = true;
1770 1770
                 break;
@@ -1793,35 +1793,35 @@  discard block
 block discarded – undo
1793 1793
      *
1794 1794
      * @return boolean
1795 1795
      */
1796
-    public function isReference($stackPtr)
1796
+    public function isReference( $stackPtr )
1797 1797
     {
1798
-        if ($this->tokens[$stackPtr]['code'] !== T_BITWISE_AND) {
1798
+        if ( $this->tokens[ $stackPtr ][ 'code' ] !== T_BITWISE_AND ) {
1799 1799
             return false;
1800 1800
         }
1801 1801
 
1802 1802
         $tokenBefore = $this->findPrevious(
1803 1803
             Util\Tokens::$emptyTokens,
1804
-            ($stackPtr - 1),
1804
+            ( $stackPtr - 1 ),
1805 1805
             null,
1806 1806
             true
1807 1807
         );
1808 1808
 
1809
-        if ($this->tokens[$tokenBefore]['code'] === T_FUNCTION) {
1809
+        if ( $this->tokens[ $tokenBefore ][ 'code' ] === T_FUNCTION ) {
1810 1810
             // Function returns a reference.
1811 1811
             return true;
1812 1812
         }
1813 1813
 
1814
-        if ($this->tokens[$tokenBefore]['code'] === T_DOUBLE_ARROW) {
1814
+        if ( $this->tokens[ $tokenBefore ][ 'code' ] === T_DOUBLE_ARROW ) {
1815 1815
             // Inside a foreach loop or array assignment, this is a reference.
1816 1816
             return true;
1817 1817
         }
1818 1818
 
1819
-        if ($this->tokens[$tokenBefore]['code'] === T_AS) {
1819
+        if ( $this->tokens[ $tokenBefore ][ 'code' ] === T_AS ) {
1820 1820
             // Inside a foreach loop, this is a reference.
1821 1821
             return true;
1822 1822
         }
1823 1823
 
1824
-        if (isset(Util\Tokens::$assignmentTokens[$this->tokens[$tokenBefore]['code']]) === true) {
1824
+        if ( isset( Util\Tokens::$assignmentTokens[ $this->tokens[ $tokenBefore ][ 'code' ] ] ) === true ) {
1825 1825
             // This is directly after an assignment. It's a reference. Even if
1826 1826
             // it is part of an operation, the other tests will handle it.
1827 1827
             return true;
@@ -1829,37 +1829,37 @@  discard block
 block discarded – undo
1829 1829
 
1830 1830
         $tokenAfter = $this->findNext(
1831 1831
             Util\Tokens::$emptyTokens,
1832
-            ($stackPtr + 1),
1832
+            ( $stackPtr + 1 ),
1833 1833
             null,
1834 1834
             true
1835 1835
         );
1836 1836
 
1837
-        if ($this->tokens[$tokenAfter]['code'] === T_NEW) {
1837
+        if ( $this->tokens[ $tokenAfter ][ 'code' ] === T_NEW ) {
1838 1838
             return true;
1839 1839
         }
1840 1840
 
1841
-        if (isset($this->tokens[$stackPtr]['nested_parenthesis']) === true) {
1842
-            $brackets    = $this->tokens[$stackPtr]['nested_parenthesis'];
1843
-            $lastBracket = array_pop($brackets);
1844
-            if (isset($this->tokens[$lastBracket]['parenthesis_owner']) === true) {
1845
-                $owner = $this->tokens[$this->tokens[$lastBracket]['parenthesis_owner']];
1846
-                if ($owner['code'] === T_FUNCTION
1847
-                    || $owner['code'] === T_CLOSURE
1841
+        if ( isset( $this->tokens[ $stackPtr ][ 'nested_parenthesis' ] ) === true ) {
1842
+            $brackets    = $this->tokens[ $stackPtr ][ 'nested_parenthesis' ];
1843
+            $lastBracket = array_pop( $brackets );
1844
+            if ( isset( $this->tokens[ $lastBracket ][ 'parenthesis_owner' ] ) === true ) {
1845
+                $owner = $this->tokens[ $this->tokens[ $lastBracket ][ 'parenthesis_owner' ] ];
1846
+                if ( $owner[ 'code' ] === T_FUNCTION
1847
+                    || $owner[ 'code' ] === T_CLOSURE
1848 1848
                 ) {
1849
-                    $params = $this->getMethodParameters($this->tokens[$lastBracket]['parenthesis_owner']);
1850
-                    foreach ($params as $param) {
1849
+                    $params = $this->getMethodParameters( $this->tokens[ $lastBracket ][ 'parenthesis_owner' ] );
1850
+                    foreach ( $params as $param ) {
1851 1851
                         $varToken = $tokenAfter;
1852
-                        if ($param['variable_length'] === true) {
1852
+                        if ( $param[ 'variable_length' ] === true ) {
1853 1853
                             $varToken = $this->findNext(
1854
-                                (Util\Tokens::$emptyTokens + [T_ELLIPSIS]),
1855
-                                ($stackPtr + 1),
1854
+                                ( Util\Tokens::$emptyTokens + [ T_ELLIPSIS ] ),
1855
+                                ( $stackPtr + 1 ),
1856 1856
                                 null,
1857 1857
                                 true
1858 1858
                             );
1859 1859
                         }
1860 1860
 
1861
-                        if ($param['token'] === $varToken
1862
-                            && $param['pass_by_reference'] === true
1861
+                        if ( $param[ 'token' ] === $varToken
1862
+                            && $param[ 'pass_by_reference' ] === true
1863 1863
                         ) {
1864 1864
                             // Function parameter declared to be passed by reference.
1865 1865
                             return true;
@@ -1868,14 +1868,14 @@  discard block
 block discarded – undo
1868 1868
                 }//end if
1869 1869
             } else {
1870 1870
                 $prev = false;
1871
-                for ($t = ($this->tokens[$lastBracket]['parenthesis_opener'] - 1); $t >= 0; $t--) {
1872
-                    if ($this->tokens[$t]['code'] !== T_WHITESPACE) {
1871
+                for ( $t = ( $this->tokens[ $lastBracket ][ 'parenthesis_opener' ] - 1 ); $t >= 0; $t-- ) {
1872
+                    if ( $this->tokens[ $t ][ 'code' ] !== T_WHITESPACE ) {
1873 1873
                         $prev = $t;
1874 1874
                         break;
1875 1875
                     }
1876 1876
                 }
1877 1877
 
1878
-                if ($prev !== false && $this->tokens[$prev]['code'] === T_USE) {
1878
+                if ( $prev !== false && $this->tokens[ $prev ][ 'code' ] === T_USE ) {
1879 1879
                     // Closure use by reference.
1880 1880
                     return true;
1881 1881
                 }
@@ -1883,29 +1883,29 @@  discard block
 block discarded – undo
1883 1883
         }//end if
1884 1884
 
1885 1885
         // Pass by reference in function calls and assign by reference in arrays.
1886
-        if ($this->tokens[$tokenBefore]['code'] === T_OPEN_PARENTHESIS
1887
-            || $this->tokens[$tokenBefore]['code'] === T_COMMA
1888
-            || $this->tokens[$tokenBefore]['code'] === T_OPEN_SHORT_ARRAY
1886
+        if ( $this->tokens[ $tokenBefore ][ 'code' ] === T_OPEN_PARENTHESIS
1887
+            || $this->tokens[ $tokenBefore ][ 'code' ] === T_COMMA
1888
+            || $this->tokens[ $tokenBefore ][ 'code' ] === T_OPEN_SHORT_ARRAY
1889 1889
         ) {
1890
-            if ($this->tokens[$tokenAfter]['code'] === T_VARIABLE) {
1890
+            if ( $this->tokens[ $tokenAfter ][ 'code' ] === T_VARIABLE ) {
1891 1891
                 return true;
1892 1892
             } else {
1893 1893
                 $skip   = Util\Tokens::$emptyTokens;
1894
-                $skip[] = T_NS_SEPARATOR;
1895
-                $skip[] = T_SELF;
1896
-                $skip[] = T_PARENT;
1897
-                $skip[] = T_STATIC;
1898
-                $skip[] = T_STRING;
1899
-                $skip[] = T_NAMESPACE;
1900
-                $skip[] = T_DOUBLE_COLON;
1894
+                $skip[ ] = T_NS_SEPARATOR;
1895
+                $skip[ ] = T_SELF;
1896
+                $skip[ ] = T_PARENT;
1897
+                $skip[ ] = T_STATIC;
1898
+                $skip[ ] = T_STRING;
1899
+                $skip[ ] = T_NAMESPACE;
1900
+                $skip[ ] = T_DOUBLE_COLON;
1901 1901
 
1902 1902
                 $nextSignificantAfter = $this->findNext(
1903 1903
                     $skip,
1904
-                    ($stackPtr + 1),
1904
+                    ( $stackPtr + 1 ),
1905 1905
                     null,
1906 1906
                     true
1907 1907
                 );
1908
-                if ($this->tokens[$nextSignificantAfter]['code'] === T_VARIABLE) {
1908
+                if ( $this->tokens[ $nextSignificantAfter ][ 'code' ] === T_VARIABLE ) {
1909 1909
                     return true;
1910 1910
                 }
1911 1911
             }//end if
@@ -1927,29 +1927,29 @@  discard block
 block discarded – undo
1927 1927
      *
1928 1928
      * @return string The token contents.
1929 1929
      */
1930
-    public function getTokensAsString($start, $length, $origContent=false)
1930
+    public function getTokensAsString( $start, $length, $origContent = false )
1931 1931
     {
1932
-        if (is_int($start) === false || isset($this->tokens[$start]) === false) {
1933
-            throw new RuntimeException('The $start position for getTokensAsString() must exist in the token stack');
1932
+        if ( is_int( $start ) === false || isset( $this->tokens[ $start ] ) === false ) {
1933
+            throw new RuntimeException( 'The $start position for getTokensAsString() must exist in the token stack' );
1934 1934
         }
1935 1935
 
1936
-        if (is_int($length) === false || $length <= 0) {
1936
+        if ( is_int( $length ) === false || $length <= 0 ) {
1937 1937
             return '';
1938 1938
         }
1939 1939
 
1940 1940
         $str = '';
1941
-        $end = ($start + $length);
1942
-        if ($end > $this->numTokens) {
1941
+        $end = ( $start + $length );
1942
+        if ( $end > $this->numTokens ) {
1943 1943
             $end = $this->numTokens;
1944 1944
         }
1945 1945
 
1946
-        for ($i = $start; $i < $end; $i++) {
1946
+        for ( $i = $start; $i < $end; $i++ ) {
1947 1947
             // If tabs are being converted to spaces by the tokeniser, the
1948 1948
             // original content should be used instead of the converted content.
1949
-            if ($origContent === true && isset($this->tokens[$i]['orig_content']) === true) {
1950
-                $str .= $this->tokens[$i]['orig_content'];
1949
+            if ( $origContent === true && isset( $this->tokens[ $i ][ 'orig_content' ] ) === true ) {
1950
+                $str .= $this->tokens[ $i ][ 'orig_content' ];
1951 1951
             } else {
1952
-                $str .= $this->tokens[$i]['content'];
1952
+                $str .= $this->tokens[ $i ][ 'content' ];
1953 1953
             }
1954 1954
         }
1955 1955
 
@@ -1987,48 +1987,48 @@  discard block
 block discarded – undo
1987 1987
     public function findPrevious(
1988 1988
         $types,
1989 1989
         $start,
1990
-        $end=null,
1991
-        $exclude=false,
1992
-        $value=null,
1993
-        $local=false
1990
+        $end = null,
1991
+        $exclude = false,
1992
+        $value = null,
1993
+        $local = false
1994 1994
     ) {
1995
-        $types = (array) $types;
1995
+        $types = (array)$types;
1996 1996
 
1997
-        if ($end === null) {
1997
+        if ( $end === null ) {
1998 1998
             $end = 0;
1999 1999
         }
2000 2000
 
2001
-        for ($i = $start; $i >= $end; $i--) {
2002
-            $found = (bool) $exclude;
2003
-            foreach ($types as $type) {
2004
-                if ($this->tokens[$i]['code'] === $type) {
2005
-                    $found = !$exclude;
2001
+        for ( $i = $start; $i >= $end; $i-- ) {
2002
+            $found = (bool)$exclude;
2003
+            foreach ( $types as $type ) {
2004
+                if ( $this->tokens[ $i ][ 'code' ] === $type ) {
2005
+                    $found = ! $exclude;
2006 2006
                     break;
2007 2007
                 }
2008 2008
             }
2009 2009
 
2010
-            if ($found === true) {
2011
-                if ($value === null) {
2010
+            if ( $found === true ) {
2011
+                if ( $value === null ) {
2012 2012
                     return $i;
2013
-                } else if ($this->tokens[$i]['content'] === $value) {
2013
+                } else if ( $this->tokens[ $i ][ 'content' ] === $value ) {
2014 2014
                     return $i;
2015 2015
                 }
2016 2016
             }
2017 2017
 
2018
-            if ($local === true) {
2019
-                if (isset($this->tokens[$i]['scope_opener']) === true
2020
-                    && $i === $this->tokens[$i]['scope_closer']
2018
+            if ( $local === true ) {
2019
+                if ( isset( $this->tokens[ $i ][ 'scope_opener' ] ) === true
2020
+                    && $i === $this->tokens[ $i ][ 'scope_closer' ]
2021 2021
                 ) {
2022
-                    $i = $this->tokens[$i]['scope_opener'];
2023
-                } else if (isset($this->tokens[$i]['bracket_opener']) === true
2024
-                    && $i === $this->tokens[$i]['bracket_closer']
2022
+                    $i = $this->tokens[ $i ][ 'scope_opener' ];
2023
+                } else if ( isset( $this->tokens[ $i ][ 'bracket_opener' ] ) === true
2024
+                    && $i === $this->tokens[ $i ][ 'bracket_closer' ]
2025 2025
                 ) {
2026
-                    $i = $this->tokens[$i]['bracket_opener'];
2027
-                } else if (isset($this->tokens[$i]['parenthesis_opener']) === true
2028
-                    && $i === $this->tokens[$i]['parenthesis_closer']
2026
+                    $i = $this->tokens[ $i ][ 'bracket_opener' ];
2027
+                } else if ( isset( $this->tokens[ $i ][ 'parenthesis_opener' ] ) === true
2028
+                    && $i === $this->tokens[ $i ][ 'parenthesis_closer' ]
2029 2029
                 ) {
2030
-                    $i = $this->tokens[$i]['parenthesis_opener'];
2031
-                } else if ($this->tokens[$i]['code'] === T_SEMICOLON) {
2030
+                    $i = $this->tokens[ $i ][ 'parenthesis_opener' ];
2031
+                } else if ( $this->tokens[ $i ][ 'code' ] === T_SEMICOLON ) {
2032 2032
                     break;
2033 2033
                 }
2034 2034
             }
@@ -2068,35 +2068,35 @@  discard block
 block discarded – undo
2068 2068
     public function findNext(
2069 2069
         $types,
2070 2070
         $start,
2071
-        $end=null,
2072
-        $exclude=false,
2073
-        $value=null,
2074
-        $local=false
2071
+        $end = null,
2072
+        $exclude = false,
2073
+        $value = null,
2074
+        $local = false
2075 2075
     ) {
2076
-        $types = (array) $types;
2076
+        $types = (array)$types;
2077 2077
 
2078
-        if ($end === null || $end > $this->numTokens) {
2078
+        if ( $end === null || $end > $this->numTokens ) {
2079 2079
             $end = $this->numTokens;
2080 2080
         }
2081 2081
 
2082
-        for ($i = $start; $i < $end; $i++) {
2083
-            $found = (bool) $exclude;
2084
-            foreach ($types as $type) {
2085
-                if ($this->tokens[$i]['code'] === $type) {
2086
-                    $found = !$exclude;
2082
+        for ( $i = $start; $i < $end; $i++ ) {
2083
+            $found = (bool)$exclude;
2084
+            foreach ( $types as $type ) {
2085
+                if ( $this->tokens[ $i ][ 'code' ] === $type ) {
2086
+                    $found = ! $exclude;
2087 2087
                     break;
2088 2088
                 }
2089 2089
             }
2090 2090
 
2091
-            if ($found === true) {
2092
-                if ($value === null) {
2091
+            if ( $found === true ) {
2092
+                if ( $value === null ) {
2093 2093
                     return $i;
2094
-                } else if ($this->tokens[$i]['content'] === $value) {
2094
+                } else if ( $this->tokens[ $i ][ 'content' ] === $value ) {
2095 2095
                     return $i;
2096 2096
                 }
2097 2097
             }
2098 2098
 
2099
-            if ($local === true && $this->tokens[$i]['code'] === T_SEMICOLON) {
2099
+            if ( $local === true && $this->tokens[ $i ][ 'code' ] === T_SEMICOLON ) {
2100 2100
                 break;
2101 2101
             }
2102 2102
         }//end for
@@ -2114,52 +2114,52 @@  discard block
 block discarded – undo
2114 2114
      *
2115 2115
      * @return int
2116 2116
      */
2117
-    public function findStartOfStatement($start, $ignore=null)
2117
+    public function findStartOfStatement( $start, $ignore = null )
2118 2118
     {
2119 2119
         $endTokens = Util\Tokens::$blockOpeners;
2120 2120
 
2121
-        $endTokens[T_COLON]            = true;
2122
-        $endTokens[T_COMMA]            = true;
2123
-        $endTokens[T_DOUBLE_ARROW]     = true;
2124
-        $endTokens[T_SEMICOLON]        = true;
2125
-        $endTokens[T_OPEN_TAG]         = true;
2126
-        $endTokens[T_CLOSE_TAG]        = true;
2127
-        $endTokens[T_OPEN_SHORT_ARRAY] = true;
2128
-
2129
-        if ($ignore !== null) {
2130
-            $ignore = (array) $ignore;
2131
-            foreach ($ignore as $code) {
2132
-                unset($endTokens[$code]);
2121
+        $endTokens[ T_COLON ]            = true;
2122
+        $endTokens[ T_COMMA ]            = true;
2123
+        $endTokens[ T_DOUBLE_ARROW ]     = true;
2124
+        $endTokens[ T_SEMICOLON ]        = true;
2125
+        $endTokens[ T_OPEN_TAG ]         = true;
2126
+        $endTokens[ T_CLOSE_TAG ]        = true;
2127
+        $endTokens[ T_OPEN_SHORT_ARRAY ] = true;
2128
+
2129
+        if ( $ignore !== null ) {
2130
+            $ignore = (array)$ignore;
2131
+            foreach ( $ignore as $code ) {
2132
+                unset( $endTokens[ $code ] );
2133 2133
             }
2134 2134
         }
2135 2135
 
2136 2136
         $lastNotEmpty = $start;
2137 2137
 
2138
-        for ($i = $start; $i >= 0; $i--) {
2139
-            if (isset($endTokens[$this->tokens[$i]['code']]) === true) {
2138
+        for ( $i = $start; $i >= 0; $i-- ) {
2139
+            if ( isset( $endTokens[ $this->tokens[ $i ][ 'code' ] ] ) === true ) {
2140 2140
                 // Found the end of the previous statement.
2141 2141
                 return $lastNotEmpty;
2142 2142
             }
2143 2143
 
2144
-            if (isset($this->tokens[$i]['scope_opener']) === true
2145
-                && $i === $this->tokens[$i]['scope_closer']
2144
+            if ( isset( $this->tokens[ $i ][ 'scope_opener' ] ) === true
2145
+                && $i === $this->tokens[ $i ][ 'scope_closer' ]
2146 2146
             ) {
2147 2147
                 // Found the end of the previous scope block.
2148 2148
                 return $lastNotEmpty;
2149 2149
             }
2150 2150
 
2151 2151
             // Skip nested statements.
2152
-            if (isset($this->tokens[$i]['bracket_opener']) === true
2153
-                && $i === $this->tokens[$i]['bracket_closer']
2152
+            if ( isset( $this->tokens[ $i ][ 'bracket_opener' ] ) === true
2153
+                && $i === $this->tokens[ $i ][ 'bracket_closer' ]
2154 2154
             ) {
2155
-                $i = $this->tokens[$i]['bracket_opener'];
2156
-            } else if (isset($this->tokens[$i]['parenthesis_opener']) === true
2157
-                && $i === $this->tokens[$i]['parenthesis_closer']
2155
+                $i = $this->tokens[ $i ][ 'bracket_opener' ];
2156
+            } else if ( isset( $this->tokens[ $i ][ 'parenthesis_opener' ] ) === true
2157
+                && $i === $this->tokens[ $i ][ 'parenthesis_closer' ]
2158 2158
             ) {
2159
-                $i = $this->tokens[$i]['parenthesis_opener'];
2159
+                $i = $this->tokens[ $i ][ 'parenthesis_opener' ];
2160 2160
             }
2161 2161
 
2162
-            if (isset(Util\Tokens::$emptyTokens[$this->tokens[$i]['code']]) === false) {
2162
+            if ( isset( Util\Tokens::$emptyTokens[ $this->tokens[ $i ][ 'code' ] ] ) === false ) {
2163 2163
                 $lastNotEmpty = $i;
2164 2164
             }
2165 2165
         }//end for
@@ -2177,7 +2177,7 @@  discard block
 block discarded – undo
2177 2177
      *
2178 2178
      * @return int
2179 2179
      */
2180
-    public function findEndOfStatement($start, $ignore=null)
2180
+    public function findEndOfStatement( $start, $ignore = null )
2181 2181
     {
2182 2182
         $endTokens = [
2183 2183
             T_COLON                => true,
@@ -2192,24 +2192,24 @@  discard block
 block discarded – undo
2192 2192
             T_CLOSE_TAG            => true,
2193 2193
         ];
2194 2194
 
2195
-        if ($ignore !== null) {
2196
-            $ignore = (array) $ignore;
2197
-            foreach ($ignore as $code) {
2198
-                unset($endTokens[$code]);
2195
+        if ( $ignore !== null ) {
2196
+            $ignore = (array)$ignore;
2197
+            foreach ( $ignore as $code ) {
2198
+                unset( $endTokens[ $code ] );
2199 2199
             }
2200 2200
         }
2201 2201
 
2202 2202
         $lastNotEmpty = $start;
2203 2203
 
2204
-        for ($i = $start; $i < $this->numTokens; $i++) {
2205
-            if ($i !== $start && isset($endTokens[$this->tokens[$i]['code']]) === true) {
2204
+        for ( $i = $start; $i < $this->numTokens; $i++ ) {
2205
+            if ( $i !== $start && isset( $endTokens[ $this->tokens[ $i ][ 'code' ] ] ) === true ) {
2206 2206
                 // Found the end of the statement.
2207
-                if ($this->tokens[$i]['code'] === T_CLOSE_PARENTHESIS
2208
-                    || $this->tokens[$i]['code'] === T_CLOSE_SQUARE_BRACKET
2209
-                    || $this->tokens[$i]['code'] === T_CLOSE_CURLY_BRACKET
2210
-                    || $this->tokens[$i]['code'] === T_CLOSE_SHORT_ARRAY
2211
-                    || $this->tokens[$i]['code'] === T_OPEN_TAG
2212
-                    || $this->tokens[$i]['code'] === T_CLOSE_TAG
2207
+                if ( $this->tokens[ $i ][ 'code' ] === T_CLOSE_PARENTHESIS
2208
+                    || $this->tokens[ $i ][ 'code' ] === T_CLOSE_SQUARE_BRACKET
2209
+                    || $this->tokens[ $i ][ 'code' ] === T_CLOSE_CURLY_BRACKET
2210
+                    || $this->tokens[ $i ][ 'code' ] === T_CLOSE_SHORT_ARRAY
2211
+                    || $this->tokens[ $i ][ 'code' ] === T_OPEN_TAG
2212
+                    || $this->tokens[ $i ][ 'code' ] === T_CLOSE_TAG
2213 2213
                 ) {
2214 2214
                     return $lastNotEmpty;
2215 2215
                 }
@@ -2218,31 +2218,31 @@  discard block
 block discarded – undo
2218 2218
             }
2219 2219
 
2220 2220
             // Skip nested statements.
2221
-            if (isset($this->tokens[$i]['scope_closer']) === true
2222
-                && ($i === $this->tokens[$i]['scope_opener']
2223
-                || $i === $this->tokens[$i]['scope_condition'])
2221
+            if ( isset( $this->tokens[ $i ][ 'scope_closer' ] ) === true
2222
+                && ( $i === $this->tokens[ $i ][ 'scope_opener' ]
2223
+                || $i === $this->tokens[ $i ][ 'scope_condition' ] )
2224 2224
             ) {
2225
-                if ($i === $start && isset(Util\Tokens::$scopeOpeners[$this->tokens[$i]['code']]) === true) {
2226
-                    return $this->tokens[$i]['scope_closer'];
2225
+                if ( $i === $start && isset( Util\Tokens::$scopeOpeners[ $this->tokens[ $i ][ 'code' ] ] ) === true ) {
2226
+                    return $this->tokens[ $i ][ 'scope_closer' ];
2227 2227
                 }
2228 2228
 
2229
-                $i = $this->tokens[$i]['scope_closer'];
2230
-            } else if (isset($this->tokens[$i]['bracket_closer']) === true
2231
-                && $i === $this->tokens[$i]['bracket_opener']
2229
+                $i = $this->tokens[ $i ][ 'scope_closer' ];
2230
+            } else if ( isset( $this->tokens[ $i ][ 'bracket_closer' ] ) === true
2231
+                && $i === $this->tokens[ $i ][ 'bracket_opener' ]
2232 2232
             ) {
2233
-                $i = $this->tokens[$i]['bracket_closer'];
2234
-            } else if (isset($this->tokens[$i]['parenthesis_closer']) === true
2235
-                && $i === $this->tokens[$i]['parenthesis_opener']
2233
+                $i = $this->tokens[ $i ][ 'bracket_closer' ];
2234
+            } else if ( isset( $this->tokens[ $i ][ 'parenthesis_closer' ] ) === true
2235
+                && $i === $this->tokens[ $i ][ 'parenthesis_opener' ]
2236 2236
             ) {
2237
-                $i = $this->tokens[$i]['parenthesis_closer'];
2237
+                $i = $this->tokens[ $i ][ 'parenthesis_closer' ];
2238 2238
             }
2239 2239
 
2240
-            if (isset(Util\Tokens::$emptyTokens[$this->tokens[$i]['code']]) === false) {
2240
+            if ( isset( Util\Tokens::$emptyTokens[ $this->tokens[ $i ][ 'code' ] ] ) === false ) {
2241 2241
                 $lastNotEmpty = $i;
2242 2242
             }
2243 2243
         }//end for
2244 2244
 
2245
-        return ($this->numTokens - 1);
2245
+        return ( $this->numTokens - 1 );
2246 2246
 
2247 2247
     }//end findEndOfStatement()
2248 2248
 
@@ -2264,38 +2264,38 @@  discard block
 block discarded – undo
2264 2264
      *
2265 2265
      * @return int | bool
2266 2266
      */
2267
-    public function findFirstOnLine($types, $start, $exclude=false, $value=null)
2267
+    public function findFirstOnLine( $types, $start, $exclude = false, $value = null )
2268 2268
     {
2269
-        if (is_array($types) === false) {
2270
-            $types = [$types];
2269
+        if ( is_array( $types ) === false ) {
2270
+            $types = [ $types ];
2271 2271
         }
2272 2272
 
2273 2273
         $foundToken = false;
2274 2274
 
2275
-        for ($i = $start; $i >= 0; $i--) {
2276
-            if ($this->tokens[$i]['line'] < $this->tokens[$start]['line']) {
2275
+        for ( $i = $start; $i >= 0; $i-- ) {
2276
+            if ( $this->tokens[ $i ][ 'line' ] < $this->tokens[ $start ][ 'line' ] ) {
2277 2277
                 break;
2278 2278
             }
2279 2279
 
2280 2280
             $found = $exclude;
2281
-            foreach ($types as $type) {
2282
-                if ($exclude === false) {
2283
-                    if ($this->tokens[$i]['code'] === $type) {
2281
+            foreach ( $types as $type ) {
2282
+                if ( $exclude === false ) {
2283
+                    if ( $this->tokens[ $i ][ 'code' ] === $type ) {
2284 2284
                         $found = true;
2285 2285
                         break;
2286 2286
                     }
2287 2287
                 } else {
2288
-                    if ($this->tokens[$i]['code'] === $type) {
2288
+                    if ( $this->tokens[ $i ][ 'code' ] === $type ) {
2289 2289
                         $found = false;
2290 2290
                         break;
2291 2291
                     }
2292 2292
                 }
2293 2293
             }
2294 2294
 
2295
-            if ($found === true) {
2296
-                if ($value === null) {
2295
+            if ( $found === true ) {
2296
+                if ( $value === null ) {
2297 2297
                     $foundToken = $i;
2298
-                } else if ($this->tokens[$i]['content'] === $value) {
2298
+                } else if ( $this->tokens[ $i ][ 'content' ] === $value ) {
2299 2299
                     $foundToken = $i;
2300 2300
                 }
2301 2301
             }
@@ -2314,23 +2314,23 @@  discard block
 block discarded – undo
2314 2314
      *
2315 2315
      * @return boolean
2316 2316
      */
2317
-    public function hasCondition($stackPtr, $types)
2317
+    public function hasCondition( $stackPtr, $types )
2318 2318
     {
2319 2319
         // Check for the existence of the token.
2320
-        if (isset($this->tokens[$stackPtr]) === false) {
2320
+        if ( isset( $this->tokens[ $stackPtr ] ) === false ) {
2321 2321
             return false;
2322 2322
         }
2323 2323
 
2324 2324
         // Make sure the token has conditions.
2325
-        if (isset($this->tokens[$stackPtr]['conditions']) === false) {
2325
+        if ( isset( $this->tokens[ $stackPtr ][ 'conditions' ] ) === false ) {
2326 2326
             return false;
2327 2327
         }
2328 2328
 
2329
-        $types      = (array) $types;
2330
-        $conditions = $this->tokens[$stackPtr]['conditions'];
2329
+        $types      = (array)$types;
2330
+        $conditions = $this->tokens[ $stackPtr ][ 'conditions' ];
2331 2331
 
2332
-        foreach ($types as $type) {
2333
-            if (in_array($type, $conditions, true) === true) {
2332
+        foreach ( $types as $type ) {
2333
+            if ( in_array( $type, $conditions, true ) === true ) {
2334 2334
                 // We found a token with the required type.
2335 2335
                 return true;
2336 2336
             }
@@ -2351,21 +2351,21 @@  discard block
 block discarded – undo
2351 2351
      *
2352 2352
      * @return int
2353 2353
      */
2354
-    public function getCondition($stackPtr, $type)
2354
+    public function getCondition( $stackPtr, $type )
2355 2355
     {
2356 2356
         // Check for the existence of the token.
2357
-        if (isset($this->tokens[$stackPtr]) === false) {
2357
+        if ( isset( $this->tokens[ $stackPtr ] ) === false ) {
2358 2358
             return false;
2359 2359
         }
2360 2360
 
2361 2361
         // Make sure the token has conditions.
2362
-        if (isset($this->tokens[$stackPtr]['conditions']) === false) {
2362
+        if ( isset( $this->tokens[ $stackPtr ][ 'conditions' ] ) === false ) {
2363 2363
             return false;
2364 2364
         }
2365 2365
 
2366
-        $conditions = $this->tokens[$stackPtr]['conditions'];
2367
-        foreach ($conditions as $token => $condition) {
2368
-            if ($condition === $type) {
2366
+        $conditions = $this->tokens[ $stackPtr ][ 'conditions' ];
2367
+        foreach ( $conditions as $token => $condition ) {
2368
+            if ( $condition === $type ) {
2369 2369
                 return $token;
2370 2370
             }
2371 2371
         }
@@ -2385,27 +2385,27 @@  discard block
 block discarded – undo
2385 2385
      *
2386 2386
      * @return string|false
2387 2387
      */
2388
-    public function findExtendedClassName($stackPtr)
2388
+    public function findExtendedClassName( $stackPtr )
2389 2389
     {
2390 2390
         // Check for the existence of the token.
2391
-        if (isset($this->tokens[$stackPtr]) === false) {
2391
+        if ( isset( $this->tokens[ $stackPtr ] ) === false ) {
2392 2392
             return false;
2393 2393
         }
2394 2394
 
2395
-        if ($this->tokens[$stackPtr]['code'] !== T_CLASS
2396
-            && $this->tokens[$stackPtr]['code'] !== T_ANON_CLASS
2397
-            && $this->tokens[$stackPtr]['code'] !== T_INTERFACE
2395
+        if ( $this->tokens[ $stackPtr ][ 'code' ] !== T_CLASS
2396
+            && $this->tokens[ $stackPtr ][ 'code' ] !== T_ANON_CLASS
2397
+            && $this->tokens[ $stackPtr ][ 'code' ] !== T_INTERFACE
2398 2398
         ) {
2399 2399
             return false;
2400 2400
         }
2401 2401
 
2402
-        if (isset($this->tokens[$stackPtr]['scope_opener']) === false) {
2402
+        if ( isset( $this->tokens[ $stackPtr ][ 'scope_opener' ] ) === false ) {
2403 2403
             return false;
2404 2404
         }
2405 2405
 
2406
-        $classOpenerIndex = $this->tokens[$stackPtr]['scope_opener'];
2407
-        $extendsIndex     = $this->findNext(T_EXTENDS, $stackPtr, $classOpenerIndex);
2408
-        if (false === $extendsIndex) {
2406
+        $classOpenerIndex = $this->tokens[ $stackPtr ][ 'scope_opener' ];
2407
+        $extendsIndex     = $this->findNext( T_EXTENDS, $stackPtr, $classOpenerIndex );
2408
+        if ( false === $extendsIndex ) {
2409 2409
             return false;
2410 2410
         }
2411 2411
 
@@ -2415,11 +2415,11 @@  discard block
 block discarded – undo
2415 2415
             T_WHITESPACE,
2416 2416
         ];
2417 2417
 
2418
-        $end  = $this->findNext($find, ($extendsIndex + 1), ($classOpenerIndex + 1), true);
2419
-        $name = $this->getTokensAsString(($extendsIndex + 1), ($end - $extendsIndex - 1));
2420
-        $name = trim($name);
2418
+        $end  = $this->findNext( $find, ( $extendsIndex + 1 ), ( $classOpenerIndex + 1 ), true );
2419
+        $name = $this->getTokensAsString( ( $extendsIndex + 1 ), ( $end - $extendsIndex - 1 ) );
2420
+        $name = trim( $name );
2421 2421
 
2422
-        if ($name === '') {
2422
+        if ( $name === '' ) {
2423 2423
             return false;
2424 2424
         }
2425 2425
 
@@ -2437,26 +2437,26 @@  discard block
 block discarded – undo
2437 2437
      *
2438 2438
      * @return array|false
2439 2439
      */
2440
-    public function findImplementedInterfaceNames($stackPtr)
2440
+    public function findImplementedInterfaceNames( $stackPtr )
2441 2441
     {
2442 2442
         // Check for the existence of the token.
2443
-        if (isset($this->tokens[$stackPtr]) === false) {
2443
+        if ( isset( $this->tokens[ $stackPtr ] ) === false ) {
2444 2444
             return false;
2445 2445
         }
2446 2446
 
2447
-        if ($this->tokens[$stackPtr]['code'] !== T_CLASS
2448
-            && $this->tokens[$stackPtr]['code'] !== T_ANON_CLASS
2447
+        if ( $this->tokens[ $stackPtr ][ 'code' ] !== T_CLASS
2448
+            && $this->tokens[ $stackPtr ][ 'code' ] !== T_ANON_CLASS
2449 2449
         ) {
2450 2450
             return false;
2451 2451
         }
2452 2452
 
2453
-        if (isset($this->tokens[$stackPtr]['scope_closer']) === false) {
2453
+        if ( isset( $this->tokens[ $stackPtr ][ 'scope_closer' ] ) === false ) {
2454 2454
             return false;
2455 2455
         }
2456 2456
 
2457
-        $classOpenerIndex = $this->tokens[$stackPtr]['scope_opener'];
2458
-        $implementsIndex  = $this->findNext(T_IMPLEMENTS, $stackPtr, $classOpenerIndex);
2459
-        if ($implementsIndex === false) {
2457
+        $classOpenerIndex = $this->tokens[ $stackPtr ][ 'scope_opener' ];
2458
+        $implementsIndex  = $this->findNext( T_IMPLEMENTS, $stackPtr, $classOpenerIndex );
2459
+        if ( $implementsIndex === false ) {
2460 2460
             return false;
2461 2461
         }
2462 2462
 
@@ -2467,15 +2467,15 @@  discard block
 block discarded – undo
2467 2467
             T_COMMA,
2468 2468
         ];
2469 2469
 
2470
-        $end  = $this->findNext($find, ($implementsIndex + 1), ($classOpenerIndex + 1), true);
2471
-        $name = $this->getTokensAsString(($implementsIndex + 1), ($end - $implementsIndex - 1));
2472
-        $name = trim($name);
2470
+        $end  = $this->findNext( $find, ( $implementsIndex + 1 ), ( $classOpenerIndex + 1 ), true );
2471
+        $name = $this->getTokensAsString( ( $implementsIndex + 1 ), ( $end - $implementsIndex - 1 ) );
2472
+        $name = trim( $name );
2473 2473
 
2474
-        if ($name === '') {
2474
+        if ( $name === '' ) {
2475 2475
             return false;
2476 2476
         } else {
2477
-            $names = explode(',', $name);
2478
-            $names = array_map('trim', $names);
2477
+            $names = explode( ',', $name );
2478
+            $names = array_map( 'trim', $names );
2479 2479
             return $names;
2480 2480
         }
2481 2481
 
Please login to merge, or discard this patch.
Braces   +34 added lines, -68 removed lines patch added patch discarded remove patch
@@ -16,8 +16,7 @@  discard block
 block discarded – undo
16 16
 use PHP_CodeSniffer\Exceptions\RuntimeException;
17 17
 use PHP_CodeSniffer\Exceptions\TokenizerException;
18 18
 
19
-class File
20
-{
19
+class File {
21 20
 
22 21
     /**
23 22
      * The absolute path to the file associated with this object.
@@ -224,8 +223,7 @@  discard block
 block discarded – undo
224 223
      *
225 224
      * @return void
226 225
      */
227
-    public function __construct($path, Ruleset $ruleset, Config $config)
228
-    {
226
+    public function __construct($path, Ruleset $ruleset, Config $config) {
229 227
         $this->path    = $path;
230 228
         $this->ruleset = $ruleset;
231 229
         $this->config  = $config;
@@ -261,8 +259,7 @@  discard block
 block discarded – undo
261 259
      *
262 260
      * @return void
263 261
      */
264
-    public function setContent($content)
265
-    {
262
+    public function setContent($content) {
266 263
         $this->content = $content;
267 264
         $this->tokens  = [];
268 265
 
@@ -284,8 +281,7 @@  discard block
 block discarded – undo
284 281
      *
285 282
      * @return void
286 283
      */
287
-    public function reloadContent()
288
-    {
284
+    public function reloadContent() {
289 285
 
290 286
     }//end reloadContent()
291 287
 
@@ -295,8 +291,7 @@  discard block
 block discarded – undo
295 291
      *
296 292
      * @return void
297 293
      */
298
-    public function disableCaching()
299
-    {
294
+    public function disableCaching() {
300 295
         $this->configCache['cache'] = false;
301 296
 
302 297
     }//end disableCaching()
@@ -307,8 +302,7 @@  discard block
 block discarded – undo
307 302
      *
308 303
      * @return void
309 304
      */
310
-    public function process()
311
-    {
305
+    public function process() {
312 306
         if ($this->ignored === true) {
313 307
             return;
314 308
         }
@@ -544,8 +538,7 @@  discard block
 block discarded – undo
544 538
      *
545 539
      * @return void
546 540
      */
547
-    public function parse()
548
-    {
541
+    public function parse() {
549 542
         if (empty($this->tokens) === false) {
550 543
             // File has already been parsed.
551 544
             return;
@@ -605,8 +598,7 @@  discard block
 block discarded – undo
605 598
      *
606 599
      * @return array
607 600
      */
608
-    public function getTokens()
609
-    {
601
+    public function getTokens() {
610 602
         return $this->tokens;
611 603
 
612 604
     }//end getTokens()
@@ -617,8 +609,7 @@  discard block
 block discarded – undo
617 609
      *
618 610
      * @return void
619 611
      */
620
-    public function cleanUp()
621
-    {
612
+    public function cleanUp() {
622 613
         $this->listenerTimes = null;
623 614
         $this->content       = null;
624 615
         $this->tokens        = null;
@@ -824,8 +815,7 @@  discard block
 block discarded – undo
824 815
      *
825 816
      * @return boolean
826 817
      */
827
-    protected function addMessage($error, $message, $line, $column, $code, $data, $severity, $fixable)
828
-    {
818
+    protected function addMessage($error, $message, $line, $column, $code, $data, $severity, $fixable) {
829 819
         // Check if this line is ignoring all message codes.
830 820
         if (isset($this->tokenizer->ignoredLines[$line]['.all']) === true) {
831 821
             return false;
@@ -1077,8 +1067,7 @@  discard block
 block discarded – undo
1077 1067
      *
1078 1068
      * @return boolean
1079 1069
      */
1080
-    public function recordMetric($stackPtr, $metric, $value)
1081
-    {
1070
+    public function recordMetric($stackPtr, $metric, $value) {
1082 1071
         if (isset($this->metrics[$metric]) === false) {
1083 1072
             $this->metrics[$metric] = ['values' => [$value => 1]];
1084 1073
             $this->metricTokens[$metric][$stackPtr] = true;
@@ -1101,8 +1090,7 @@  discard block
 block discarded – undo
1101 1090
      *
1102 1091
      * @return int
1103 1092
      */
1104
-    public function getErrorCount()
1105
-    {
1093
+    public function getErrorCount() {
1106 1094
         return $this->errorCount;
1107 1095
 
1108 1096
     }//end getErrorCount()
@@ -1113,8 +1101,7 @@  discard block
 block discarded – undo
1113 1101
      *
1114 1102
      * @return int
1115 1103
      */
1116
-    public function getWarningCount()
1117
-    {
1104
+    public function getWarningCount() {
1118 1105
         return $this->warningCount;
1119 1106
 
1120 1107
     }//end getWarningCount()
@@ -1125,8 +1112,7 @@  discard block
 block discarded – undo
1125 1112
      *
1126 1113
      * @return int
1127 1114
      */
1128
-    public function getFixableCount()
1129
-    {
1115
+    public function getFixableCount() {
1130 1116
         return $this->fixableCount;
1131 1117
 
1132 1118
     }//end getFixableCount()
@@ -1137,8 +1123,7 @@  discard block
 block discarded – undo
1137 1123
      *
1138 1124
      * @return int
1139 1125
      */
1140
-    public function getFixedCount()
1141
-    {
1126
+    public function getFixedCount() {
1142 1127
         return $this->fixedCount;
1143 1128
 
1144 1129
     }//end getFixedCount()
@@ -1149,8 +1134,7 @@  discard block
 block discarded – undo
1149 1134
      *
1150 1135
      * @return array
1151 1136
      */
1152
-    public function getIgnoredLines()
1153
-    {
1137
+    public function getIgnoredLines() {
1154 1138
         return $this->tokenizer->ignoredLines;
1155 1139
 
1156 1140
     }//end getIgnoredLines()
@@ -1161,8 +1145,7 @@  discard block
 block discarded – undo
1161 1145
      *
1162 1146
      * @return array
1163 1147
      */
1164
-    public function getErrors()
1165
-    {
1148
+    public function getErrors() {
1166 1149
         return $this->errors;
1167 1150
 
1168 1151
     }//end getErrors()
@@ -1173,8 +1156,7 @@  discard block
 block discarded – undo
1173 1156
      *
1174 1157
      * @return array
1175 1158
      */
1176
-    public function getWarnings()
1177
-    {
1159
+    public function getWarnings() {
1178 1160
         return $this->warnings;
1179 1161
 
1180 1162
     }//end getWarnings()
@@ -1185,8 +1167,7 @@  discard block
 block discarded – undo
1185 1167
      *
1186 1168
      * @return array
1187 1169
      */
1188
-    public function getMetrics()
1189
-    {
1170
+    public function getMetrics() {
1190 1171
         return $this->metrics;
1191 1172
 
1192 1173
     }//end getMetrics()
@@ -1197,8 +1178,7 @@  discard block
 block discarded – undo
1197 1178
      *
1198 1179
      * @return string
1199 1180
      */
1200
-    public function getFilename()
1201
-    {
1181
+    public function getFilename() {
1202 1182
         return $this->path;
1203 1183
 
1204 1184
     }//end getFilename()
@@ -1216,8 +1196,7 @@  discard block
 block discarded – undo
1216 1196
      *                                                      T_FUNCTION, T_CLASS, T_ANON_CLASS,
1217 1197
      *                                                      T_CLOSURE, T_TRAIT, or T_INTERFACE.
1218 1198
      */
1219
-    public function getDeclarationName($stackPtr)
1220
-    {
1199
+    public function getDeclarationName($stackPtr) {
1221 1200
         $tokenCode = $this->tokens[$stackPtr]['code'];
1222 1201
 
1223 1202
         if ($tokenCode === T_ANON_CLASS || $tokenCode === T_CLOSURE) {
@@ -1282,8 +1261,7 @@  discard block
 block discarded – undo
1282 1261
      * @throws \PHP_CodeSniffer\Exceptions\TokenizerException If the specified $stackPtr is not of
1283 1262
      *                                                        type T_FUNCTION or T_CLOSURE.
1284 1263
      */
1285
-    public function getMethodParameters($stackPtr)
1286
-    {
1264
+    public function getMethodParameters($stackPtr) {
1287 1265
         if ($this->tokens[$stackPtr]['code'] !== T_FUNCTION
1288 1266
             && $this->tokens[$stackPtr]['code'] !== T_CLOSURE
1289 1267
         ) {
@@ -1474,8 +1452,7 @@  discard block
 block discarded – undo
1474 1452
      * @throws \PHP_CodeSniffer\Exceptions\TokenizerException If the specified position is not a
1475 1453
      *                                                        T_FUNCTION token.
1476 1454
      */
1477
-    public function getMethodProperties($stackPtr)
1478
-    {
1455
+    public function getMethodProperties($stackPtr) {
1479 1456
         if ($this->tokens[$stackPtr]['code'] !== T_FUNCTION
1480 1457
             && $this->tokens[$stackPtr]['code'] !== T_CLOSURE
1481 1458
         ) {
@@ -1624,8 +1601,7 @@  discard block
 block discarded – undo
1624 1601
      *                                                        T_VARIABLE token, or if the position is not
1625 1602
      *                                                        a class member variable.
1626 1603
      */
1627
-    public function getMemberProperties($stackPtr)
1628
-    {
1604
+    public function getMemberProperties($stackPtr) {
1629 1605
         if ($this->tokens[$stackPtr]['code'] !== T_VARIABLE) {
1630 1606
             throw new TokenizerException('$stackPtr must be of type T_VARIABLE');
1631 1607
         }
@@ -1742,8 +1718,7 @@  discard block
 block discarded – undo
1742 1718
      * @throws \PHP_CodeSniffer\Exceptions\TokenizerException If the specified position is not a
1743 1719
      *                                                        T_CLASS token.
1744 1720
      */
1745
-    public function getClassProperties($stackPtr)
1746
-    {
1721
+    public function getClassProperties($stackPtr) {
1747 1722
         if ($this->tokens[$stackPtr]['code'] !== T_CLASS) {
1748 1723
             throw new TokenizerException('$stackPtr must be of type T_CLASS');
1749 1724
         }
@@ -1793,8 +1768,7 @@  discard block
 block discarded – undo
1793 1768
      *
1794 1769
      * @return boolean
1795 1770
      */
1796
-    public function isReference($stackPtr)
1797
-    {
1771
+    public function isReference($stackPtr) {
1798 1772
         if ($this->tokens[$stackPtr]['code'] !== T_BITWISE_AND) {
1799 1773
             return false;
1800 1774
         }
@@ -1927,8 +1901,7 @@  discard block
 block discarded – undo
1927 1901
      *
1928 1902
      * @return string The token contents.
1929 1903
      */
1930
-    public function getTokensAsString($start, $length, $origContent=false)
1931
-    {
1904
+    public function getTokensAsString($start, $length, $origContent=false) {
1932 1905
         if (is_int($start) === false || isset($this->tokens[$start]) === false) {
1933 1906
             throw new RuntimeException('The $start position for getTokensAsString() must exist in the token stack');
1934 1907
         }
@@ -2114,8 +2087,7 @@  discard block
 block discarded – undo
2114 2087
      *
2115 2088
      * @return int
2116 2089
      */
2117
-    public function findStartOfStatement($start, $ignore=null)
2118
-    {
2090
+    public function findStartOfStatement($start, $ignore=null) {
2119 2091
         $endTokens = Util\Tokens::$blockOpeners;
2120 2092
 
2121 2093
         $endTokens[T_COLON]            = true;
@@ -2177,8 +2149,7 @@  discard block
 block discarded – undo
2177 2149
      *
2178 2150
      * @return int
2179 2151
      */
2180
-    public function findEndOfStatement($start, $ignore=null)
2181
-    {
2152
+    public function findEndOfStatement($start, $ignore=null) {
2182 2153
         $endTokens = [
2183 2154
             T_COLON                => true,
2184 2155
             T_COMMA                => true,
@@ -2264,8 +2235,7 @@  discard block
 block discarded – undo
2264 2235
      *
2265 2236
      * @return int | bool
2266 2237
      */
2267
-    public function findFirstOnLine($types, $start, $exclude=false, $value=null)
2268
-    {
2238
+    public function findFirstOnLine($types, $start, $exclude=false, $value=null) {
2269 2239
         if (is_array($types) === false) {
2270 2240
             $types = [$types];
2271 2241
         }
@@ -2314,8 +2284,7 @@  discard block
 block discarded – undo
2314 2284
      *
2315 2285
      * @return boolean
2316 2286
      */
2317
-    public function hasCondition($stackPtr, $types)
2318
-    {
2287
+    public function hasCondition($stackPtr, $types) {
2319 2288
         // Check for the existence of the token.
2320 2289
         if (isset($this->tokens[$stackPtr]) === false) {
2321 2290
             return false;
@@ -2351,8 +2320,7 @@  discard block
 block discarded – undo
2351 2320
      *
2352 2321
      * @return int
2353 2322
      */
2354
-    public function getCondition($stackPtr, $type)
2355
-    {
2323
+    public function getCondition($stackPtr, $type) {
2356 2324
         // Check for the existence of the token.
2357 2325
         if (isset($this->tokens[$stackPtr]) === false) {
2358 2326
             return false;
@@ -2385,8 +2353,7 @@  discard block
 block discarded – undo
2385 2353
      *
2386 2354
      * @return string|false
2387 2355
      */
2388
-    public function findExtendedClassName($stackPtr)
2389
-    {
2356
+    public function findExtendedClassName($stackPtr) {
2390 2357
         // Check for the existence of the token.
2391 2358
         if (isset($this->tokens[$stackPtr]) === false) {
2392 2359
             return false;
@@ -2437,8 +2404,7 @@  discard block
 block discarded – undo
2437 2404
      *
2438 2405
      * @return array|false
2439 2406
      */
2440
-    public function findImplementedInterfaceNames($stackPtr)
2441
-    {
2407
+    public function findImplementedInterfaceNames($stackPtr) {
2442 2408
         // Check for the existence of the token.
2443 2409
         if (isset($this->tokens[$stackPtr]) === false) {
2444 2410
             return false;
Please login to merge, or discard this patch.