Completed
Pull Request — develop (#1492)
by Zack
17:43
created
src/Standards/Generic/Sniffs/Formatting/SpaceAfterNotSniff.php 3 patches
Indentation   +114 added lines, -114 removed lines patch added patch discarded remove patch
@@ -16,120 +16,120 @@
 block discarded – undo
16 16
 class SpaceAfterNotSniff implements Sniff
17 17
 {
18 18
 
19
-    /**
20
-     * A list of tokenizers this sniff supports.
21
-     *
22
-     * @var array
23
-     */
24
-    public $supportedTokenizers = [
25
-        'PHP',
26
-        'JS',
27
-    ];
28
-
29
-    /**
30
-     * The number of spaces desired after the NOT operator.
31
-     *
32
-     * @var integer
33
-     */
34
-    public $spacing = 1;
35
-
36
-    /**
37
-     * Allow newlines instead of spaces.
38
-     *
39
-     * @var boolean
40
-     */
41
-    public $ignoreNewlines = false;
42
-
43
-
44
-    /**
45
-     * Returns an array of tokens this test wants to listen for.
46
-     *
47
-     * @return array
48
-     */
49
-    public function register()
50
-    {
51
-        return [T_BOOLEAN_NOT];
52
-
53
-    }//end register()
54
-
55
-
56
-    /**
57
-     * Processes this test, when one of its tokens is encountered.
58
-     *
59
-     * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.
60
-     * @param int                         $stackPtr  The position of the current token in
61
-     *                                               the stack passed in $tokens.
62
-     *
63
-     * @return void
64
-     */
65
-    public function process(File $phpcsFile, $stackPtr)
66
-    {
67
-        $tokens        = $phpcsFile->getTokens();
68
-        $this->spacing = (int) $this->spacing;
69
-
70
-        $nextNonEmpty = $phpcsFile->findNext(Tokens::$emptyTokens, ($stackPtr + 1), null, true);
71
-        if ($nextNonEmpty === false) {
72
-            return;
73
-        }
74
-
75
-        if ($this->ignoreNewlines === true
76
-            && $tokens[$stackPtr]['line'] !== $tokens[$nextNonEmpty]['line']
77
-        ) {
78
-            return;
79
-        }
80
-
81
-        if ($this->spacing === 0 && $nextNonEmpty === ($stackPtr + 1)) {
82
-            return;
83
-        }
84
-
85
-        $nextNonWhitespace = $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 1), null, true);
86
-        if ($nextNonEmpty !== $nextNonWhitespace) {
87
-            $error = 'Expected %s space(s) after NOT operator; comment found';
88
-            $data  = [$this->spacing];
89
-            $phpcsFile->addError($error, $stackPtr, 'CommentFound', $data);
90
-            return;
91
-        }
92
-
93
-        $found = 0;
94
-        if ($tokens[$stackPtr]['line'] !== $tokens[$nextNonEmpty]['line']) {
95
-            $found = 'newline';
96
-        } else if ($tokens[($stackPtr + 1)]['code'] === T_WHITESPACE) {
97
-            $found = $tokens[($stackPtr + 1)]['length'];
98
-        }
99
-
100
-        if ($found === $this->spacing) {
101
-            return;
102
-        }
103
-
104
-        $error = 'Expected %s space(s) after NOT operator; %s found';
105
-        $data  = [
106
-            $this->spacing,
107
-            $found,
108
-        ];
109
-
110
-        $fix = $phpcsFile->addFixableError($error, $stackPtr, 'Incorrect', $data);
111
-        if ($fix === true) {
112
-            $padding = str_repeat(' ', $this->spacing);
113
-            if ($found === 0) {
114
-                $phpcsFile->fixer->addContent($stackPtr, $padding);
115
-            } else {
116
-                $phpcsFile->fixer->beginChangeset();
117
-                $start = ($stackPtr + 1);
118
-
119
-                if ($this->spacing > 0) {
120
-                    $phpcsFile->fixer->replaceToken($start, $padding);
121
-                    ++$start;
122
-                }
123
-
124
-                for ($i = $start; $i < $nextNonWhitespace; $i++) {
125
-                    $phpcsFile->fixer->replaceToken($i, '');
126
-                }
127
-
128
-                $phpcsFile->fixer->endChangeset();
129
-            }
130
-        }
131
-
132
-    }//end process()
19
+	/**
20
+	 * A list of tokenizers this sniff supports.
21
+	 *
22
+	 * @var array
23
+	 */
24
+	public $supportedTokenizers = [
25
+		'PHP',
26
+		'JS',
27
+	];
28
+
29
+	/**
30
+	 * The number of spaces desired after the NOT operator.
31
+	 *
32
+	 * @var integer
33
+	 */
34
+	public $spacing = 1;
35
+
36
+	/**
37
+	 * Allow newlines instead of spaces.
38
+	 *
39
+	 * @var boolean
40
+	 */
41
+	public $ignoreNewlines = false;
42
+
43
+
44
+	/**
45
+	 * Returns an array of tokens this test wants to listen for.
46
+	 *
47
+	 * @return array
48
+	 */
49
+	public function register()
50
+	{
51
+		return [T_BOOLEAN_NOT];
52
+
53
+	}//end register()
54
+
55
+
56
+	/**
57
+	 * Processes this test, when one of its tokens is encountered.
58
+	 *
59
+	 * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.
60
+	 * @param int                         $stackPtr  The position of the current token in
61
+	 *                                               the stack passed in $tokens.
62
+	 *
63
+	 * @return void
64
+	 */
65
+	public function process(File $phpcsFile, $stackPtr)
66
+	{
67
+		$tokens        = $phpcsFile->getTokens();
68
+		$this->spacing = (int) $this->spacing;
69
+
70
+		$nextNonEmpty = $phpcsFile->findNext(Tokens::$emptyTokens, ($stackPtr + 1), null, true);
71
+		if ($nextNonEmpty === false) {
72
+			return;
73
+		}
74
+
75
+		if ($this->ignoreNewlines === true
76
+			&& $tokens[$stackPtr]['line'] !== $tokens[$nextNonEmpty]['line']
77
+		) {
78
+			return;
79
+		}
80
+
81
+		if ($this->spacing === 0 && $nextNonEmpty === ($stackPtr + 1)) {
82
+			return;
83
+		}
84
+
85
+		$nextNonWhitespace = $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 1), null, true);
86
+		if ($nextNonEmpty !== $nextNonWhitespace) {
87
+			$error = 'Expected %s space(s) after NOT operator; comment found';
88
+			$data  = [$this->spacing];
89
+			$phpcsFile->addError($error, $stackPtr, 'CommentFound', $data);
90
+			return;
91
+		}
92
+
93
+		$found = 0;
94
+		if ($tokens[$stackPtr]['line'] !== $tokens[$nextNonEmpty]['line']) {
95
+			$found = 'newline';
96
+		} else if ($tokens[($stackPtr + 1)]['code'] === T_WHITESPACE) {
97
+			$found = $tokens[($stackPtr + 1)]['length'];
98
+		}
99
+
100
+		if ($found === $this->spacing) {
101
+			return;
102
+		}
103
+
104
+		$error = 'Expected %s space(s) after NOT operator; %s found';
105
+		$data  = [
106
+			$this->spacing,
107
+			$found,
108
+		];
109
+
110
+		$fix = $phpcsFile->addFixableError($error, $stackPtr, 'Incorrect', $data);
111
+		if ($fix === true) {
112
+			$padding = str_repeat(' ', $this->spacing);
113
+			if ($found === 0) {
114
+				$phpcsFile->fixer->addContent($stackPtr, $padding);
115
+			} else {
116
+				$phpcsFile->fixer->beginChangeset();
117
+				$start = ($stackPtr + 1);
118
+
119
+				if ($this->spacing > 0) {
120
+					$phpcsFile->fixer->replaceToken($start, $padding);
121
+					++$start;
122
+				}
123
+
124
+				for ($i = $start; $i < $nextNonWhitespace; $i++) {
125
+					$phpcsFile->fixer->replaceToken($i, '');
126
+				}
127
+
128
+				$phpcsFile->fixer->endChangeset();
129
+			}
130
+		}
131
+
132
+	}//end process()
133 133
 
134 134
 
135 135
 }//end class
Please login to merge, or discard this patch.
Spacing   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -48,7 +48,7 @@  discard block
 block discarded – undo
48 48
      */
49 49
     public function register()
50 50
     {
51
-        return [T_BOOLEAN_NOT];
51
+        return [ T_BOOLEAN_NOT ];
52 52
 
53 53
     }//end register()
54 54
 
@@ -62,42 +62,42 @@  discard block
 block discarded – undo
62 62
      *
63 63
      * @return void
64 64
      */
65
-    public function process(File $phpcsFile, $stackPtr)
65
+    public function process( File $phpcsFile, $stackPtr )
66 66
     {
67 67
         $tokens        = $phpcsFile->getTokens();
68
-        $this->spacing = (int) $this->spacing;
68
+        $this->spacing = (int)$this->spacing;
69 69
 
70
-        $nextNonEmpty = $phpcsFile->findNext(Tokens::$emptyTokens, ($stackPtr + 1), null, true);
71
-        if ($nextNonEmpty === false) {
70
+        $nextNonEmpty = $phpcsFile->findNext( Tokens::$emptyTokens, ( $stackPtr + 1 ), null, true );
71
+        if ( $nextNonEmpty === false ) {
72 72
             return;
73 73
         }
74 74
 
75
-        if ($this->ignoreNewlines === true
76
-            && $tokens[$stackPtr]['line'] !== $tokens[$nextNonEmpty]['line']
75
+        if ( $this->ignoreNewlines === true
76
+            && $tokens[ $stackPtr ][ 'line' ] !== $tokens[ $nextNonEmpty ][ 'line' ]
77 77
         ) {
78 78
             return;
79 79
         }
80 80
 
81
-        if ($this->spacing === 0 && $nextNonEmpty === ($stackPtr + 1)) {
81
+        if ( $this->spacing === 0 && $nextNonEmpty === ( $stackPtr + 1 ) ) {
82 82
             return;
83 83
         }
84 84
 
85
-        $nextNonWhitespace = $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 1), null, true);
86
-        if ($nextNonEmpty !== $nextNonWhitespace) {
85
+        $nextNonWhitespace = $phpcsFile->findNext( T_WHITESPACE, ( $stackPtr + 1 ), null, true );
86
+        if ( $nextNonEmpty !== $nextNonWhitespace ) {
87 87
             $error = 'Expected %s space(s) after NOT operator; comment found';
88
-            $data  = [$this->spacing];
89
-            $phpcsFile->addError($error, $stackPtr, 'CommentFound', $data);
88
+            $data  = [ $this->spacing ];
89
+            $phpcsFile->addError( $error, $stackPtr, 'CommentFound', $data );
90 90
             return;
91 91
         }
92 92
 
93 93
         $found = 0;
94
-        if ($tokens[$stackPtr]['line'] !== $tokens[$nextNonEmpty]['line']) {
94
+        if ( $tokens[ $stackPtr ][ 'line' ] !== $tokens[ $nextNonEmpty ][ 'line' ] ) {
95 95
             $found = 'newline';
96
-        } else if ($tokens[($stackPtr + 1)]['code'] === T_WHITESPACE) {
97
-            $found = $tokens[($stackPtr + 1)]['length'];
96
+        } else if ( $tokens[ ( $stackPtr + 1 ) ][ 'code' ] === T_WHITESPACE ) {
97
+            $found = $tokens[ ( $stackPtr + 1 ) ][ 'length' ];
98 98
         }
99 99
 
100
-        if ($found === $this->spacing) {
100
+        if ( $found === $this->spacing ) {
101 101
             return;
102 102
         }
103 103
 
@@ -107,22 +107,22 @@  discard block
 block discarded – undo
107 107
             $found,
108 108
         ];
109 109
 
110
-        $fix = $phpcsFile->addFixableError($error, $stackPtr, 'Incorrect', $data);
111
-        if ($fix === true) {
112
-            $padding = str_repeat(' ', $this->spacing);
113
-            if ($found === 0) {
114
-                $phpcsFile->fixer->addContent($stackPtr, $padding);
110
+        $fix = $phpcsFile->addFixableError( $error, $stackPtr, 'Incorrect', $data );
111
+        if ( $fix === true ) {
112
+            $padding = str_repeat( ' ', $this->spacing );
113
+            if ( $found === 0 ) {
114
+                $phpcsFile->fixer->addContent( $stackPtr, $padding );
115 115
             } else {
116 116
                 $phpcsFile->fixer->beginChangeset();
117
-                $start = ($stackPtr + 1);
117
+                $start = ( $stackPtr + 1 );
118 118
 
119
-                if ($this->spacing > 0) {
120
-                    $phpcsFile->fixer->replaceToken($start, $padding);
119
+                if ( $this->spacing > 0 ) {
120
+                    $phpcsFile->fixer->replaceToken( $start, $padding );
121 121
                     ++$start;
122 122
                 }
123 123
 
124
-                for ($i = $start; $i < $nextNonWhitespace; $i++) {
125
-                    $phpcsFile->fixer->replaceToken($i, '');
124
+                for ( $i = $start; $i < $nextNonWhitespace; $i++ ) {
125
+                    $phpcsFile->fixer->replaceToken( $i, '' );
126 126
                 }
127 127
 
128 128
                 $phpcsFile->fixer->endChangeset();
Please login to merge, or discard this patch.
Braces   +3 added lines, -6 removed lines patch added patch discarded remove patch
@@ -13,8 +13,7 @@  discard block
 block discarded – undo
13 13
 use PHP_CodeSniffer\Files\File;
14 14
 use PHP_CodeSniffer\Util\Tokens;
15 15
 
16
-class SpaceAfterNotSniff implements Sniff
17
-{
16
+class SpaceAfterNotSniff implements Sniff {
18 17
 
19 18
     /**
20 19
      * A list of tokenizers this sniff supports.
@@ -46,8 +45,7 @@  discard block
 block discarded – undo
46 45
      *
47 46
      * @return array
48 47
      */
49
-    public function register()
50
-    {
48
+    public function register() {
51 49
         return [T_BOOLEAN_NOT];
52 50
 
53 51
     }//end register()
@@ -62,8 +60,7 @@  discard block
 block discarded – undo
62 60
      *
63 61
      * @return void
64 62
      */
65
-    public function process(File $phpcsFile, $stackPtr)
66
-    {
63
+    public function process(File $phpcsFile, $stackPtr) {
67 64
         $tokens        = $phpcsFile->getTokens();
68 65
         $this->spacing = (int) $this->spacing;
69 66
 
Please login to merge, or discard this patch.
src/Standards/Generic/Sniffs/Formatting/SpaceBeforeCastSniff.php 3 patches
Indentation   +51 added lines, -51 removed lines patch added patch discarded remove patch
@@ -17,57 +17,57 @@
 block discarded – undo
17 17
 {
18 18
 
19 19
 
20
-    /**
21
-     * Returns an array of tokens this test wants to listen for.
22
-     *
23
-     * @return array
24
-     */
25
-    public function register()
26
-    {
27
-        return Tokens::$castTokens;
28
-
29
-    }//end register()
30
-
31
-
32
-    /**
33
-     * Processes this test, when one of its tokens is encountered.
34
-     *
35
-     * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.
36
-     * @param int                         $stackPtr  The position of the current token in
37
-     *                                               the stack passed in $tokens.
38
-     *
39
-     * @return void
40
-     */
41
-    public function process(File $phpcsFile, $stackPtr)
42
-    {
43
-        $tokens = $phpcsFile->getTokens();
44
-
45
-        if ($tokens[$stackPtr]['column'] === 1) {
46
-            return;
47
-        }
48
-
49
-        if ($tokens[($stackPtr - 1)]['code'] !== T_WHITESPACE) {
50
-            $error = 'A cast statement must be preceded by a single space';
51
-            $fix   = $phpcsFile->addFixableError($error, $stackPtr, 'NoSpace');
52
-            if ($fix === true) {
53
-                $phpcsFile->fixer->addContentBefore($stackPtr, ' ');
54
-            }
55
-
56
-            $phpcsFile->recordMetric($stackPtr, 'Spacing before cast statement', 0);
57
-            return;
58
-        }
59
-
60
-        $phpcsFile->recordMetric($stackPtr, 'Spacing before cast statement', $tokens[($stackPtr - 1)]['length']);
61
-
62
-        if ($tokens[($stackPtr - 1)]['column'] !== 1 && $tokens[($stackPtr - 1)]['length'] !== 1) {
63
-            $error = 'A cast statement must be preceded by a single space';
64
-            $fix   = $phpcsFile->addFixableError($error, $stackPtr, 'TooMuchSpace');
65
-            if ($fix === true) {
66
-                $phpcsFile->fixer->replaceToken(($stackPtr - 1), ' ');
67
-            }
68
-        }
69
-
70
-    }//end process()
20
+	/**
21
+	 * Returns an array of tokens this test wants to listen for.
22
+	 *
23
+	 * @return array
24
+	 */
25
+	public function register()
26
+	{
27
+		return Tokens::$castTokens;
28
+
29
+	}//end register()
30
+
31
+
32
+	/**
33
+	 * Processes this test, when one of its tokens is encountered.
34
+	 *
35
+	 * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.
36
+	 * @param int                         $stackPtr  The position of the current token in
37
+	 *                                               the stack passed in $tokens.
38
+	 *
39
+	 * @return void
40
+	 */
41
+	public function process(File $phpcsFile, $stackPtr)
42
+	{
43
+		$tokens = $phpcsFile->getTokens();
44
+
45
+		if ($tokens[$stackPtr]['column'] === 1) {
46
+			return;
47
+		}
48
+
49
+		if ($tokens[($stackPtr - 1)]['code'] !== T_WHITESPACE) {
50
+			$error = 'A cast statement must be preceded by a single space';
51
+			$fix   = $phpcsFile->addFixableError($error, $stackPtr, 'NoSpace');
52
+			if ($fix === true) {
53
+				$phpcsFile->fixer->addContentBefore($stackPtr, ' ');
54
+			}
55
+
56
+			$phpcsFile->recordMetric($stackPtr, 'Spacing before cast statement', 0);
57
+			return;
58
+		}
59
+
60
+		$phpcsFile->recordMetric($stackPtr, 'Spacing before cast statement', $tokens[($stackPtr - 1)]['length']);
61
+
62
+		if ($tokens[($stackPtr - 1)]['column'] !== 1 && $tokens[($stackPtr - 1)]['length'] !== 1) {
63
+			$error = 'A cast statement must be preceded by a single space';
64
+			$fix   = $phpcsFile->addFixableError($error, $stackPtr, 'TooMuchSpace');
65
+			if ($fix === true) {
66
+				$phpcsFile->fixer->replaceToken(($stackPtr - 1), ' ');
67
+			}
68
+		}
69
+
70
+	}//end process()
71 71
 
72 72
 
73 73
 }//end class
Please login to merge, or discard this patch.
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -38,32 +38,32 @@
 block discarded – undo
38 38
      *
39 39
      * @return void
40 40
      */
41
-    public function process(File $phpcsFile, $stackPtr)
41
+    public function process( File $phpcsFile, $stackPtr )
42 42
     {
43 43
         $tokens = $phpcsFile->getTokens();
44 44
 
45
-        if ($tokens[$stackPtr]['column'] === 1) {
45
+        if ( $tokens[ $stackPtr ][ 'column' ] === 1 ) {
46 46
             return;
47 47
         }
48 48
 
49
-        if ($tokens[($stackPtr - 1)]['code'] !== T_WHITESPACE) {
49
+        if ( $tokens[ ( $stackPtr - 1 ) ][ 'code' ] !== T_WHITESPACE ) {
50 50
             $error = 'A cast statement must be preceded by a single space';
51
-            $fix   = $phpcsFile->addFixableError($error, $stackPtr, 'NoSpace');
52
-            if ($fix === true) {
53
-                $phpcsFile->fixer->addContentBefore($stackPtr, ' ');
51
+            $fix   = $phpcsFile->addFixableError( $error, $stackPtr, 'NoSpace' );
52
+            if ( $fix === true ) {
53
+                $phpcsFile->fixer->addContentBefore( $stackPtr, ' ' );
54 54
             }
55 55
 
56
-            $phpcsFile->recordMetric($stackPtr, 'Spacing before cast statement', 0);
56
+            $phpcsFile->recordMetric( $stackPtr, 'Spacing before cast statement', 0 );
57 57
             return;
58 58
         }
59 59
 
60
-        $phpcsFile->recordMetric($stackPtr, 'Spacing before cast statement', $tokens[($stackPtr - 1)]['length']);
60
+        $phpcsFile->recordMetric( $stackPtr, 'Spacing before cast statement', $tokens[ ( $stackPtr - 1 ) ][ 'length' ] );
61 61
 
62
-        if ($tokens[($stackPtr - 1)]['column'] !== 1 && $tokens[($stackPtr - 1)]['length'] !== 1) {
62
+        if ( $tokens[ ( $stackPtr - 1 ) ][ 'column' ] !== 1 && $tokens[ ( $stackPtr - 1 ) ][ 'length' ] !== 1 ) {
63 63
             $error = 'A cast statement must be preceded by a single space';
64
-            $fix   = $phpcsFile->addFixableError($error, $stackPtr, 'TooMuchSpace');
65
-            if ($fix === true) {
66
-                $phpcsFile->fixer->replaceToken(($stackPtr - 1), ' ');
64
+            $fix   = $phpcsFile->addFixableError( $error, $stackPtr, 'TooMuchSpace' );
65
+            if ( $fix === true ) {
66
+                $phpcsFile->fixer->replaceToken( ( $stackPtr - 1 ), ' ' );
67 67
             }
68 68
         }
69 69
 
Please login to merge, or discard this patch.
Braces   +3 added lines, -6 removed lines patch added patch discarded remove patch
@@ -13,8 +13,7 @@  discard block
 block discarded – undo
13 13
 use PHP_CodeSniffer\Files\File;
14 14
 use PHP_CodeSniffer\Util\Tokens;
15 15
 
16
-class SpaceBeforeCastSniff implements Sniff
17
-{
16
+class SpaceBeforeCastSniff implements Sniff {
18 17
 
19 18
 
20 19
     /**
@@ -22,8 +21,7 @@  discard block
 block discarded – undo
22 21
      *
23 22
      * @return array
24 23
      */
25
-    public function register()
26
-    {
24
+    public function register() {
27 25
         return Tokens::$castTokens;
28 26
 
29 27
     }//end register()
@@ -38,8 +36,7 @@  discard block
 block discarded – undo
38 36
      *
39 37
      * @return void
40 38
      */
41
-    public function process(File $phpcsFile, $stackPtr)
42
-    {
39
+    public function process(File $phpcsFile, $stackPtr) {
43 40
         $tokens = $phpcsFile->getTokens();
44 41
 
45 42
         if ($tokens[$stackPtr]['column'] === 1) {
Please login to merge, or discard this patch.
src/Standards/Generic/Sniffs/Formatting/MultipleStatementAlignmentSniff.php 3 patches
Indentation   +363 added lines, -363 removed lines patch added patch discarded remove patch
@@ -19,369 +19,369 @@
 block discarded – undo
19 19
 class MultipleStatementAlignmentSniff implements Sniff
20 20
 {
21 21
 
22
-    /**
23
-     * A list of tokenizers this sniff supports.
24
-     *
25
-     * @var array
26
-     */
27
-    public $supportedTokenizers = [
28
-        'PHP',
29
-        'JS',
30
-    ];
31
-
32
-    /**
33
-     * If true, an error will be thrown; otherwise a warning.
34
-     *
35
-     * @var boolean
36
-     */
37
-    public $error = false;
38
-
39
-    /**
40
-     * The maximum amount of padding before the alignment is ignored.
41
-     *
42
-     * If the amount of padding required to align this assignment with the
43
-     * surrounding assignments exceeds this number, the assignment will be
44
-     * ignored and no errors or warnings will be thrown.
45
-     *
46
-     * @var integer
47
-     */
48
-    public $maxPadding = 1000;
49
-
50
-
51
-    /**
52
-     * Returns an array of tokens this test wants to listen for.
53
-     *
54
-     * @return array
55
-     */
56
-    public function register()
57
-    {
58
-        $tokens = Tokens::$assignmentTokens;
59
-        unset($tokens[T_DOUBLE_ARROW]);
60
-        return $tokens;
61
-
62
-    }//end register()
63
-
64
-
65
-    /**
66
-     * Processes this test, when one of its tokens is encountered.
67
-     *
68
-     * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.
69
-     * @param int                         $stackPtr  The position of the current token
70
-     *                                               in the stack passed in $tokens.
71
-     *
72
-     * @return int
73
-     */
74
-    public function process(File $phpcsFile, $stackPtr)
75
-    {
76
-        $tokens = $phpcsFile->getTokens();
77
-
78
-        // Ignore assignments used in a condition, like an IF or FOR.
79
-        if (isset($tokens[$stackPtr]['nested_parenthesis']) === true) {
80
-            foreach ($tokens[$stackPtr]['nested_parenthesis'] as $start => $end) {
81
-                if (isset($tokens[$start]['parenthesis_owner']) === true) {
82
-                    return;
83
-                }
84
-            }
85
-        }
86
-
87
-        $lastAssign = $this->checkAlignment($phpcsFile, $stackPtr);
88
-        return ($lastAssign + 1);
89
-
90
-    }//end process()
91
-
92
-
93
-    /**
94
-     * Processes this test, when one of its tokens is encountered.
95
-     *
96
-     * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.
97
-     * @param int                         $stackPtr  The position of the current token
98
-     *                                               in the stack passed in $tokens.
99
-     * @param int                         $end       The token where checking should end.
100
-     *                                               If NULL, the entire file will be checked.
101
-     *
102
-     * @return int
103
-     */
104
-    public function checkAlignment($phpcsFile, $stackPtr, $end=null)
105
-    {
106
-        $tokens = $phpcsFile->getTokens();
107
-
108
-        $assignments = [];
109
-        $prevAssign  = null;
110
-        $lastLine    = $tokens[$stackPtr]['line'];
111
-        $maxPadding  = null;
112
-        $stopped     = null;
113
-        $lastCode    = $stackPtr;
114
-        $lastSemi    = null;
115
-        $arrayEnd    = null;
116
-
117
-        if ($end === null) {
118
-            $end = $phpcsFile->numTokens;
119
-        }
120
-
121
-        $find = Tokens::$assignmentTokens;
122
-        unset($find[T_DOUBLE_ARROW]);
123
-
124
-        $scopes = Tokens::$scopeOpeners;
125
-        unset($scopes[T_CLOSURE]);
126
-        unset($scopes[T_ANON_CLASS]);
127
-        unset($scopes[T_OBJECT]);
128
-
129
-        for ($assign = $stackPtr; $assign < $end; $assign++) {
130
-            if ($tokens[$assign]['level'] < $tokens[$stackPtr]['level']) {
131
-                // Statement is in a different context, so the block is over.
132
-                break;
133
-            }
134
-
135
-            if (isset($scopes[$tokens[$assign]['code']]) === true
136
-                && isset($tokens[$assign]['scope_opener']) === true
137
-                && $tokens[$assign]['level'] === $tokens[$stackPtr]['level']
138
-            ) {
139
-                break;
140
-            }
141
-
142
-            if ($assign === $arrayEnd) {
143
-                $arrayEnd = null;
144
-            }
145
-
146
-            if (isset($find[$tokens[$assign]['code']]) === false) {
147
-                // A blank line indicates that the assignment block has ended.
148
-                if (isset(Tokens::$emptyTokens[$tokens[$assign]['code']]) === false
149
-                    && ($tokens[$assign]['line'] - $tokens[$lastCode]['line']) > 1
150
-                    && $tokens[$assign]['level'] === $tokens[$stackPtr]['level']
151
-                    && $arrayEnd === null
152
-                ) {
153
-                    break;
154
-                }
155
-
156
-                if ($tokens[$assign]['code'] === T_CLOSE_TAG) {
157
-                    // Breaking out of PHP ends the assignment block.
158
-                    break;
159
-                }
160
-
161
-                if ($tokens[$assign]['code'] === T_OPEN_SHORT_ARRAY
162
-                    && isset($tokens[$assign]['bracket_closer']) === true
163
-                ) {
164
-                    $arrayEnd = $tokens[$assign]['bracket_closer'];
165
-                }
166
-
167
-                if ($tokens[$assign]['code'] === T_ARRAY
168
-                    && isset($tokens[$assign]['parenthesis_opener']) === true
169
-                    && isset($tokens[$tokens[$assign]['parenthesis_opener']]['parenthesis_closer']) === true
170
-                ) {
171
-                    $arrayEnd = $tokens[$tokens[$assign]['parenthesis_opener']]['parenthesis_closer'];
172
-                }
173
-
174
-                if (isset(Tokens::$emptyTokens[$tokens[$assign]['code']]) === false) {
175
-                    $lastCode = $assign;
176
-
177
-                    if ($tokens[$assign]['code'] === T_SEMICOLON) {
178
-                        if ($tokens[$assign]['conditions'] === $tokens[$stackPtr]['conditions']) {
179
-                            if ($lastSemi !== null && $prevAssign !== null && $lastSemi > $prevAssign) {
180
-                                // This statement did not have an assignment operator in it.
181
-                                break;
182
-                            } else {
183
-                                $lastSemi = $assign;
184
-                            }
185
-                        } else if ($tokens[$assign]['level'] < $tokens[$stackPtr]['level']) {
186
-                            // Statement is in a different context, so the block is over.
187
-                            break;
188
-                        }
189
-                    }
190
-                }//end if
191
-
192
-                continue;
193
-            } else if ($assign !== $stackPtr && $tokens[$assign]['line'] === $lastLine) {
194
-                // Skip multiple assignments on the same line. We only need to
195
-                // try and align the first assignment.
196
-                continue;
197
-            }//end if
198
-
199
-            if ($assign !== $stackPtr) {
200
-                if ($tokens[$assign]['level'] > $tokens[$stackPtr]['level']) {
201
-                    // Has to be nested inside the same conditions as the first assignment.
202
-                    // We've gone one level down, so process this new block.
203
-                    $assign   = $this->checkAlignment($phpcsFile, $assign);
204
-                    $lastCode = $assign;
205
-                    continue;
206
-                } else if ($tokens[$assign]['level'] < $tokens[$stackPtr]['level']) {
207
-                    // We've gone one level up, so the block we are processing is done.
208
-                    break;
209
-                } else if ($arrayEnd !== null) {
210
-                    // Assignments inside arrays are not part of
211
-                    // the original block, so process this new block.
212
-                    $assign   = ($this->checkAlignment($phpcsFile, $assign, $arrayEnd) - 1);
213
-                    $arrayEnd = null;
214
-                    $lastCode = $assign;
215
-                    continue;
216
-                }
217
-
218
-                // Make sure it is not assigned inside a condition (eg. IF, FOR).
219
-                if (isset($tokens[$assign]['nested_parenthesis']) === true) {
220
-                    foreach ($tokens[$assign]['nested_parenthesis'] as $start => $end) {
221
-                        if (isset($tokens[$start]['parenthesis_owner']) === true) {
222
-                            break(2);
223
-                        }
224
-                    }
225
-                }
226
-            }//end if
227
-
228
-            $var = $phpcsFile->findPrevious(
229
-                Tokens::$emptyTokens,
230
-                ($assign - 1),
231
-                null,
232
-                true
233
-            );
234
-
235
-            // Make sure we wouldn't break our max padding length if we
236
-            // aligned with this statement, or they wouldn't break the max
237
-            // padding length if they aligned with us.
238
-            $varEnd    = $tokens[($var + 1)]['column'];
239
-            $assignLen = $tokens[$assign]['length'];
240
-            if ($assign !== $stackPtr) {
241
-                if ($prevAssign === null) {
242
-                    // Processing an inner block but no assignments found.
243
-                    break;
244
-                }
245
-
246
-                if (($varEnd + 1) > $assignments[$prevAssign]['assign_col']) {
247
-                    $padding      = 1;
248
-                    $assignColumn = ($varEnd + 1);
249
-                } else {
250
-                    $padding = ($assignments[$prevAssign]['assign_col'] - $varEnd + $assignments[$prevAssign]['assign_len'] - $assignLen);
251
-                    if ($padding <= 0) {
252
-                        $padding = 1;
253
-                    }
254
-
255
-                    if ($padding > $this->maxPadding) {
256
-                        $stopped = $assign;
257
-                        break;
258
-                    }
259
-
260
-                    $assignColumn = ($varEnd + $padding);
261
-                }//end if
262
-
263
-                if (($assignColumn + $assignLen) > ($assignments[$maxPadding]['assign_col'] + $assignments[$maxPadding]['assign_len'])) {
264
-                    $newPadding = ($varEnd - $assignments[$maxPadding]['var_end'] + $assignLen - $assignments[$maxPadding]['assign_len'] + 1);
265
-                    if ($newPadding > $this->maxPadding) {
266
-                        $stopped = $assign;
267
-                        break;
268
-                    } else {
269
-                        // New alignment settings for previous assignments.
270
-                        foreach ($assignments as $i => $data) {
271
-                            if ($i === $assign) {
272
-                                break;
273
-                            }
274
-
275
-                            $newPadding = ($varEnd - $data['var_end'] + $assignLen - $data['assign_len'] + 1);
276
-                            $assignments[$i]['expected']   = $newPadding;
277
-                            $assignments[$i]['assign_col'] = ($data['var_end'] + $newPadding);
278
-                        }
279
-
280
-                        $padding      = 1;
281
-                        $assignColumn = ($varEnd + 1);
282
-                    }
283
-                } else if ($padding > $assignments[$maxPadding]['expected']) {
284
-                    $maxPadding = $assign;
285
-                }//end if
286
-            } else {
287
-                $padding      = 1;
288
-                $assignColumn = ($varEnd + 1);
289
-                $maxPadding   = $assign;
290
-            }//end if
291
-
292
-            $found = 0;
293
-            if ($tokens[($var + 1)]['code'] === T_WHITESPACE) {
294
-                $found = $tokens[($var + 1)]['length'];
295
-                if ($found === 0) {
296
-                    // This means a newline was found.
297
-                    $found = 1;
298
-                }
299
-            }
300
-
301
-            $assignments[$assign] = [
302
-                'var_end'    => $varEnd,
303
-                'assign_len' => $assignLen,
304
-                'assign_col' => $assignColumn,
305
-                'expected'   => $padding,
306
-                'found'      => $found,
307
-            ];
308
-
309
-            $lastLine   = $tokens[$assign]['line'];
310
-            $prevAssign = $assign;
311
-        }//end for
312
-
313
-        if (empty($assignments) === true) {
314
-            return $stackPtr;
315
-        }
316
-
317
-        $numAssignments = count($assignments);
318
-
319
-        $errorGenerated = false;
320
-        foreach ($assignments as $assignment => $data) {
321
-            if ($data['found'] === $data['expected']) {
322
-                continue;
323
-            }
324
-
325
-            $expectedText = $data['expected'].' space';
326
-            if ($data['expected'] !== 1) {
327
-                $expectedText .= 's';
328
-            }
329
-
330
-            if ($data['found'] === null) {
331
-                $foundText = 'a new line';
332
-            } else {
333
-                $foundText = $data['found'].' space';
334
-                if ($data['found'] !== 1) {
335
-                    $foundText .= 's';
336
-                }
337
-            }
338
-
339
-            if ($numAssignments === 1) {
340
-                $type  = 'Incorrect';
341
-                $error = 'Equals sign not aligned correctly; expected %s but found %s';
342
-            } else {
343
-                $type  = 'NotSame';
344
-                $error = 'Equals sign not aligned with surrounding assignments; expected %s but found %s';
345
-            }
346
-
347
-            $errorData = [
348
-                $expectedText,
349
-                $foundText,
350
-            ];
351
-
352
-            if ($this->error === true) {
353
-                $fix = $phpcsFile->addFixableError($error, $assignment, $type, $errorData);
354
-            } else {
355
-                $fix = $phpcsFile->addFixableWarning($error, $assignment, $type.'Warning', $errorData);
356
-            }
357
-
358
-            $errorGenerated = true;
359
-
360
-            if ($fix === true && $data['found'] !== null) {
361
-                $newContent = str_repeat(' ', $data['expected']);
362
-                if ($data['found'] === 0) {
363
-                    $phpcsFile->fixer->addContentBefore($assignment, $newContent);
364
-                } else {
365
-                    $phpcsFile->fixer->replaceToken(($assignment - 1), $newContent);
366
-                }
367
-            }
368
-        }//end foreach
369
-
370
-        if ($numAssignments > 1) {
371
-            if ($errorGenerated === true) {
372
-                $phpcsFile->recordMetric($stackPtr, 'Adjacent assignments aligned', 'no');
373
-            } else {
374
-                $phpcsFile->recordMetric($stackPtr, 'Adjacent assignments aligned', 'yes');
375
-            }
376
-        }
377
-
378
-        if ($stopped !== null) {
379
-            return $this->checkAlignment($phpcsFile, $stopped);
380
-        } else {
381
-            return $assign;
382
-        }
383
-
384
-    }//end checkAlignment()
22
+	/**
23
+	 * A list of tokenizers this sniff supports.
24
+	 *
25
+	 * @var array
26
+	 */
27
+	public $supportedTokenizers = [
28
+		'PHP',
29
+		'JS',
30
+	];
31
+
32
+	/**
33
+	 * If true, an error will be thrown; otherwise a warning.
34
+	 *
35
+	 * @var boolean
36
+	 */
37
+	public $error = false;
38
+
39
+	/**
40
+	 * The maximum amount of padding before the alignment is ignored.
41
+	 *
42
+	 * If the amount of padding required to align this assignment with the
43
+	 * surrounding assignments exceeds this number, the assignment will be
44
+	 * ignored and no errors or warnings will be thrown.
45
+	 *
46
+	 * @var integer
47
+	 */
48
+	public $maxPadding = 1000;
49
+
50
+
51
+	/**
52
+	 * Returns an array of tokens this test wants to listen for.
53
+	 *
54
+	 * @return array
55
+	 */
56
+	public function register()
57
+	{
58
+		$tokens = Tokens::$assignmentTokens;
59
+		unset($tokens[T_DOUBLE_ARROW]);
60
+		return $tokens;
61
+
62
+	}//end register()
63
+
64
+
65
+	/**
66
+	 * Processes this test, when one of its tokens is encountered.
67
+	 *
68
+	 * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.
69
+	 * @param int                         $stackPtr  The position of the current token
70
+	 *                                               in the stack passed in $tokens.
71
+	 *
72
+	 * @return int
73
+	 */
74
+	public function process(File $phpcsFile, $stackPtr)
75
+	{
76
+		$tokens = $phpcsFile->getTokens();
77
+
78
+		// Ignore assignments used in a condition, like an IF or FOR.
79
+		if (isset($tokens[$stackPtr]['nested_parenthesis']) === true) {
80
+			foreach ($tokens[$stackPtr]['nested_parenthesis'] as $start => $end) {
81
+				if (isset($tokens[$start]['parenthesis_owner']) === true) {
82
+					return;
83
+				}
84
+			}
85
+		}
86
+
87
+		$lastAssign = $this->checkAlignment($phpcsFile, $stackPtr);
88
+		return ($lastAssign + 1);
89
+
90
+	}//end process()
91
+
92
+
93
+	/**
94
+	 * Processes this test, when one of its tokens is encountered.
95
+	 *
96
+	 * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.
97
+	 * @param int                         $stackPtr  The position of the current token
98
+	 *                                               in the stack passed in $tokens.
99
+	 * @param int                         $end       The token where checking should end.
100
+	 *                                               If NULL, the entire file will be checked.
101
+	 *
102
+	 * @return int
103
+	 */
104
+	public function checkAlignment($phpcsFile, $stackPtr, $end=null)
105
+	{
106
+		$tokens = $phpcsFile->getTokens();
107
+
108
+		$assignments = [];
109
+		$prevAssign  = null;
110
+		$lastLine    = $tokens[$stackPtr]['line'];
111
+		$maxPadding  = null;
112
+		$stopped     = null;
113
+		$lastCode    = $stackPtr;
114
+		$lastSemi    = null;
115
+		$arrayEnd    = null;
116
+
117
+		if ($end === null) {
118
+			$end = $phpcsFile->numTokens;
119
+		}
120
+
121
+		$find = Tokens::$assignmentTokens;
122
+		unset($find[T_DOUBLE_ARROW]);
123
+
124
+		$scopes = Tokens::$scopeOpeners;
125
+		unset($scopes[T_CLOSURE]);
126
+		unset($scopes[T_ANON_CLASS]);
127
+		unset($scopes[T_OBJECT]);
128
+
129
+		for ($assign = $stackPtr; $assign < $end; $assign++) {
130
+			if ($tokens[$assign]['level'] < $tokens[$stackPtr]['level']) {
131
+				// Statement is in a different context, so the block is over.
132
+				break;
133
+			}
134
+
135
+			if (isset($scopes[$tokens[$assign]['code']]) === true
136
+				&& isset($tokens[$assign]['scope_opener']) === true
137
+				&& $tokens[$assign]['level'] === $tokens[$stackPtr]['level']
138
+			) {
139
+				break;
140
+			}
141
+
142
+			if ($assign === $arrayEnd) {
143
+				$arrayEnd = null;
144
+			}
145
+
146
+			if (isset($find[$tokens[$assign]['code']]) === false) {
147
+				// A blank line indicates that the assignment block has ended.
148
+				if (isset(Tokens::$emptyTokens[$tokens[$assign]['code']]) === false
149
+					&& ($tokens[$assign]['line'] - $tokens[$lastCode]['line']) > 1
150
+					&& $tokens[$assign]['level'] === $tokens[$stackPtr]['level']
151
+					&& $arrayEnd === null
152
+				) {
153
+					break;
154
+				}
155
+
156
+				if ($tokens[$assign]['code'] === T_CLOSE_TAG) {
157
+					// Breaking out of PHP ends the assignment block.
158
+					break;
159
+				}
160
+
161
+				if ($tokens[$assign]['code'] === T_OPEN_SHORT_ARRAY
162
+					&& isset($tokens[$assign]['bracket_closer']) === true
163
+				) {
164
+					$arrayEnd = $tokens[$assign]['bracket_closer'];
165
+				}
166
+
167
+				if ($tokens[$assign]['code'] === T_ARRAY
168
+					&& isset($tokens[$assign]['parenthesis_opener']) === true
169
+					&& isset($tokens[$tokens[$assign]['parenthesis_opener']]['parenthesis_closer']) === true
170
+				) {
171
+					$arrayEnd = $tokens[$tokens[$assign]['parenthesis_opener']]['parenthesis_closer'];
172
+				}
173
+
174
+				if (isset(Tokens::$emptyTokens[$tokens[$assign]['code']]) === false) {
175
+					$lastCode = $assign;
176
+
177
+					if ($tokens[$assign]['code'] === T_SEMICOLON) {
178
+						if ($tokens[$assign]['conditions'] === $tokens[$stackPtr]['conditions']) {
179
+							if ($lastSemi !== null && $prevAssign !== null && $lastSemi > $prevAssign) {
180
+								// This statement did not have an assignment operator in it.
181
+								break;
182
+							} else {
183
+								$lastSemi = $assign;
184
+							}
185
+						} else if ($tokens[$assign]['level'] < $tokens[$stackPtr]['level']) {
186
+							// Statement is in a different context, so the block is over.
187
+							break;
188
+						}
189
+					}
190
+				}//end if
191
+
192
+				continue;
193
+			} else if ($assign !== $stackPtr && $tokens[$assign]['line'] === $lastLine) {
194
+				// Skip multiple assignments on the same line. We only need to
195
+				// try and align the first assignment.
196
+				continue;
197
+			}//end if
198
+
199
+			if ($assign !== $stackPtr) {
200
+				if ($tokens[$assign]['level'] > $tokens[$stackPtr]['level']) {
201
+					// Has to be nested inside the same conditions as the first assignment.
202
+					// We've gone one level down, so process this new block.
203
+					$assign   = $this->checkAlignment($phpcsFile, $assign);
204
+					$lastCode = $assign;
205
+					continue;
206
+				} else if ($tokens[$assign]['level'] < $tokens[$stackPtr]['level']) {
207
+					// We've gone one level up, so the block we are processing is done.
208
+					break;
209
+				} else if ($arrayEnd !== null) {
210
+					// Assignments inside arrays are not part of
211
+					// the original block, so process this new block.
212
+					$assign   = ($this->checkAlignment($phpcsFile, $assign, $arrayEnd) - 1);
213
+					$arrayEnd = null;
214
+					$lastCode = $assign;
215
+					continue;
216
+				}
217
+
218
+				// Make sure it is not assigned inside a condition (eg. IF, FOR).
219
+				if (isset($tokens[$assign]['nested_parenthesis']) === true) {
220
+					foreach ($tokens[$assign]['nested_parenthesis'] as $start => $end) {
221
+						if (isset($tokens[$start]['parenthesis_owner']) === true) {
222
+							break(2);
223
+						}
224
+					}
225
+				}
226
+			}//end if
227
+
228
+			$var = $phpcsFile->findPrevious(
229
+				Tokens::$emptyTokens,
230
+				($assign - 1),
231
+				null,
232
+				true
233
+			);
234
+
235
+			// Make sure we wouldn't break our max padding length if we
236
+			// aligned with this statement, or they wouldn't break the max
237
+			// padding length if they aligned with us.
238
+			$varEnd    = $tokens[($var + 1)]['column'];
239
+			$assignLen = $tokens[$assign]['length'];
240
+			if ($assign !== $stackPtr) {
241
+				if ($prevAssign === null) {
242
+					// Processing an inner block but no assignments found.
243
+					break;
244
+				}
245
+
246
+				if (($varEnd + 1) > $assignments[$prevAssign]['assign_col']) {
247
+					$padding      = 1;
248
+					$assignColumn = ($varEnd + 1);
249
+				} else {
250
+					$padding = ($assignments[$prevAssign]['assign_col'] - $varEnd + $assignments[$prevAssign]['assign_len'] - $assignLen);
251
+					if ($padding <= 0) {
252
+						$padding = 1;
253
+					}
254
+
255
+					if ($padding > $this->maxPadding) {
256
+						$stopped = $assign;
257
+						break;
258
+					}
259
+
260
+					$assignColumn = ($varEnd + $padding);
261
+				}//end if
262
+
263
+				if (($assignColumn + $assignLen) > ($assignments[$maxPadding]['assign_col'] + $assignments[$maxPadding]['assign_len'])) {
264
+					$newPadding = ($varEnd - $assignments[$maxPadding]['var_end'] + $assignLen - $assignments[$maxPadding]['assign_len'] + 1);
265
+					if ($newPadding > $this->maxPadding) {
266
+						$stopped = $assign;
267
+						break;
268
+					} else {
269
+						// New alignment settings for previous assignments.
270
+						foreach ($assignments as $i => $data) {
271
+							if ($i === $assign) {
272
+								break;
273
+							}
274
+
275
+							$newPadding = ($varEnd - $data['var_end'] + $assignLen - $data['assign_len'] + 1);
276
+							$assignments[$i]['expected']   = $newPadding;
277
+							$assignments[$i]['assign_col'] = ($data['var_end'] + $newPadding);
278
+						}
279
+
280
+						$padding      = 1;
281
+						$assignColumn = ($varEnd + 1);
282
+					}
283
+				} else if ($padding > $assignments[$maxPadding]['expected']) {
284
+					$maxPadding = $assign;
285
+				}//end if
286
+			} else {
287
+				$padding      = 1;
288
+				$assignColumn = ($varEnd + 1);
289
+				$maxPadding   = $assign;
290
+			}//end if
291
+
292
+			$found = 0;
293
+			if ($tokens[($var + 1)]['code'] === T_WHITESPACE) {
294
+				$found = $tokens[($var + 1)]['length'];
295
+				if ($found === 0) {
296
+					// This means a newline was found.
297
+					$found = 1;
298
+				}
299
+			}
300
+
301
+			$assignments[$assign] = [
302
+				'var_end'    => $varEnd,
303
+				'assign_len' => $assignLen,
304
+				'assign_col' => $assignColumn,
305
+				'expected'   => $padding,
306
+				'found'      => $found,
307
+			];
308
+
309
+			$lastLine   = $tokens[$assign]['line'];
310
+			$prevAssign = $assign;
311
+		}//end for
312
+
313
+		if (empty($assignments) === true) {
314
+			return $stackPtr;
315
+		}
316
+
317
+		$numAssignments = count($assignments);
318
+
319
+		$errorGenerated = false;
320
+		foreach ($assignments as $assignment => $data) {
321
+			if ($data['found'] === $data['expected']) {
322
+				continue;
323
+			}
324
+
325
+			$expectedText = $data['expected'].' space';
326
+			if ($data['expected'] !== 1) {
327
+				$expectedText .= 's';
328
+			}
329
+
330
+			if ($data['found'] === null) {
331
+				$foundText = 'a new line';
332
+			} else {
333
+				$foundText = $data['found'].' space';
334
+				if ($data['found'] !== 1) {
335
+					$foundText .= 's';
336
+				}
337
+			}
338
+
339
+			if ($numAssignments === 1) {
340
+				$type  = 'Incorrect';
341
+				$error = 'Equals sign not aligned correctly; expected %s but found %s';
342
+			} else {
343
+				$type  = 'NotSame';
344
+				$error = 'Equals sign not aligned with surrounding assignments; expected %s but found %s';
345
+			}
346
+
347
+			$errorData = [
348
+				$expectedText,
349
+				$foundText,
350
+			];
351
+
352
+			if ($this->error === true) {
353
+				$fix = $phpcsFile->addFixableError($error, $assignment, $type, $errorData);
354
+			} else {
355
+				$fix = $phpcsFile->addFixableWarning($error, $assignment, $type.'Warning', $errorData);
356
+			}
357
+
358
+			$errorGenerated = true;
359
+
360
+			if ($fix === true && $data['found'] !== null) {
361
+				$newContent = str_repeat(' ', $data['expected']);
362
+				if ($data['found'] === 0) {
363
+					$phpcsFile->fixer->addContentBefore($assignment, $newContent);
364
+				} else {
365
+					$phpcsFile->fixer->replaceToken(($assignment - 1), $newContent);
366
+				}
367
+			}
368
+		}//end foreach
369
+
370
+		if ($numAssignments > 1) {
371
+			if ($errorGenerated === true) {
372
+				$phpcsFile->recordMetric($stackPtr, 'Adjacent assignments aligned', 'no');
373
+			} else {
374
+				$phpcsFile->recordMetric($stackPtr, 'Adjacent assignments aligned', 'yes');
375
+			}
376
+		}
377
+
378
+		if ($stopped !== null) {
379
+			return $this->checkAlignment($phpcsFile, $stopped);
380
+		} else {
381
+			return $assign;
382
+		}
383
+
384
+	}//end checkAlignment()
385 385
 
386 386
 
387 387
 }//end class
Please login to merge, or discard this patch.
Spacing   +100 added lines, -100 removed lines patch added patch discarded remove patch
@@ -56,7 +56,7 @@  discard block
 block discarded – undo
56 56
     public function register()
57 57
     {
58 58
         $tokens = Tokens::$assignmentTokens;
59
-        unset($tokens[T_DOUBLE_ARROW]);
59
+        unset( $tokens[ T_DOUBLE_ARROW ] );
60 60
         return $tokens;
61 61
 
62 62
     }//end register()
@@ -71,21 +71,21 @@  discard block
 block discarded – undo
71 71
      *
72 72
      * @return int
73 73
      */
74
-    public function process(File $phpcsFile, $stackPtr)
74
+    public function process( File $phpcsFile, $stackPtr )
75 75
     {
76 76
         $tokens = $phpcsFile->getTokens();
77 77
 
78 78
         // Ignore assignments used in a condition, like an IF or FOR.
79
-        if (isset($tokens[$stackPtr]['nested_parenthesis']) === true) {
80
-            foreach ($tokens[$stackPtr]['nested_parenthesis'] as $start => $end) {
81
-                if (isset($tokens[$start]['parenthesis_owner']) === true) {
79
+        if ( isset( $tokens[ $stackPtr ][ 'nested_parenthesis' ] ) === true ) {
80
+            foreach ( $tokens[ $stackPtr ][ 'nested_parenthesis' ] as $start => $end ) {
81
+                if ( isset( $tokens[ $start ][ 'parenthesis_owner' ] ) === true ) {
82 82
                     return;
83 83
                 }
84 84
             }
85 85
         }
86 86
 
87
-        $lastAssign = $this->checkAlignment($phpcsFile, $stackPtr);
88
-        return ($lastAssign + 1);
87
+        $lastAssign = $this->checkAlignment( $phpcsFile, $stackPtr );
88
+        return ( $lastAssign + 1 );
89 89
 
90 90
     }//end process()
91 91
 
@@ -101,88 +101,88 @@  discard block
 block discarded – undo
101 101
      *
102 102
      * @return int
103 103
      */
104
-    public function checkAlignment($phpcsFile, $stackPtr, $end=null)
104
+    public function checkAlignment( $phpcsFile, $stackPtr, $end = null )
105 105
     {
106 106
         $tokens = $phpcsFile->getTokens();
107 107
 
108
-        $assignments = [];
108
+        $assignments = [ ];
109 109
         $prevAssign  = null;
110
-        $lastLine    = $tokens[$stackPtr]['line'];
110
+        $lastLine    = $tokens[ $stackPtr ][ 'line' ];
111 111
         $maxPadding  = null;
112 112
         $stopped     = null;
113 113
         $lastCode    = $stackPtr;
114 114
         $lastSemi    = null;
115 115
         $arrayEnd    = null;
116 116
 
117
-        if ($end === null) {
117
+        if ( $end === null ) {
118 118
             $end = $phpcsFile->numTokens;
119 119
         }
120 120
 
121 121
         $find = Tokens::$assignmentTokens;
122
-        unset($find[T_DOUBLE_ARROW]);
122
+        unset( $find[ T_DOUBLE_ARROW ] );
123 123
 
124 124
         $scopes = Tokens::$scopeOpeners;
125
-        unset($scopes[T_CLOSURE]);
126
-        unset($scopes[T_ANON_CLASS]);
127
-        unset($scopes[T_OBJECT]);
125
+        unset( $scopes[ T_CLOSURE ] );
126
+        unset( $scopes[ T_ANON_CLASS ] );
127
+        unset( $scopes[ T_OBJECT ] );
128 128
 
129
-        for ($assign = $stackPtr; $assign < $end; $assign++) {
130
-            if ($tokens[$assign]['level'] < $tokens[$stackPtr]['level']) {
129
+        for ( $assign = $stackPtr; $assign < $end; $assign++ ) {
130
+            if ( $tokens[ $assign ][ 'level' ] < $tokens[ $stackPtr ][ 'level' ] ) {
131 131
                 // Statement is in a different context, so the block is over.
132 132
                 break;
133 133
             }
134 134
 
135
-            if (isset($scopes[$tokens[$assign]['code']]) === true
136
-                && isset($tokens[$assign]['scope_opener']) === true
137
-                && $tokens[$assign]['level'] === $tokens[$stackPtr]['level']
135
+            if ( isset( $scopes[ $tokens[ $assign ][ 'code' ] ] ) === true
136
+                && isset( $tokens[ $assign ][ 'scope_opener' ] ) === true
137
+                && $tokens[ $assign ][ 'level' ] === $tokens[ $stackPtr ][ 'level' ]
138 138
             ) {
139 139
                 break;
140 140
             }
141 141
 
142
-            if ($assign === $arrayEnd) {
142
+            if ( $assign === $arrayEnd ) {
143 143
                 $arrayEnd = null;
144 144
             }
145 145
 
146
-            if (isset($find[$tokens[$assign]['code']]) === false) {
146
+            if ( isset( $find[ $tokens[ $assign ][ 'code' ] ] ) === false ) {
147 147
                 // A blank line indicates that the assignment block has ended.
148
-                if (isset(Tokens::$emptyTokens[$tokens[$assign]['code']]) === false
149
-                    && ($tokens[$assign]['line'] - $tokens[$lastCode]['line']) > 1
150
-                    && $tokens[$assign]['level'] === $tokens[$stackPtr]['level']
148
+                if ( isset( Tokens::$emptyTokens[ $tokens[ $assign ][ 'code' ] ] ) === false
149
+                    && ( $tokens[ $assign ][ 'line' ] - $tokens[ $lastCode ][ 'line' ] ) > 1
150
+                    && $tokens[ $assign ][ 'level' ] === $tokens[ $stackPtr ][ 'level' ]
151 151
                     && $arrayEnd === null
152 152
                 ) {
153 153
                     break;
154 154
                 }
155 155
 
156
-                if ($tokens[$assign]['code'] === T_CLOSE_TAG) {
156
+                if ( $tokens[ $assign ][ 'code' ] === T_CLOSE_TAG ) {
157 157
                     // Breaking out of PHP ends the assignment block.
158 158
                     break;
159 159
                 }
160 160
 
161
-                if ($tokens[$assign]['code'] === T_OPEN_SHORT_ARRAY
162
-                    && isset($tokens[$assign]['bracket_closer']) === true
161
+                if ( $tokens[ $assign ][ 'code' ] === T_OPEN_SHORT_ARRAY
162
+                    && isset( $tokens[ $assign ][ 'bracket_closer' ] ) === true
163 163
                 ) {
164
-                    $arrayEnd = $tokens[$assign]['bracket_closer'];
164
+                    $arrayEnd = $tokens[ $assign ][ 'bracket_closer' ];
165 165
                 }
166 166
 
167
-                if ($tokens[$assign]['code'] === T_ARRAY
168
-                    && isset($tokens[$assign]['parenthesis_opener']) === true
169
-                    && isset($tokens[$tokens[$assign]['parenthesis_opener']]['parenthesis_closer']) === true
167
+                if ( $tokens[ $assign ][ 'code' ] === T_ARRAY
168
+                    && isset( $tokens[ $assign ][ 'parenthesis_opener' ] ) === true
169
+                    && isset( $tokens[ $tokens[ $assign ][ 'parenthesis_opener' ] ][ 'parenthesis_closer' ] ) === true
170 170
                 ) {
171
-                    $arrayEnd = $tokens[$tokens[$assign]['parenthesis_opener']]['parenthesis_closer'];
171
+                    $arrayEnd = $tokens[ $tokens[ $assign ][ 'parenthesis_opener' ] ][ 'parenthesis_closer' ];
172 172
                 }
173 173
 
174
-                if (isset(Tokens::$emptyTokens[$tokens[$assign]['code']]) === false) {
174
+                if ( isset( Tokens::$emptyTokens[ $tokens[ $assign ][ 'code' ] ] ) === false ) {
175 175
                     $lastCode = $assign;
176 176
 
177
-                    if ($tokens[$assign]['code'] === T_SEMICOLON) {
178
-                        if ($tokens[$assign]['conditions'] === $tokens[$stackPtr]['conditions']) {
179
-                            if ($lastSemi !== null && $prevAssign !== null && $lastSemi > $prevAssign) {
177
+                    if ( $tokens[ $assign ][ 'code' ] === T_SEMICOLON ) {
178
+                        if ( $tokens[ $assign ][ 'conditions' ] === $tokens[ $stackPtr ][ 'conditions' ] ) {
179
+                            if ( $lastSemi !== null && $prevAssign !== null && $lastSemi > $prevAssign ) {
180 180
                                 // This statement did not have an assignment operator in it.
181 181
                                 break;
182 182
                             } else {
183 183
                                 $lastSemi = $assign;
184 184
                             }
185
-                        } else if ($tokens[$assign]['level'] < $tokens[$stackPtr]['level']) {
185
+                        } else if ( $tokens[ $assign ][ 'level' ] < $tokens[ $stackPtr ][ 'level' ] ) {
186 186
                             // Statement is in a different context, so the block is over.
187 187
                             break;
188 188
                         }
@@ -190,36 +190,36 @@  discard block
 block discarded – undo
190 190
                 }//end if
191 191
 
192 192
                 continue;
193
-            } else if ($assign !== $stackPtr && $tokens[$assign]['line'] === $lastLine) {
193
+            } else if ( $assign !== $stackPtr && $tokens[ $assign ][ 'line' ] === $lastLine ) {
194 194
                 // Skip multiple assignments on the same line. We only need to
195 195
                 // try and align the first assignment.
196 196
                 continue;
197 197
             }//end if
198 198
 
199
-            if ($assign !== $stackPtr) {
200
-                if ($tokens[$assign]['level'] > $tokens[$stackPtr]['level']) {
199
+            if ( $assign !== $stackPtr ) {
200
+                if ( $tokens[ $assign ][ 'level' ] > $tokens[ $stackPtr ][ 'level' ] ) {
201 201
                     // Has to be nested inside the same conditions as the first assignment.
202 202
                     // We've gone one level down, so process this new block.
203
-                    $assign   = $this->checkAlignment($phpcsFile, $assign);
203
+                    $assign   = $this->checkAlignment( $phpcsFile, $assign );
204 204
                     $lastCode = $assign;
205 205
                     continue;
206
-                } else if ($tokens[$assign]['level'] < $tokens[$stackPtr]['level']) {
206
+                } else if ( $tokens[ $assign ][ 'level' ] < $tokens[ $stackPtr ][ 'level' ] ) {
207 207
                     // We've gone one level up, so the block we are processing is done.
208 208
                     break;
209
-                } else if ($arrayEnd !== null) {
209
+                } else if ( $arrayEnd !== null ) {
210 210
                     // Assignments inside arrays are not part of
211 211
                     // the original block, so process this new block.
212
-                    $assign   = ($this->checkAlignment($phpcsFile, $assign, $arrayEnd) - 1);
212
+                    $assign   = ( $this->checkAlignment( $phpcsFile, $assign, $arrayEnd ) - 1 );
213 213
                     $arrayEnd = null;
214 214
                     $lastCode = $assign;
215 215
                     continue;
216 216
                 }
217 217
 
218 218
                 // Make sure it is not assigned inside a condition (eg. IF, FOR).
219
-                if (isset($tokens[$assign]['nested_parenthesis']) === true) {
220
-                    foreach ($tokens[$assign]['nested_parenthesis'] as $start => $end) {
221
-                        if (isset($tokens[$start]['parenthesis_owner']) === true) {
222
-                            break(2);
219
+                if ( isset( $tokens[ $assign ][ 'nested_parenthesis' ] ) === true ) {
220
+                    foreach ( $tokens[ $assign ][ 'nested_parenthesis' ] as $start => $end ) {
221
+                        if ( isset( $tokens[ $start ][ 'parenthesis_owner' ] ) === true ) {
222
+                            break( 2 );
223 223
                         }
224 224
                     }
225 225
                 }
@@ -227,7 +227,7 @@  discard block
 block discarded – undo
227 227
 
228 228
             $var = $phpcsFile->findPrevious(
229 229
                 Tokens::$emptyTokens,
230
-                ($assign - 1),
230
+                ( $assign - 1 ),
231 231
                 null,
232 232
                 true
233 233
             );
@@ -235,70 +235,70 @@  discard block
 block discarded – undo
235 235
             // Make sure we wouldn't break our max padding length if we
236 236
             // aligned with this statement, or they wouldn't break the max
237 237
             // padding length if they aligned with us.
238
-            $varEnd    = $tokens[($var + 1)]['column'];
239
-            $assignLen = $tokens[$assign]['length'];
240
-            if ($assign !== $stackPtr) {
241
-                if ($prevAssign === null) {
238
+            $varEnd    = $tokens[ ( $var + 1 ) ][ 'column' ];
239
+            $assignLen = $tokens[ $assign ][ 'length' ];
240
+            if ( $assign !== $stackPtr ) {
241
+                if ( $prevAssign === null ) {
242 242
                     // Processing an inner block but no assignments found.
243 243
                     break;
244 244
                 }
245 245
 
246
-                if (($varEnd + 1) > $assignments[$prevAssign]['assign_col']) {
246
+                if ( ( $varEnd + 1 ) > $assignments[ $prevAssign ][ 'assign_col' ] ) {
247 247
                     $padding      = 1;
248
-                    $assignColumn = ($varEnd + 1);
248
+                    $assignColumn = ( $varEnd + 1 );
249 249
                 } else {
250
-                    $padding = ($assignments[$prevAssign]['assign_col'] - $varEnd + $assignments[$prevAssign]['assign_len'] - $assignLen);
251
-                    if ($padding <= 0) {
250
+                    $padding = ( $assignments[ $prevAssign ][ 'assign_col' ] - $varEnd + $assignments[ $prevAssign ][ 'assign_len' ] - $assignLen );
251
+                    if ( $padding <= 0 ) {
252 252
                         $padding = 1;
253 253
                     }
254 254
 
255
-                    if ($padding > $this->maxPadding) {
255
+                    if ( $padding > $this->maxPadding ) {
256 256
                         $stopped = $assign;
257 257
                         break;
258 258
                     }
259 259
 
260
-                    $assignColumn = ($varEnd + $padding);
260
+                    $assignColumn = ( $varEnd + $padding );
261 261
                 }//end if
262 262
 
263
-                if (($assignColumn + $assignLen) > ($assignments[$maxPadding]['assign_col'] + $assignments[$maxPadding]['assign_len'])) {
264
-                    $newPadding = ($varEnd - $assignments[$maxPadding]['var_end'] + $assignLen - $assignments[$maxPadding]['assign_len'] + 1);
265
-                    if ($newPadding > $this->maxPadding) {
263
+                if ( ( $assignColumn + $assignLen ) > ( $assignments[ $maxPadding ][ 'assign_col' ] + $assignments[ $maxPadding ][ 'assign_len' ] ) ) {
264
+                    $newPadding = ( $varEnd - $assignments[ $maxPadding ][ 'var_end' ] + $assignLen - $assignments[ $maxPadding ][ 'assign_len' ] + 1 );
265
+                    if ( $newPadding > $this->maxPadding ) {
266 266
                         $stopped = $assign;
267 267
                         break;
268 268
                     } else {
269 269
                         // New alignment settings for previous assignments.
270
-                        foreach ($assignments as $i => $data) {
271
-                            if ($i === $assign) {
270
+                        foreach ( $assignments as $i => $data ) {
271
+                            if ( $i === $assign ) {
272 272
                                 break;
273 273
                             }
274 274
 
275
-                            $newPadding = ($varEnd - $data['var_end'] + $assignLen - $data['assign_len'] + 1);
276
-                            $assignments[$i]['expected']   = $newPadding;
277
-                            $assignments[$i]['assign_col'] = ($data['var_end'] + $newPadding);
275
+                            $newPadding = ( $varEnd - $data[ 'var_end' ] + $assignLen - $data[ 'assign_len' ] + 1 );
276
+                            $assignments[ $i ][ 'expected' ]   = $newPadding;
277
+                            $assignments[ $i ][ 'assign_col' ] = ( $data[ 'var_end' ] + $newPadding );
278 278
                         }
279 279
 
280 280
                         $padding      = 1;
281
-                        $assignColumn = ($varEnd + 1);
281
+                        $assignColumn = ( $varEnd + 1 );
282 282
                     }
283
-                } else if ($padding > $assignments[$maxPadding]['expected']) {
283
+                } else if ( $padding > $assignments[ $maxPadding ][ 'expected' ] ) {
284 284
                     $maxPadding = $assign;
285 285
                 }//end if
286 286
             } else {
287 287
                 $padding      = 1;
288
-                $assignColumn = ($varEnd + 1);
288
+                $assignColumn = ( $varEnd + 1 );
289 289
                 $maxPadding   = $assign;
290 290
             }//end if
291 291
 
292 292
             $found = 0;
293
-            if ($tokens[($var + 1)]['code'] === T_WHITESPACE) {
294
-                $found = $tokens[($var + 1)]['length'];
295
-                if ($found === 0) {
293
+            if ( $tokens[ ( $var + 1 ) ][ 'code' ] === T_WHITESPACE ) {
294
+                $found = $tokens[ ( $var + 1 ) ][ 'length' ];
295
+                if ( $found === 0 ) {
296 296
                     // This means a newline was found.
297 297
                     $found = 1;
298 298
                 }
299 299
             }
300 300
 
301
-            $assignments[$assign] = [
301
+            $assignments[ $assign ] = [
302 302
                 'var_end'    => $varEnd,
303 303
                 'assign_len' => $assignLen,
304 304
                 'assign_col' => $assignColumn,
@@ -306,37 +306,37 @@  discard block
 block discarded – undo
306 306
                 'found'      => $found,
307 307
             ];
308 308
 
309
-            $lastLine   = $tokens[$assign]['line'];
309
+            $lastLine   = $tokens[ $assign ][ 'line' ];
310 310
             $prevAssign = $assign;
311 311
         }//end for
312 312
 
313
-        if (empty($assignments) === true) {
313
+        if ( empty( $assignments ) === true ) {
314 314
             return $stackPtr;
315 315
         }
316 316
 
317
-        $numAssignments = count($assignments);
317
+        $numAssignments = count( $assignments );
318 318
 
319 319
         $errorGenerated = false;
320
-        foreach ($assignments as $assignment => $data) {
321
-            if ($data['found'] === $data['expected']) {
320
+        foreach ( $assignments as $assignment => $data ) {
321
+            if ( $data[ 'found' ] === $data[ 'expected' ] ) {
322 322
                 continue;
323 323
             }
324 324
 
325
-            $expectedText = $data['expected'].' space';
326
-            if ($data['expected'] !== 1) {
325
+            $expectedText = $data[ 'expected' ] . ' space';
326
+            if ( $data[ 'expected' ] !== 1 ) {
327 327
                 $expectedText .= 's';
328 328
             }
329 329
 
330
-            if ($data['found'] === null) {
330
+            if ( $data[ 'found' ] === null ) {
331 331
                 $foundText = 'a new line';
332 332
             } else {
333
-                $foundText = $data['found'].' space';
334
-                if ($data['found'] !== 1) {
333
+                $foundText = $data[ 'found' ] . ' space';
334
+                if ( $data[ 'found' ] !== 1 ) {
335 335
                     $foundText .= 's';
336 336
                 }
337 337
             }
338 338
 
339
-            if ($numAssignments === 1) {
339
+            if ( $numAssignments === 1 ) {
340 340
                 $type  = 'Incorrect';
341 341
                 $error = 'Equals sign not aligned correctly; expected %s but found %s';
342 342
             } else {
@@ -349,34 +349,34 @@  discard block
 block discarded – undo
349 349
                 $foundText,
350 350
             ];
351 351
 
352
-            if ($this->error === true) {
353
-                $fix = $phpcsFile->addFixableError($error, $assignment, $type, $errorData);
352
+            if ( $this->error === true ) {
353
+                $fix = $phpcsFile->addFixableError( $error, $assignment, $type, $errorData );
354 354
             } else {
355
-                $fix = $phpcsFile->addFixableWarning($error, $assignment, $type.'Warning', $errorData);
355
+                $fix = $phpcsFile->addFixableWarning( $error, $assignment, $type . 'Warning', $errorData );
356 356
             }
357 357
 
358 358
             $errorGenerated = true;
359 359
 
360
-            if ($fix === true && $data['found'] !== null) {
361
-                $newContent = str_repeat(' ', $data['expected']);
362
-                if ($data['found'] === 0) {
363
-                    $phpcsFile->fixer->addContentBefore($assignment, $newContent);
360
+            if ( $fix === true && $data[ 'found' ] !== null ) {
361
+                $newContent = str_repeat( ' ', $data[ 'expected' ] );
362
+                if ( $data[ 'found' ] === 0 ) {
363
+                    $phpcsFile->fixer->addContentBefore( $assignment, $newContent );
364 364
                 } else {
365
-                    $phpcsFile->fixer->replaceToken(($assignment - 1), $newContent);
365
+                    $phpcsFile->fixer->replaceToken( ( $assignment - 1 ), $newContent );
366 366
                 }
367 367
             }
368 368
         }//end foreach
369 369
 
370
-        if ($numAssignments > 1) {
371
-            if ($errorGenerated === true) {
372
-                $phpcsFile->recordMetric($stackPtr, 'Adjacent assignments aligned', 'no');
370
+        if ( $numAssignments > 1 ) {
371
+            if ( $errorGenerated === true ) {
372
+                $phpcsFile->recordMetric( $stackPtr, 'Adjacent assignments aligned', 'no' );
373 373
             } else {
374
-                $phpcsFile->recordMetric($stackPtr, 'Adjacent assignments aligned', 'yes');
374
+                $phpcsFile->recordMetric( $stackPtr, 'Adjacent assignments aligned', 'yes' );
375 375
             }
376 376
         }
377 377
 
378
-        if ($stopped !== null) {
379
-            return $this->checkAlignment($phpcsFile, $stopped);
378
+        if ( $stopped !== null ) {
379
+            return $this->checkAlignment( $phpcsFile, $stopped );
380 380
         } else {
381 381
             return $assign;
382 382
         }
Please login to merge, or discard this patch.
Braces   +4 added lines, -8 removed lines patch added patch discarded remove patch
@@ -16,8 +16,7 @@  discard block
 block discarded – undo
16 16
 use PHP_CodeSniffer\Files\File;
17 17
 use PHP_CodeSniffer\Util\Tokens;
18 18
 
19
-class MultipleStatementAlignmentSniff implements Sniff
20
-{
19
+class MultipleStatementAlignmentSniff implements Sniff {
21 20
 
22 21
     /**
23 22
      * A list of tokenizers this sniff supports.
@@ -53,8 +52,7 @@  discard block
 block discarded – undo
53 52
      *
54 53
      * @return array
55 54
      */
56
-    public function register()
57
-    {
55
+    public function register() {
58 56
         $tokens = Tokens::$assignmentTokens;
59 57
         unset($tokens[T_DOUBLE_ARROW]);
60 58
         return $tokens;
@@ -71,8 +69,7 @@  discard block
 block discarded – undo
71 69
      *
72 70
      * @return int
73 71
      */
74
-    public function process(File $phpcsFile, $stackPtr)
75
-    {
72
+    public function process(File $phpcsFile, $stackPtr) {
76 73
         $tokens = $phpcsFile->getTokens();
77 74
 
78 75
         // Ignore assignments used in a condition, like an IF or FOR.
@@ -101,8 +98,7 @@  discard block
 block discarded – undo
101 98
      *
102 99
      * @return int
103 100
      */
104
-    public function checkAlignment($phpcsFile, $stackPtr, $end=null)
105
-    {
101
+    public function checkAlignment($phpcsFile, $stackPtr, $end=null) {
106 102
         $tokens = $phpcsFile->getTokens();
107 103
 
108 104
         $assignments = [];
Please login to merge, or discard this patch.
php_codesniffer/src/Standards/Generic/Sniffs/PHP/ClosingPHPTagSniff.php 3 patches
Indentation   +30 added lines, -30 removed lines patch added patch discarded remove patch
@@ -16,36 +16,36 @@
 block discarded – undo
16 16
 {
17 17
 
18 18
 
19
-    /**
20
-     * Returns an array of tokens this test wants to listen for.
21
-     *
22
-     * @return array
23
-     */
24
-    public function register()
25
-    {
26
-        return [T_OPEN_TAG];
27
-
28
-    }//end register()
29
-
30
-
31
-    /**
32
-     * Processes this sniff, when one of its tokens is encountered.
33
-     *
34
-     * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.
35
-     * @param int                         $stackPtr  The position of the current token in
36
-     *                                               the stack passed in $tokens.
37
-     *
38
-     * @return void
39
-     */
40
-    public function process(File $phpcsFile, $stackPtr)
41
-    {
42
-        $closeTag = $phpcsFile->findNext(T_CLOSE_TAG, $stackPtr);
43
-        if ($closeTag === false) {
44
-            $error = 'The PHP open tag does not have a corresponding PHP close tag';
45
-            $phpcsFile->addError($error, $stackPtr, 'NotFound');
46
-        }
47
-
48
-    }//end process()
19
+	/**
20
+	 * Returns an array of tokens this test wants to listen for.
21
+	 *
22
+	 * @return array
23
+	 */
24
+	public function register()
25
+	{
26
+		return [T_OPEN_TAG];
27
+
28
+	}//end register()
29
+
30
+
31
+	/**
32
+	 * Processes this sniff, when one of its tokens is encountered.
33
+	 *
34
+	 * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.
35
+	 * @param int                         $stackPtr  The position of the current token in
36
+	 *                                               the stack passed in $tokens.
37
+	 *
38
+	 * @return void
39
+	 */
40
+	public function process(File $phpcsFile, $stackPtr)
41
+	{
42
+		$closeTag = $phpcsFile->findNext(T_CLOSE_TAG, $stackPtr);
43
+		if ($closeTag === false) {
44
+			$error = 'The PHP open tag does not have a corresponding PHP close tag';
45
+			$phpcsFile->addError($error, $stackPtr, 'NotFound');
46
+		}
47
+
48
+	}//end process()
49 49
 
50 50
 
51 51
 }//end class
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -23,7 +23,7 @@  discard block
 block discarded – undo
23 23
      */
24 24
     public function register()
25 25
     {
26
-        return [T_OPEN_TAG];
26
+        return [ T_OPEN_TAG ];
27 27
 
28 28
     }//end register()
29 29
 
@@ -37,12 +37,12 @@  discard block
 block discarded – undo
37 37
      *
38 38
      * @return void
39 39
      */
40
-    public function process(File $phpcsFile, $stackPtr)
40
+    public function process( File $phpcsFile, $stackPtr )
41 41
     {
42
-        $closeTag = $phpcsFile->findNext(T_CLOSE_TAG, $stackPtr);
43
-        if ($closeTag === false) {
42
+        $closeTag = $phpcsFile->findNext( T_CLOSE_TAG, $stackPtr );
43
+        if ( $closeTag === false ) {
44 44
             $error = 'The PHP open tag does not have a corresponding PHP close tag';
45
-            $phpcsFile->addError($error, $stackPtr, 'NotFound');
45
+            $phpcsFile->addError( $error, $stackPtr, 'NotFound' );
46 46
         }
47 47
 
48 48
     }//end process()
Please login to merge, or discard this patch.
Braces   +3 added lines, -6 removed lines patch added patch discarded remove patch
@@ -12,8 +12,7 @@  discard block
 block discarded – undo
12 12
 use PHP_CodeSniffer\Sniffs\Sniff;
13 13
 use PHP_CodeSniffer\Files\File;
14 14
 
15
-class ClosingPHPTagSniff implements Sniff
16
-{
15
+class ClosingPHPTagSniff implements Sniff {
17 16
 
18 17
 
19 18
     /**
@@ -21,8 +20,7 @@  discard block
 block discarded – undo
21 20
      *
22 21
      * @return array
23 22
      */
24
-    public function register()
25
-    {
23
+    public function register() {
26 24
         return [T_OPEN_TAG];
27 25
 
28 26
     }//end register()
@@ -37,8 +35,7 @@  discard block
 block discarded – undo
37 35
      *
38 36
      * @return void
39 37
      */
40
-    public function process(File $phpcsFile, $stackPtr)
41
-    {
38
+    public function process(File $phpcsFile, $stackPtr) {
42 39
         $closeTag = $phpcsFile->findNext(T_CLOSE_TAG, $stackPtr);
43 40
         if ($closeTag === false) {
44 41
             $error = 'The PHP open tag does not have a corresponding PHP close tag';
Please login to merge, or discard this patch.
src/Standards/Generic/Sniffs/PHP/CharacterBeforePHPOpeningTagSniff.php 3 patches
Indentation   +58 added lines, -58 removed lines patch added patch discarded remove patch
@@ -15,73 +15,73 @@
 block discarded – undo
15 15
 class CharacterBeforePHPOpeningTagSniff implements Sniff
16 16
 {
17 17
 
18
-    /**
19
-     * List of supported BOM definitions.
20
-     *
21
-     * Use encoding names as keys and hex BOM representations as values.
22
-     *
23
-     * @var array
24
-     */
25
-    protected $bomDefinitions = [
26
-        'UTF-8'       => 'efbbbf',
27
-        'UTF-16 (BE)' => 'feff',
28
-        'UTF-16 (LE)' => 'fffe',
29
-    ];
18
+	/**
19
+	 * List of supported BOM definitions.
20
+	 *
21
+	 * Use encoding names as keys and hex BOM representations as values.
22
+	 *
23
+	 * @var array
24
+	 */
25
+	protected $bomDefinitions = [
26
+		'UTF-8'       => 'efbbbf',
27
+		'UTF-16 (BE)' => 'feff',
28
+		'UTF-16 (LE)' => 'fffe',
29
+	];
30 30
 
31 31
 
32
-    /**
33
-     * Returns an array of tokens this test wants to listen for.
34
-     *
35
-     * @return array
36
-     */
37
-    public function register()
38
-    {
39
-        return [T_OPEN_TAG];
32
+	/**
33
+	 * Returns an array of tokens this test wants to listen for.
34
+	 *
35
+	 * @return array
36
+	 */
37
+	public function register()
38
+	{
39
+		return [T_OPEN_TAG];
40 40
 
41
-    }//end register()
41
+	}//end register()
42 42
 
43 43
 
44
-    /**
45
-     * Processes this sniff, when one of its tokens is encountered.
46
-     *
47
-     * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.
48
-     * @param int                         $stackPtr  The position of the current token in
49
-     *                                               the stack passed in $tokens.
50
-     *
51
-     * @return void
52
-     */
53
-    public function process(File $phpcsFile, $stackPtr)
54
-    {
55
-        $expected = 0;
56
-        if ($stackPtr > 0) {
57
-            // Allow a byte-order mark.
58
-            $tokens = $phpcsFile->getTokens();
59
-            foreach ($this->bomDefinitions as $bomName => $expectedBomHex) {
60
-                $bomByteLength = (strlen($expectedBomHex) / 2);
61
-                $htmlBomHex    = bin2hex(substr($tokens[0]['content'], 0, $bomByteLength));
62
-                if ($htmlBomHex === $expectedBomHex) {
63
-                    $expected++;
64
-                    break;
65
-                }
66
-            }
44
+	/**
45
+	 * Processes this sniff, when one of its tokens is encountered.
46
+	 *
47
+	 * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.
48
+	 * @param int                         $stackPtr  The position of the current token in
49
+	 *                                               the stack passed in $tokens.
50
+	 *
51
+	 * @return void
52
+	 */
53
+	public function process(File $phpcsFile, $stackPtr)
54
+	{
55
+		$expected = 0;
56
+		if ($stackPtr > 0) {
57
+			// Allow a byte-order mark.
58
+			$tokens = $phpcsFile->getTokens();
59
+			foreach ($this->bomDefinitions as $bomName => $expectedBomHex) {
60
+				$bomByteLength = (strlen($expectedBomHex) / 2);
61
+				$htmlBomHex    = bin2hex(substr($tokens[0]['content'], 0, $bomByteLength));
62
+				if ($htmlBomHex === $expectedBomHex) {
63
+					$expected++;
64
+					break;
65
+				}
66
+			}
67 67
 
68
-            // Allow a shebang line.
69
-            $tokens = $phpcsFile->getTokens();
70
-            if (substr($tokens[0]['content'], 0, 2) === '#!') {
71
-                $expected++;
72
-            }
73
-        }
68
+			// Allow a shebang line.
69
+			$tokens = $phpcsFile->getTokens();
70
+			if (substr($tokens[0]['content'], 0, 2) === '#!') {
71
+				$expected++;
72
+			}
73
+		}
74 74
 
75
-        if ($stackPtr !== $expected) {
76
-            $error = 'The opening PHP tag must be the first content in the file';
77
-            $phpcsFile->addError($error, $stackPtr, 'Found');
78
-        }
75
+		if ($stackPtr !== $expected) {
76
+			$error = 'The opening PHP tag must be the first content in the file';
77
+			$phpcsFile->addError($error, $stackPtr, 'Found');
78
+		}
79 79
 
80
-        // Skip the rest of the file so we don't pick up additional
81
-        // open tags, typically embedded in HTML.
82
-        return $phpcsFile->numTokens;
80
+		// Skip the rest of the file so we don't pick up additional
81
+		// open tags, typically embedded in HTML.
82
+		return $phpcsFile->numTokens;
83 83
 
84
-    }//end process()
84
+	}//end process()
85 85
 
86 86
 
87 87
 }//end class
Please login to merge, or discard this patch.
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -36,7 +36,7 @@  discard block
 block discarded – undo
36 36
      */
37 37
     public function register()
38 38
     {
39
-        return [T_OPEN_TAG];
39
+        return [ T_OPEN_TAG ];
40 40
 
41 41
     }//end register()
42 42
 
@@ -50,16 +50,16 @@  discard block
 block discarded – undo
50 50
      *
51 51
      * @return void
52 52
      */
53
-    public function process(File $phpcsFile, $stackPtr)
53
+    public function process( File $phpcsFile, $stackPtr )
54 54
     {
55 55
         $expected = 0;
56
-        if ($stackPtr > 0) {
56
+        if ( $stackPtr > 0 ) {
57 57
             // Allow a byte-order mark.
58 58
             $tokens = $phpcsFile->getTokens();
59
-            foreach ($this->bomDefinitions as $bomName => $expectedBomHex) {
60
-                $bomByteLength = (strlen($expectedBomHex) / 2);
61
-                $htmlBomHex    = bin2hex(substr($tokens[0]['content'], 0, $bomByteLength));
62
-                if ($htmlBomHex === $expectedBomHex) {
59
+            foreach ( $this->bomDefinitions as $bomName => $expectedBomHex ) {
60
+                $bomByteLength = ( strlen( $expectedBomHex ) / 2 );
61
+                $htmlBomHex    = bin2hex( substr( $tokens[ 0 ][ 'content' ], 0, $bomByteLength ) );
62
+                if ( $htmlBomHex === $expectedBomHex ) {
63 63
                     $expected++;
64 64
                     break;
65 65
                 }
@@ -67,14 +67,14 @@  discard block
 block discarded – undo
67 67
 
68 68
             // Allow a shebang line.
69 69
             $tokens = $phpcsFile->getTokens();
70
-            if (substr($tokens[0]['content'], 0, 2) === '#!') {
70
+            if ( substr( $tokens[ 0 ][ 'content' ], 0, 2 ) === '#!' ) {
71 71
                 $expected++;
72 72
             }
73 73
         }
74 74
 
75
-        if ($stackPtr !== $expected) {
75
+        if ( $stackPtr !== $expected ) {
76 76
             $error = 'The opening PHP tag must be the first content in the file';
77
-            $phpcsFile->addError($error, $stackPtr, 'Found');
77
+            $phpcsFile->addError( $error, $stackPtr, 'Found' );
78 78
         }
79 79
 
80 80
         // Skip the rest of the file so we don't pick up additional
Please login to merge, or discard this patch.
Braces   +3 added lines, -6 removed lines patch added patch discarded remove patch
@@ -12,8 +12,7 @@  discard block
 block discarded – undo
12 12
 use PHP_CodeSniffer\Sniffs\Sniff;
13 13
 use PHP_CodeSniffer\Files\File;
14 14
 
15
-class CharacterBeforePHPOpeningTagSniff implements Sniff
16
-{
15
+class CharacterBeforePHPOpeningTagSniff implements Sniff {
17 16
 
18 17
     /**
19 18
      * List of supported BOM definitions.
@@ -34,8 +33,7 @@  discard block
 block discarded – undo
34 33
      *
35 34
      * @return array
36 35
      */
37
-    public function register()
38
-    {
36
+    public function register() {
39 37
         return [T_OPEN_TAG];
40 38
 
41 39
     }//end register()
@@ -50,8 +48,7 @@  discard block
 block discarded – undo
50 48
      *
51 49
      * @return void
52 50
      */
53
-    public function process(File $phpcsFile, $stackPtr)
54
-    {
51
+    public function process(File $phpcsFile, $stackPtr) {
55 52
         $expected = 0;
56 53
         if ($stackPtr > 0) {
57 54
             // Allow a byte-order mark.
Please login to merge, or discard this patch.
php_codesniffer/src/Standards/Generic/Sniffs/PHP/LowerCaseKeywordSniff.php 3 patches
Indentation   +113 added lines, -113 removed lines patch added patch discarded remove patch
@@ -17,126 +17,126 @@
 block discarded – undo
17 17
 {
18 18
 
19 19
 
20
-    /**
21
-     * Returns an array of tokens this test wants to listen for.
22
-     *
23
-     * @return array
24
-     */
25
-    public function register()
26
-    {
27
-        return [
28
-            T_HALT_COMPILER,
29
-            T_ABSTRACT,
30
-            T_ARRAY,
31
-            T_AS,
32
-            T_BREAK,
33
-            T_CALLABLE,
34
-            T_CASE,
35
-            T_CATCH,
36
-            T_CLASS,
37
-            T_CLONE,
38
-            T_CLOSURE,
39
-            T_CONST,
40
-            T_CONTINUE,
41
-            T_DECLARE,
42
-            T_DEFAULT,
43
-            T_DO,
44
-            T_ECHO,
45
-            T_ELSE,
46
-            T_ELSEIF,
47
-            T_EMPTY,
48
-            T_ENDDECLARE,
49
-            T_ENDFOR,
50
-            T_ENDFOREACH,
51
-            T_ENDIF,
52
-            T_ENDSWITCH,
53
-            T_ENDWHILE,
54
-            T_EVAL,
55
-            T_EXIT,
56
-            T_EXTENDS,
57
-            T_FINAL,
58
-            T_FINALLY,
59
-            T_FOR,
60
-            T_FOREACH,
61
-            T_FUNCTION,
62
-            T_GLOBAL,
63
-            T_GOTO,
64
-            T_IF,
65
-            T_IMPLEMENTS,
66
-            T_INCLUDE,
67
-            T_INCLUDE_ONCE,
68
-            T_INSTANCEOF,
69
-            T_INSTEADOF,
70
-            T_INTERFACE,
71
-            T_ISSET,
72
-            T_LIST,
73
-            T_LOGICAL_AND,
74
-            T_LOGICAL_OR,
75
-            T_LOGICAL_XOR,
76
-            T_NAMESPACE,
77
-            T_NEW,
78
-            T_PARENT,
79
-            T_PRINT,
80
-            T_PRIVATE,
81
-            T_PROTECTED,
82
-            T_PUBLIC,
83
-            T_REQUIRE,
84
-            T_REQUIRE_ONCE,
85
-            T_RETURN,
86
-            T_SELF,
87
-            T_STATIC,
88
-            T_SWITCH,
89
-            T_THROW,
90
-            T_TRAIT,
91
-            T_TRY,
92
-            T_UNSET,
93
-            T_USE,
94
-            T_VAR,
95
-            T_WHILE,
96
-            T_YIELD,
97
-            T_YIELD_FROM,
98
-        ];
20
+	/**
21
+	 * Returns an array of tokens this test wants to listen for.
22
+	 *
23
+	 * @return array
24
+	 */
25
+	public function register()
26
+	{
27
+		return [
28
+			T_HALT_COMPILER,
29
+			T_ABSTRACT,
30
+			T_ARRAY,
31
+			T_AS,
32
+			T_BREAK,
33
+			T_CALLABLE,
34
+			T_CASE,
35
+			T_CATCH,
36
+			T_CLASS,
37
+			T_CLONE,
38
+			T_CLOSURE,
39
+			T_CONST,
40
+			T_CONTINUE,
41
+			T_DECLARE,
42
+			T_DEFAULT,
43
+			T_DO,
44
+			T_ECHO,
45
+			T_ELSE,
46
+			T_ELSEIF,
47
+			T_EMPTY,
48
+			T_ENDDECLARE,
49
+			T_ENDFOR,
50
+			T_ENDFOREACH,
51
+			T_ENDIF,
52
+			T_ENDSWITCH,
53
+			T_ENDWHILE,
54
+			T_EVAL,
55
+			T_EXIT,
56
+			T_EXTENDS,
57
+			T_FINAL,
58
+			T_FINALLY,
59
+			T_FOR,
60
+			T_FOREACH,
61
+			T_FUNCTION,
62
+			T_GLOBAL,
63
+			T_GOTO,
64
+			T_IF,
65
+			T_IMPLEMENTS,
66
+			T_INCLUDE,
67
+			T_INCLUDE_ONCE,
68
+			T_INSTANCEOF,
69
+			T_INSTEADOF,
70
+			T_INTERFACE,
71
+			T_ISSET,
72
+			T_LIST,
73
+			T_LOGICAL_AND,
74
+			T_LOGICAL_OR,
75
+			T_LOGICAL_XOR,
76
+			T_NAMESPACE,
77
+			T_NEW,
78
+			T_PARENT,
79
+			T_PRINT,
80
+			T_PRIVATE,
81
+			T_PROTECTED,
82
+			T_PUBLIC,
83
+			T_REQUIRE,
84
+			T_REQUIRE_ONCE,
85
+			T_RETURN,
86
+			T_SELF,
87
+			T_STATIC,
88
+			T_SWITCH,
89
+			T_THROW,
90
+			T_TRAIT,
91
+			T_TRY,
92
+			T_UNSET,
93
+			T_USE,
94
+			T_VAR,
95
+			T_WHILE,
96
+			T_YIELD,
97
+			T_YIELD_FROM,
98
+		];
99 99
 
100
-    }//end register()
100
+	}//end register()
101 101
 
102 102
 
103
-    /**
104
-     * Processes this sniff, when one of its tokens is encountered.
105
-     *
106
-     * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.
107
-     * @param int                         $stackPtr  The position of the current token in the
108
-     *                                               stack passed in $tokens.
109
-     *
110
-     * @return void
111
-     */
112
-    public function process(File $phpcsFile, $stackPtr)
113
-    {
114
-        $tokens  = $phpcsFile->getTokens();
115
-        $keyword = $tokens[$stackPtr]['content'];
116
-        if (strtolower($keyword) !== $keyword) {
117
-            if ($keyword === strtoupper($keyword)) {
118
-                $phpcsFile->recordMetric($stackPtr, 'PHP keyword case', 'upper');
119
-            } else {
120
-                $phpcsFile->recordMetric($stackPtr, 'PHP keyword case', 'mixed');
121
-            }
103
+	/**
104
+	 * Processes this sniff, when one of its tokens is encountered.
105
+	 *
106
+	 * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.
107
+	 * @param int                         $stackPtr  The position of the current token in the
108
+	 *                                               stack passed in $tokens.
109
+	 *
110
+	 * @return void
111
+	 */
112
+	public function process(File $phpcsFile, $stackPtr)
113
+	{
114
+		$tokens  = $phpcsFile->getTokens();
115
+		$keyword = $tokens[$stackPtr]['content'];
116
+		if (strtolower($keyword) !== $keyword) {
117
+			if ($keyword === strtoupper($keyword)) {
118
+				$phpcsFile->recordMetric($stackPtr, 'PHP keyword case', 'upper');
119
+			} else {
120
+				$phpcsFile->recordMetric($stackPtr, 'PHP keyword case', 'mixed');
121
+			}
122 122
 
123
-            $messageKeyword = Util\Common::prepareForOutput($keyword);
123
+			$messageKeyword = Util\Common::prepareForOutput($keyword);
124 124
 
125
-            $error = 'PHP keywords must be lowercase; expected "%s" but found "%s"';
126
-            $data  = [
127
-                strtolower($messageKeyword),
128
-                $messageKeyword,
129
-            ];
125
+			$error = 'PHP keywords must be lowercase; expected "%s" but found "%s"';
126
+			$data  = [
127
+				strtolower($messageKeyword),
128
+				$messageKeyword,
129
+			];
130 130
 
131
-            $fix = $phpcsFile->addFixableError($error, $stackPtr, 'Found', $data);
132
-            if ($fix === true) {
133
-                $phpcsFile->fixer->replaceToken($stackPtr, strtolower($keyword));
134
-            }
135
-        } else {
136
-            $phpcsFile->recordMetric($stackPtr, 'PHP keyword case', 'lower');
137
-        }//end if
131
+			$fix = $phpcsFile->addFixableError($error, $stackPtr, 'Found', $data);
132
+			if ($fix === true) {
133
+				$phpcsFile->fixer->replaceToken($stackPtr, strtolower($keyword));
134
+			}
135
+		} else {
136
+			$phpcsFile->recordMetric($stackPtr, 'PHP keyword case', 'lower');
137
+		}//end if
138 138
 
139
-    }//end process()
139
+	}//end process()
140 140
 
141 141
 
142 142
 }//end class
Please login to merge, or discard this patch.
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -109,31 +109,31 @@
 block discarded – undo
109 109
      *
110 110
      * @return void
111 111
      */
112
-    public function process(File $phpcsFile, $stackPtr)
112
+    public function process( File $phpcsFile, $stackPtr )
113 113
     {
114 114
         $tokens  = $phpcsFile->getTokens();
115
-        $keyword = $tokens[$stackPtr]['content'];
116
-        if (strtolower($keyword) !== $keyword) {
117
-            if ($keyword === strtoupper($keyword)) {
118
-                $phpcsFile->recordMetric($stackPtr, 'PHP keyword case', 'upper');
115
+        $keyword = $tokens[ $stackPtr ][ 'content' ];
116
+        if ( strtolower( $keyword ) !== $keyword ) {
117
+            if ( $keyword === strtoupper( $keyword ) ) {
118
+                $phpcsFile->recordMetric( $stackPtr, 'PHP keyword case', 'upper' );
119 119
             } else {
120
-                $phpcsFile->recordMetric($stackPtr, 'PHP keyword case', 'mixed');
120
+                $phpcsFile->recordMetric( $stackPtr, 'PHP keyword case', 'mixed' );
121 121
             }
122 122
 
123
-            $messageKeyword = Util\Common::prepareForOutput($keyword);
123
+            $messageKeyword = Util\Common::prepareForOutput( $keyword );
124 124
 
125 125
             $error = 'PHP keywords must be lowercase; expected "%s" but found "%s"';
126 126
             $data  = [
127
-                strtolower($messageKeyword),
127
+                strtolower( $messageKeyword ),
128 128
                 $messageKeyword,
129 129
             ];
130 130
 
131
-            $fix = $phpcsFile->addFixableError($error, $stackPtr, 'Found', $data);
132
-            if ($fix === true) {
133
-                $phpcsFile->fixer->replaceToken($stackPtr, strtolower($keyword));
131
+            $fix = $phpcsFile->addFixableError( $error, $stackPtr, 'Found', $data );
132
+            if ( $fix === true ) {
133
+                $phpcsFile->fixer->replaceToken( $stackPtr, strtolower( $keyword ) );
134 134
             }
135 135
         } else {
136
-            $phpcsFile->recordMetric($stackPtr, 'PHP keyword case', 'lower');
136
+            $phpcsFile->recordMetric( $stackPtr, 'PHP keyword case', 'lower' );
137 137
         }//end if
138 138
 
139 139
     }//end process()
Please login to merge, or discard this patch.
Braces   +3 added lines, -6 removed lines patch added patch discarded remove patch
@@ -13,8 +13,7 @@  discard block
 block discarded – undo
13 13
 use PHP_CodeSniffer\Files\File;
14 14
 use PHP_CodeSniffer\Util;
15 15
 
16
-class LowerCaseKeywordSniff implements Sniff
17
-{
16
+class LowerCaseKeywordSniff implements Sniff {
18 17
 
19 18
 
20 19
     /**
@@ -22,8 +21,7 @@  discard block
 block discarded – undo
22 21
      *
23 22
      * @return array
24 23
      */
25
-    public function register()
26
-    {
24
+    public function register() {
27 25
         return [
28 26
             T_HALT_COMPILER,
29 27
             T_ABSTRACT,
@@ -109,8 +107,7 @@  discard block
 block discarded – undo
109 107
      *
110 108
      * @return void
111 109
      */
112
-    public function process(File $phpcsFile, $stackPtr)
113
-    {
110
+    public function process(File $phpcsFile, $stackPtr) {
114 111
         $tokens  = $phpcsFile->getTokens();
115 112
         $keyword = $tokens[$stackPtr]['content'];
116 113
         if (strtolower($keyword) !== $keyword) {
Please login to merge, or discard this patch.
php_codesniffer/src/Standards/Generic/Sniffs/PHP/UpperCaseConstantSniff.php 3 patches
Indentation   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -16,58 +16,58 @@
 block discarded – undo
16 16
 {
17 17
 
18 18
 
19
-    /**
20
-     * Returns an array of tokens this test wants to listen for.
21
-     *
22
-     * @return array
23
-     */
24
-    public function register()
25
-    {
26
-        return [
27
-            T_TRUE,
28
-            T_FALSE,
29
-            T_NULL,
30
-        ];
19
+	/**
20
+	 * Returns an array of tokens this test wants to listen for.
21
+	 *
22
+	 * @return array
23
+	 */
24
+	public function register()
25
+	{
26
+		return [
27
+			T_TRUE,
28
+			T_FALSE,
29
+			T_NULL,
30
+		];
31 31
 
32
-    }//end register()
32
+	}//end register()
33 33
 
34 34
 
35
-    /**
36
-     * Processes this sniff, when one of its tokens is encountered.
37
-     *
38
-     * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.
39
-     * @param int                         $stackPtr  The position of the current token in the
40
-     *                                               stack passed in $tokens.
41
-     *
42
-     * @return void
43
-     */
44
-    public function process(File $phpcsFile, $stackPtr)
45
-    {
46
-        $tokens   = $phpcsFile->getTokens();
47
-        $keyword  = $tokens[$stackPtr]['content'];
48
-        $expected = strtoupper($keyword);
49
-        if ($keyword !== $expected) {
50
-            if ($keyword === strtolower($keyword)) {
51
-                $phpcsFile->recordMetric($stackPtr, 'PHP constant case', 'lower');
52
-            } else {
53
-                $phpcsFile->recordMetric($stackPtr, 'PHP constant case', 'mixed');
54
-            }
35
+	/**
36
+	 * Processes this sniff, when one of its tokens is encountered.
37
+	 *
38
+	 * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.
39
+	 * @param int                         $stackPtr  The position of the current token in the
40
+	 *                                               stack passed in $tokens.
41
+	 *
42
+	 * @return void
43
+	 */
44
+	public function process(File $phpcsFile, $stackPtr)
45
+	{
46
+		$tokens   = $phpcsFile->getTokens();
47
+		$keyword  = $tokens[$stackPtr]['content'];
48
+		$expected = strtoupper($keyword);
49
+		if ($keyword !== $expected) {
50
+			if ($keyword === strtolower($keyword)) {
51
+				$phpcsFile->recordMetric($stackPtr, 'PHP constant case', 'lower');
52
+			} else {
53
+				$phpcsFile->recordMetric($stackPtr, 'PHP constant case', 'mixed');
54
+			}
55 55
 
56
-            $error = 'TRUE, FALSE and NULL must be uppercase; expected "%s" but found "%s"';
57
-            $data  = [
58
-                $expected,
59
-                $keyword,
60
-            ];
56
+			$error = 'TRUE, FALSE and NULL must be uppercase; expected "%s" but found "%s"';
57
+			$data  = [
58
+				$expected,
59
+				$keyword,
60
+			];
61 61
 
62
-            $fix = $phpcsFile->addFixableError($error, $stackPtr, 'Found', $data);
63
-            if ($fix === true) {
64
-                $phpcsFile->fixer->replaceToken($stackPtr, $expected);
65
-            }
66
-        } else {
67
-            $phpcsFile->recordMetric($stackPtr, 'PHP constant case', 'upper');
68
-        }
62
+			$fix = $phpcsFile->addFixableError($error, $stackPtr, 'Found', $data);
63
+			if ($fix === true) {
64
+				$phpcsFile->fixer->replaceToken($stackPtr, $expected);
65
+			}
66
+		} else {
67
+			$phpcsFile->recordMetric($stackPtr, 'PHP constant case', 'upper');
68
+		}
69 69
 
70
-    }//end process()
70
+	}//end process()
71 71
 
72 72
 
73 73
 }//end class
Please login to merge, or discard this patch.
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -41,16 +41,16 @@  discard block
 block discarded – undo
41 41
      *
42 42
      * @return void
43 43
      */
44
-    public function process(File $phpcsFile, $stackPtr)
44
+    public function process( File $phpcsFile, $stackPtr )
45 45
     {
46 46
         $tokens   = $phpcsFile->getTokens();
47
-        $keyword  = $tokens[$stackPtr]['content'];
48
-        $expected = strtoupper($keyword);
49
-        if ($keyword !== $expected) {
50
-            if ($keyword === strtolower($keyword)) {
51
-                $phpcsFile->recordMetric($stackPtr, 'PHP constant case', 'lower');
47
+        $keyword  = $tokens[ $stackPtr ][ 'content' ];
48
+        $expected = strtoupper( $keyword );
49
+        if ( $keyword !== $expected ) {
50
+            if ( $keyword === strtolower( $keyword ) ) {
51
+                $phpcsFile->recordMetric( $stackPtr, 'PHP constant case', 'lower' );
52 52
             } else {
53
-                $phpcsFile->recordMetric($stackPtr, 'PHP constant case', 'mixed');
53
+                $phpcsFile->recordMetric( $stackPtr, 'PHP constant case', 'mixed' );
54 54
             }
55 55
 
56 56
             $error = 'TRUE, FALSE and NULL must be uppercase; expected "%s" but found "%s"';
@@ -59,12 +59,12 @@  discard block
 block discarded – undo
59 59
                 $keyword,
60 60
             ];
61 61
 
62
-            $fix = $phpcsFile->addFixableError($error, $stackPtr, 'Found', $data);
63
-            if ($fix === true) {
64
-                $phpcsFile->fixer->replaceToken($stackPtr, $expected);
62
+            $fix = $phpcsFile->addFixableError( $error, $stackPtr, 'Found', $data );
63
+            if ( $fix === true ) {
64
+                $phpcsFile->fixer->replaceToken( $stackPtr, $expected );
65 65
             }
66 66
         } else {
67
-            $phpcsFile->recordMetric($stackPtr, 'PHP constant case', 'upper');
67
+            $phpcsFile->recordMetric( $stackPtr, 'PHP constant case', 'upper' );
68 68
         }
69 69
 
70 70
     }//end process()
Please login to merge, or discard this patch.
Braces   +3 added lines, -6 removed lines patch added patch discarded remove patch
@@ -12,8 +12,7 @@  discard block
 block discarded – undo
12 12
 use PHP_CodeSniffer\Sniffs\Sniff;
13 13
 use PHP_CodeSniffer\Files\File;
14 14
 
15
-class UpperCaseConstantSniff implements Sniff
16
-{
15
+class UpperCaseConstantSniff implements Sniff {
17 16
 
18 17
 
19 18
     /**
@@ -21,8 +20,7 @@  discard block
 block discarded – undo
21 20
      *
22 21
      * @return array
23 22
      */
24
-    public function register()
25
-    {
23
+    public function register() {
26 24
         return [
27 25
             T_TRUE,
28 26
             T_FALSE,
@@ -41,8 +39,7 @@  discard block
 block discarded – undo
41 39
      *
42 40
      * @return void
43 41
      */
44
-    public function process(File $phpcsFile, $stackPtr)
45
-    {
42
+    public function process(File $phpcsFile, $stackPtr) {
46 43
         $tokens   = $phpcsFile->getTokens();
47 44
         $keyword  = $tokens[$stackPtr]['content'];
48 45
         $expected = strtoupper($keyword);
Please login to merge, or discard this patch.
squizlabs/php_codesniffer/src/Standards/Generic/Sniffs/PHP/SyntaxSniff.php 3 patches
Indentation   +41 added lines, -41 removed lines patch added patch discarded remove patch
@@ -17,55 +17,55 @@
 block discarded – undo
17 17
 class SyntaxSniff implements Sniff
18 18
 {
19 19
 
20
-    /**
21
-     * The path to the PHP version we are checking with.
22
-     *
23
-     * @var string
24
-     */
25
-    private $phpPath = null;
20
+	/**
21
+	 * The path to the PHP version we are checking with.
22
+	 *
23
+	 * @var string
24
+	 */
25
+	private $phpPath = null;
26 26
 
27 27
 
28
-    /**
29
-     * Returns an array of tokens this test wants to listen for.
30
-     *
31
-     * @return array
32
-     */
33
-    public function register()
34
-    {
35
-        return [T_OPEN_TAG];
28
+	/**
29
+	 * Returns an array of tokens this test wants to listen for.
30
+	 *
31
+	 * @return array
32
+	 */
33
+	public function register()
34
+	{
35
+		return [T_OPEN_TAG];
36 36
 
37
-    }//end register()
37
+	}//end register()
38 38
 
39 39
 
40
-    /**
41
-     * Processes this test, when one of its tokens is encountered.
42
-     *
43
-     * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.
44
-     * @param int                         $stackPtr  The position of the current token in
45
-     *                                               the stack passed in $tokens.
46
-     *
47
-     * @return void
48
-     */
49
-    public function process(File $phpcsFile, $stackPtr)
50
-    {
51
-        if ($this->phpPath === null) {
52
-            $this->phpPath = Config::getExecutablePath('php');
53
-        }
40
+	/**
41
+	 * Processes this test, when one of its tokens is encountered.
42
+	 *
43
+	 * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.
44
+	 * @param int                         $stackPtr  The position of the current token in
45
+	 *                                               the stack passed in $tokens.
46
+	 *
47
+	 * @return void
48
+	 */
49
+	public function process(File $phpcsFile, $stackPtr)
50
+	{
51
+		if ($this->phpPath === null) {
52
+			$this->phpPath = Config::getExecutablePath('php');
53
+		}
54 54
 
55
-        $fileName = escapeshellarg($phpcsFile->getFilename());
56
-        $cmd      = escapeshellcmd($this->phpPath)." -l -d display_errors=1 -d error_prepend_string='' $fileName 2>&1";
57
-        $output   = shell_exec($cmd);
58
-        $matches  = [];
59
-        if (preg_match('/^.*error:(.*) in .* on line ([0-9]+)/m', trim($output), $matches) === 1) {
60
-            $error = trim($matches[1]);
61
-            $line  = (int) $matches[2];
62
-            $phpcsFile->addErrorOnLine("PHP syntax error: $error", $line, 'PHPSyntax');
63
-        }
55
+		$fileName = escapeshellarg($phpcsFile->getFilename());
56
+		$cmd      = escapeshellcmd($this->phpPath)." -l -d display_errors=1 -d error_prepend_string='' $fileName 2>&1";
57
+		$output   = shell_exec($cmd);
58
+		$matches  = [];
59
+		if (preg_match('/^.*error:(.*) in .* on line ([0-9]+)/m', trim($output), $matches) === 1) {
60
+			$error = trim($matches[1]);
61
+			$line  = (int) $matches[2];
62
+			$phpcsFile->addErrorOnLine("PHP syntax error: $error", $line, 'PHPSyntax');
63
+		}
64 64
 
65
-        // Ignore the rest of the file.
66
-        return ($phpcsFile->numTokens + 1);
65
+		// Ignore the rest of the file.
66
+		return ($phpcsFile->numTokens + 1);
67 67
 
68
-    }//end process()
68
+	}//end process()
69 69
 
70 70
 
71 71
 }//end class
Please login to merge, or discard this patch.
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -32,7 +32,7 @@  discard block
 block discarded – undo
32 32
      */
33 33
     public function register()
34 34
     {
35
-        return [T_OPEN_TAG];
35
+        return [ T_OPEN_TAG ];
36 36
 
37 37
     }//end register()
38 38
 
@@ -46,24 +46,24 @@  discard block
 block discarded – undo
46 46
      *
47 47
      * @return void
48 48
      */
49
-    public function process(File $phpcsFile, $stackPtr)
49
+    public function process( File $phpcsFile, $stackPtr )
50 50
     {
51
-        if ($this->phpPath === null) {
52
-            $this->phpPath = Config::getExecutablePath('php');
51
+        if ( $this->phpPath === null ) {
52
+            $this->phpPath = Config::getExecutablePath( 'php' );
53 53
         }
54 54
 
55
-        $fileName = escapeshellarg($phpcsFile->getFilename());
56
-        $cmd      = escapeshellcmd($this->phpPath)." -l -d display_errors=1 -d error_prepend_string='' $fileName 2>&1";
57
-        $output   = shell_exec($cmd);
58
-        $matches  = [];
59
-        if (preg_match('/^.*error:(.*) in .* on line ([0-9]+)/m', trim($output), $matches) === 1) {
60
-            $error = trim($matches[1]);
61
-            $line  = (int) $matches[2];
62
-            $phpcsFile->addErrorOnLine("PHP syntax error: $error", $line, 'PHPSyntax');
55
+        $fileName = escapeshellarg( $phpcsFile->getFilename() );
56
+        $cmd      = escapeshellcmd( $this->phpPath ) . " -l -d display_errors=1 -d error_prepend_string='' $fileName 2>&1";
57
+        $output   = shell_exec( $cmd );
58
+        $matches  = [ ];
59
+        if ( preg_match( '/^.*error:(.*) in .* on line ([0-9]+)/m', trim( $output ), $matches ) === 1 ) {
60
+            $error = trim( $matches[ 1 ] );
61
+            $line  = (int)$matches[ 2 ];
62
+            $phpcsFile->addErrorOnLine( "PHP syntax error: $error", $line, 'PHPSyntax' );
63 63
         }
64 64
 
65 65
         // Ignore the rest of the file.
66
-        return ($phpcsFile->numTokens + 1);
66
+        return ( $phpcsFile->numTokens + 1 );
67 67
 
68 68
     }//end process()
69 69
 
Please login to merge, or discard this patch.
Braces   +3 added lines, -6 removed lines patch added patch discarded remove patch
@@ -14,8 +14,7 @@  discard block
 block discarded – undo
14 14
 use PHP_CodeSniffer\Files\File;
15 15
 use PHP_CodeSniffer\Config;
16 16
 
17
-class SyntaxSniff implements Sniff
18
-{
17
+class SyntaxSniff implements Sniff {
19 18
 
20 19
     /**
21 20
      * The path to the PHP version we are checking with.
@@ -30,8 +29,7 @@  discard block
 block discarded – undo
30 29
      *
31 30
      * @return array
32 31
      */
33
-    public function register()
34
-    {
32
+    public function register() {
35 33
         return [T_OPEN_TAG];
36 34
 
37 35
     }//end register()
@@ -46,8 +44,7 @@  discard block
 block discarded – undo
46 44
      *
47 45
      * @return void
48 46
      */
49
-    public function process(File $phpcsFile, $stackPtr)
50
-    {
47
+    public function process(File $phpcsFile, $stackPtr) {
51 48
         if ($this->phpPath === null) {
52 49
             $this->phpPath = Config::getExecutablePath('php');
53 50
         }
Please login to merge, or discard this patch.
src/Standards/Generic/Sniffs/PHP/DisallowShortOpenTagSniff.php 3 patches
Indentation   +146 added lines, -146 removed lines patch added patch discarded remove patch
@@ -17,152 +17,152 @@
 block discarded – undo
17 17
 {
18 18
 
19 19
 
20
-    /**
21
-     * Returns an array of tokens this test wants to listen for.
22
-     *
23
-     * @return array
24
-     */
25
-    public function register()
26
-    {
27
-        $targets = [
28
-            T_OPEN_TAG,
29
-            T_OPEN_TAG_WITH_ECHO,
30
-        ];
31
-
32
-        $shortOpenTags = (bool) ini_get('short_open_tag');
33
-        if ($shortOpenTags === false) {
34
-            $targets[] = T_INLINE_HTML;
35
-        }
36
-
37
-        return $targets;
38
-
39
-    }//end register()
40
-
41
-
42
-    /**
43
-     * Processes this test, when one of its tokens is encountered.
44
-     *
45
-     * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.
46
-     * @param int                         $stackPtr  The position of the current token
47
-     *                                               in the stack passed in $tokens.
48
-     *
49
-     * @return void
50
-     */
51
-    public function process(File $phpcsFile, $stackPtr)
52
-    {
53
-        $tokens = $phpcsFile->getTokens();
54
-        $token  = $tokens[$stackPtr];
55
-
56
-        if ($token['code'] === T_OPEN_TAG && $token['content'] === '<?') {
57
-            $error = 'Short PHP opening tag used; expected "<?php" but found "%s"';
58
-            $data  = [$token['content']];
59
-            $fix   = $phpcsFile->addFixableError($error, $stackPtr, 'Found', $data);
60
-            if ($fix === true) {
61
-                $correctOpening = '<?php';
62
-                if (isset($tokens[($stackPtr + 1)]) === true && $tokens[($stackPtr + 1)]['code'] !== T_WHITESPACE) {
63
-                    // Avoid creation of invalid open tags like <?phpecho if the original was <?echo .
64
-                    $correctOpening .= ' ';
65
-                }
66
-
67
-                $phpcsFile->fixer->replaceToken($stackPtr, $correctOpening);
68
-            }
69
-
70
-            $phpcsFile->recordMetric($stackPtr, 'PHP short open tag used', 'yes');
71
-        } else {
72
-            $phpcsFile->recordMetric($stackPtr, 'PHP short open tag used', 'no');
73
-        }
74
-
75
-        if ($token['code'] === T_OPEN_TAG_WITH_ECHO) {
76
-            $nextVar = $tokens[$phpcsFile->findNext(Tokens::$emptyTokens, ($stackPtr + 1), null, true)];
77
-            $error   = 'Short PHP opening tag used with echo; expected "<?php echo %s ..." but found "%s %s ..."';
78
-            $data    = [
79
-                $nextVar['content'],
80
-                $token['content'],
81
-                $nextVar['content'],
82
-            ];
83
-            $fix     = $phpcsFile->addFixableError($error, $stackPtr, 'EchoFound', $data);
84
-            if ($fix === true) {
85
-                if ($tokens[($stackPtr + 1)]['code'] !== T_WHITESPACE) {
86
-                    $phpcsFile->fixer->replaceToken($stackPtr, '<?php echo ');
87
-                } else {
88
-                    $phpcsFile->fixer->replaceToken($stackPtr, '<?php echo');
89
-                }
90
-            }
91
-        }
92
-
93
-        if ($token['code'] === T_INLINE_HTML) {
94
-            $content     = $token['content'];
95
-            $openerFound = strpos($content, '<?');
96
-
97
-            if ($openerFound === false) {
98
-                return;
99
-            }
100
-
101
-            $closerFound = false;
102
-
103
-            // Inspect current token and subsequent inline HTML token to find a close tag.
104
-            for ($i = $stackPtr; $i < $phpcsFile->numTokens; $i++) {
105
-                if ($tokens[$i]['code'] !== T_INLINE_HTML) {
106
-                    break;
107
-                }
108
-
109
-                $closerFound = strrpos($tokens[$i]['content'], '?>');
110
-                if ($closerFound !== false) {
111
-                    if ($i !== $stackPtr) {
112
-                        break;
113
-                    } else if ($closerFound > $openerFound) {
114
-                        break;
115
-                    } else {
116
-                        $closerFound = false;
117
-                    }
118
-                }
119
-            }
120
-
121
-            if ($closerFound !== false) {
122
-                $error   = 'Possible use of short open tags detected; found: %s';
123
-                $snippet = $this->getSnippet($content, '<?');
124
-                $data    = ['<?'.$snippet];
125
-
126
-                $phpcsFile->addWarning($error, $stackPtr, 'PossibleFound', $data);
127
-
128
-                // Skip forward to the token containing the closer.
129
-                if (($i - 1) > $stackPtr) {
130
-                    return $i;
131
-                }
132
-            }
133
-        }//end if
134
-
135
-    }//end process()
136
-
137
-
138
-    /**
139
-     * Get a snippet from a HTML token.
140
-     *
141
-     * @param string $content The content of the HTML token.
142
-     * @param string $start   Partial string to use as a starting point for the snippet.
143
-     * @param int    $length  The target length of the snippet to get. Defaults to 40.
144
-     *
145
-     * @return string
146
-     */
147
-    protected function getSnippet($content, $start='', $length=40)
148
-    {
149
-        $startPos = 0;
150
-
151
-        if ($start !== '') {
152
-            $startPos = strpos($content, $start);
153
-            if ($startPos !== false) {
154
-                $startPos += strlen($start);
155
-            }
156
-        }
157
-
158
-        $snippet = substr($content, $startPos, $length);
159
-        if ((strlen($content) - $startPos) > $length) {
160
-            $snippet .= '...';
161
-        }
162
-
163
-        return $snippet;
164
-
165
-    }//end getSnippet()
20
+	/**
21
+	 * Returns an array of tokens this test wants to listen for.
22
+	 *
23
+	 * @return array
24
+	 */
25
+	public function register()
26
+	{
27
+		$targets = [
28
+			T_OPEN_TAG,
29
+			T_OPEN_TAG_WITH_ECHO,
30
+		];
31
+
32
+		$shortOpenTags = (bool) ini_get('short_open_tag');
33
+		if ($shortOpenTags === false) {
34
+			$targets[] = T_INLINE_HTML;
35
+		}
36
+
37
+		return $targets;
38
+
39
+	}//end register()
40
+
41
+
42
+	/**
43
+	 * Processes this test, when one of its tokens is encountered.
44
+	 *
45
+	 * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.
46
+	 * @param int                         $stackPtr  The position of the current token
47
+	 *                                               in the stack passed in $tokens.
48
+	 *
49
+	 * @return void
50
+	 */
51
+	public function process(File $phpcsFile, $stackPtr)
52
+	{
53
+		$tokens = $phpcsFile->getTokens();
54
+		$token  = $tokens[$stackPtr];
55
+
56
+		if ($token['code'] === T_OPEN_TAG && $token['content'] === '<?') {
57
+			$error = 'Short PHP opening tag used; expected "<?php" but found "%s"';
58
+			$data  = [$token['content']];
59
+			$fix   = $phpcsFile->addFixableError($error, $stackPtr, 'Found', $data);
60
+			if ($fix === true) {
61
+				$correctOpening = '<?php';
62
+				if (isset($tokens[($stackPtr + 1)]) === true && $tokens[($stackPtr + 1)]['code'] !== T_WHITESPACE) {
63
+					// Avoid creation of invalid open tags like <?phpecho if the original was <?echo .
64
+					$correctOpening .= ' ';
65
+				}
66
+
67
+				$phpcsFile->fixer->replaceToken($stackPtr, $correctOpening);
68
+			}
69
+
70
+			$phpcsFile->recordMetric($stackPtr, 'PHP short open tag used', 'yes');
71
+		} else {
72
+			$phpcsFile->recordMetric($stackPtr, 'PHP short open tag used', 'no');
73
+		}
74
+
75
+		if ($token['code'] === T_OPEN_TAG_WITH_ECHO) {
76
+			$nextVar = $tokens[$phpcsFile->findNext(Tokens::$emptyTokens, ($stackPtr + 1), null, true)];
77
+			$error   = 'Short PHP opening tag used with echo; expected "<?php echo %s ..." but found "%s %s ..."';
78
+			$data    = [
79
+				$nextVar['content'],
80
+				$token['content'],
81
+				$nextVar['content'],
82
+			];
83
+			$fix     = $phpcsFile->addFixableError($error, $stackPtr, 'EchoFound', $data);
84
+			if ($fix === true) {
85
+				if ($tokens[($stackPtr + 1)]['code'] !== T_WHITESPACE) {
86
+					$phpcsFile->fixer->replaceToken($stackPtr, '<?php echo ');
87
+				} else {
88
+					$phpcsFile->fixer->replaceToken($stackPtr, '<?php echo');
89
+				}
90
+			}
91
+		}
92
+
93
+		if ($token['code'] === T_INLINE_HTML) {
94
+			$content     = $token['content'];
95
+			$openerFound = strpos($content, '<?');
96
+
97
+			if ($openerFound === false) {
98
+				return;
99
+			}
100
+
101
+			$closerFound = false;
102
+
103
+			// Inspect current token and subsequent inline HTML token to find a close tag.
104
+			for ($i = $stackPtr; $i < $phpcsFile->numTokens; $i++) {
105
+				if ($tokens[$i]['code'] !== T_INLINE_HTML) {
106
+					break;
107
+				}
108
+
109
+				$closerFound = strrpos($tokens[$i]['content'], '?>');
110
+				if ($closerFound !== false) {
111
+					if ($i !== $stackPtr) {
112
+						break;
113
+					} else if ($closerFound > $openerFound) {
114
+						break;
115
+					} else {
116
+						$closerFound = false;
117
+					}
118
+				}
119
+			}
120
+
121
+			if ($closerFound !== false) {
122
+				$error   = 'Possible use of short open tags detected; found: %s';
123
+				$snippet = $this->getSnippet($content, '<?');
124
+				$data    = ['<?'.$snippet];
125
+
126
+				$phpcsFile->addWarning($error, $stackPtr, 'PossibleFound', $data);
127
+
128
+				// Skip forward to the token containing the closer.
129
+				if (($i - 1) > $stackPtr) {
130
+					return $i;
131
+				}
132
+			}
133
+		}//end if
134
+
135
+	}//end process()
136
+
137
+
138
+	/**
139
+	 * Get a snippet from a HTML token.
140
+	 *
141
+	 * @param string $content The content of the HTML token.
142
+	 * @param string $start   Partial string to use as a starting point for the snippet.
143
+	 * @param int    $length  The target length of the snippet to get. Defaults to 40.
144
+	 *
145
+	 * @return string
146
+	 */
147
+	protected function getSnippet($content, $start='', $length=40)
148
+	{
149
+		$startPos = 0;
150
+
151
+		if ($start !== '') {
152
+			$startPos = strpos($content, $start);
153
+			if ($startPos !== false) {
154
+				$startPos += strlen($start);
155
+			}
156
+		}
157
+
158
+		$snippet = substr($content, $startPos, $length);
159
+		if ((strlen($content) - $startPos) > $length) {
160
+			$snippet .= '...';
161
+		}
162
+
163
+		return $snippet;
164
+
165
+	}//end getSnippet()
166 166
 
167 167
 
168 168
 }//end class
Please login to merge, or discard this patch.
Spacing   +45 added lines, -45 removed lines patch added patch discarded remove patch
@@ -29,9 +29,9 @@  discard block
 block discarded – undo
29 29
             T_OPEN_TAG_WITH_ECHO,
30 30
         ];
31 31
 
32
-        $shortOpenTags = (bool) ini_get('short_open_tag');
33
-        if ($shortOpenTags === false) {
34
-            $targets[] = T_INLINE_HTML;
32
+        $shortOpenTags = (bool)ini_get( 'short_open_tag' );
33
+        if ( $shortOpenTags === false ) {
34
+            $targets[ ] = T_INLINE_HTML;
35 35
         }
36 36
 
37 37
         return $targets;
@@ -48,69 +48,69 @@  discard block
 block discarded – undo
48 48
      *
49 49
      * @return void
50 50
      */
51
-    public function process(File $phpcsFile, $stackPtr)
51
+    public function process( File $phpcsFile, $stackPtr )
52 52
     {
53 53
         $tokens = $phpcsFile->getTokens();
54
-        $token  = $tokens[$stackPtr];
54
+        $token  = $tokens[ $stackPtr ];
55 55
 
56
-        if ($token['code'] === T_OPEN_TAG && $token['content'] === '<?') {
56
+        if ( $token[ 'code' ] === T_OPEN_TAG && $token[ 'content' ] === '<?' ) {
57 57
             $error = 'Short PHP opening tag used; expected "<?php" but found "%s"';
58
-            $data  = [$token['content']];
59
-            $fix   = $phpcsFile->addFixableError($error, $stackPtr, 'Found', $data);
60
-            if ($fix === true) {
58
+            $data  = [ $token[ 'content' ] ];
59
+            $fix   = $phpcsFile->addFixableError( $error, $stackPtr, 'Found', $data );
60
+            if ( $fix === true ) {
61 61
                 $correctOpening = '<?php';
62
-                if (isset($tokens[($stackPtr + 1)]) === true && $tokens[($stackPtr + 1)]['code'] !== T_WHITESPACE) {
62
+                if ( isset( $tokens[ ( $stackPtr + 1 ) ] ) === true && $tokens[ ( $stackPtr + 1 ) ][ 'code' ] !== T_WHITESPACE ) {
63 63
                     // Avoid creation of invalid open tags like <?phpecho if the original was <?echo .
64 64
                     $correctOpening .= ' ';
65 65
                 }
66 66
 
67
-                $phpcsFile->fixer->replaceToken($stackPtr, $correctOpening);
67
+                $phpcsFile->fixer->replaceToken( $stackPtr, $correctOpening );
68 68
             }
69 69
 
70
-            $phpcsFile->recordMetric($stackPtr, 'PHP short open tag used', 'yes');
70
+            $phpcsFile->recordMetric( $stackPtr, 'PHP short open tag used', 'yes' );
71 71
         } else {
72
-            $phpcsFile->recordMetric($stackPtr, 'PHP short open tag used', 'no');
72
+            $phpcsFile->recordMetric( $stackPtr, 'PHP short open tag used', 'no' );
73 73
         }
74 74
 
75
-        if ($token['code'] === T_OPEN_TAG_WITH_ECHO) {
76
-            $nextVar = $tokens[$phpcsFile->findNext(Tokens::$emptyTokens, ($stackPtr + 1), null, true)];
75
+        if ( $token[ 'code' ] === T_OPEN_TAG_WITH_ECHO ) {
76
+            $nextVar = $tokens[ $phpcsFile->findNext( Tokens::$emptyTokens, ( $stackPtr + 1 ), null, true ) ];
77 77
             $error   = 'Short PHP opening tag used with echo; expected "<?php echo %s ..." but found "%s %s ..."';
78 78
             $data    = [
79
-                $nextVar['content'],
80
-                $token['content'],
81
-                $nextVar['content'],
79
+                $nextVar[ 'content' ],
80
+                $token[ 'content' ],
81
+                $nextVar[ 'content' ],
82 82
             ];
83
-            $fix     = $phpcsFile->addFixableError($error, $stackPtr, 'EchoFound', $data);
84
-            if ($fix === true) {
85
-                if ($tokens[($stackPtr + 1)]['code'] !== T_WHITESPACE) {
86
-                    $phpcsFile->fixer->replaceToken($stackPtr, '<?php echo ');
83
+            $fix = $phpcsFile->addFixableError( $error, $stackPtr, 'EchoFound', $data );
84
+            if ( $fix === true ) {
85
+                if ( $tokens[ ( $stackPtr + 1 ) ][ 'code' ] !== T_WHITESPACE ) {
86
+                    $phpcsFile->fixer->replaceToken( $stackPtr, '<?php echo ' );
87 87
                 } else {
88
-                    $phpcsFile->fixer->replaceToken($stackPtr, '<?php echo');
88
+                    $phpcsFile->fixer->replaceToken( $stackPtr, '<?php echo' );
89 89
                 }
90 90
             }
91 91
         }
92 92
 
93
-        if ($token['code'] === T_INLINE_HTML) {
94
-            $content     = $token['content'];
95
-            $openerFound = strpos($content, '<?');
93
+        if ( $token[ 'code' ] === T_INLINE_HTML ) {
94
+            $content     = $token[ 'content' ];
95
+            $openerFound = strpos( $content, '<?' );
96 96
 
97
-            if ($openerFound === false) {
97
+            if ( $openerFound === false ) {
98 98
                 return;
99 99
             }
100 100
 
101 101
             $closerFound = false;
102 102
 
103 103
             // Inspect current token and subsequent inline HTML token to find a close tag.
104
-            for ($i = $stackPtr; $i < $phpcsFile->numTokens; $i++) {
105
-                if ($tokens[$i]['code'] !== T_INLINE_HTML) {
104
+            for ( $i = $stackPtr; $i < $phpcsFile->numTokens; $i++ ) {
105
+                if ( $tokens[ $i ][ 'code' ] !== T_INLINE_HTML ) {
106 106
                     break;
107 107
                 }
108 108
 
109
-                $closerFound = strrpos($tokens[$i]['content'], '?>');
110
-                if ($closerFound !== false) {
111
-                    if ($i !== $stackPtr) {
109
+                $closerFound = strrpos( $tokens[ $i ][ 'content' ], '?>' );
110
+                if ( $closerFound !== false ) {
111
+                    if ( $i !== $stackPtr ) {
112 112
                         break;
113
-                    } else if ($closerFound > $openerFound) {
113
+                    } else if ( $closerFound > $openerFound ) {
114 114
                         break;
115 115
                     } else {
116 116
                         $closerFound = false;
@@ -118,15 +118,15 @@  discard block
 block discarded – undo
118 118
                 }
119 119
             }
120 120
 
121
-            if ($closerFound !== false) {
121
+            if ( $closerFound !== false ) {
122 122
                 $error   = 'Possible use of short open tags detected; found: %s';
123
-                $snippet = $this->getSnippet($content, '<?');
124
-                $data    = ['<?'.$snippet];
123
+                $snippet = $this->getSnippet( $content, '<?' );
124
+                $data    = [ '<?' . $snippet ];
125 125
 
126
-                $phpcsFile->addWarning($error, $stackPtr, 'PossibleFound', $data);
126
+                $phpcsFile->addWarning( $error, $stackPtr, 'PossibleFound', $data );
127 127
 
128 128
                 // Skip forward to the token containing the closer.
129
-                if (($i - 1) > $stackPtr) {
129
+                if ( ( $i - 1 ) > $stackPtr ) {
130 130
                     return $i;
131 131
                 }
132 132
             }
@@ -144,19 +144,19 @@  discard block
 block discarded – undo
144 144
      *
145 145
      * @return string
146 146
      */
147
-    protected function getSnippet($content, $start='', $length=40)
147
+    protected function getSnippet( $content, $start = '', $length = 40 )
148 148
     {
149 149
         $startPos = 0;
150 150
 
151
-        if ($start !== '') {
152
-            $startPos = strpos($content, $start);
153
-            if ($startPos !== false) {
154
-                $startPos += strlen($start);
151
+        if ( $start !== '' ) {
152
+            $startPos = strpos( $content, $start );
153
+            if ( $startPos !== false ) {
154
+                $startPos += strlen( $start );
155 155
             }
156 156
         }
157 157
 
158
-        $snippet = substr($content, $startPos, $length);
159
-        if ((strlen($content) - $startPos) > $length) {
158
+        $snippet = substr( $content, $startPos, $length );
159
+        if ( ( strlen( $content ) - $startPos ) > $length ) {
160 160
             $snippet .= '...';
161 161
         }
162 162
 
Please login to merge, or discard this patch.
Braces   +4 added lines, -8 removed lines patch added patch discarded remove patch
@@ -13,8 +13,7 @@  discard block
 block discarded – undo
13 13
 use PHP_CodeSniffer\Files\File;
14 14
 use PHP_CodeSniffer\Util\Tokens;
15 15
 
16
-class DisallowShortOpenTagSniff implements Sniff
17
-{
16
+class DisallowShortOpenTagSniff implements Sniff {
18 17
 
19 18
 
20 19
     /**
@@ -22,8 +21,7 @@  discard block
 block discarded – undo
22 21
      *
23 22
      * @return array
24 23
      */
25
-    public function register()
26
-    {
24
+    public function register() {
27 25
         $targets = [
28 26
             T_OPEN_TAG,
29 27
             T_OPEN_TAG_WITH_ECHO,
@@ -48,8 +46,7 @@  discard block
 block discarded – undo
48 46
      *
49 47
      * @return void
50 48
      */
51
-    public function process(File $phpcsFile, $stackPtr)
52
-    {
49
+    public function process(File $phpcsFile, $stackPtr) {
53 50
         $tokens = $phpcsFile->getTokens();
54 51
         $token  = $tokens[$stackPtr];
55 52
 
@@ -144,8 +141,7 @@  discard block
 block discarded – undo
144 141
      *
145 142
      * @return string
146 143
      */
147
-    protected function getSnippet($content, $start='', $length=40)
148
-    {
144
+    protected function getSnippet($content, $start='', $length=40) {
149 145
         $startPos = 0;
150 146
 
151 147
         if ($start !== '') {
Please login to merge, or discard this patch.