Completed
Branch dev (e59588)
by
unknown
29:01 queued 21:36
created
src/Standards/PEAR/Tests/Commenting/ClassCommentUnitTest.php 1 patch
Indentation   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -15,56 +15,56 @@
 block discarded – undo
15 15
 {
16 16
 
17 17
 
18
-    /**
19
-     * Returns the lines where errors should occur.
20
-     *
21
-     * The key of the array should represent the line number and the value
22
-     * should represent the number of errors that should occur on that line.
23
-     *
24
-     * @return array<int, int>
25
-     */
26
-    public function getErrorList()
27
-    {
28
-        return [
29
-            4   => 1,
30
-            15  => 1,
31
-            51  => 1,
32
-            63  => 1,
33
-            65  => 2,
34
-            66  => 1,
35
-            68  => 1,
36
-            70  => 1,
37
-            71  => 1,
38
-            72  => 1,
39
-            74  => 2,
40
-            75  => 1,
41
-            76  => 1,
42
-            77  => 1,
43
-            85  => 1,
44
-            96  => 5,
45
-            106 => 5,
46
-            116 => 5,
47
-        ];
18
+	/**
19
+	 * Returns the lines where errors should occur.
20
+	 *
21
+	 * The key of the array should represent the line number and the value
22
+	 * should represent the number of errors that should occur on that line.
23
+	 *
24
+	 * @return array<int, int>
25
+	 */
26
+	public function getErrorList()
27
+	{
28
+		return [
29
+			4   => 1,
30
+			15  => 1,
31
+			51  => 1,
32
+			63  => 1,
33
+			65  => 2,
34
+			66  => 1,
35
+			68  => 1,
36
+			70  => 1,
37
+			71  => 1,
38
+			72  => 1,
39
+			74  => 2,
40
+			75  => 1,
41
+			76  => 1,
42
+			77  => 1,
43
+			85  => 1,
44
+			96  => 5,
45
+			106 => 5,
46
+			116 => 5,
47
+		];
48 48
 
49
-    }//end getErrorList()
49
+	}//end getErrorList()
50 50
 
51 51
 
52
-    /**
53
-     * Returns the lines where warnings should occur.
54
-     *
55
-     * The key of the array should represent the line number and the value
56
-     * should represent the number of warnings that should occur on that line.
57
-     *
58
-     * @return array<int, int>
59
-     */
60
-    public function getWarningList()
61
-    {
62
-        return [
63
-            71 => 1,
64
-            73 => 1,
65
-        ];
52
+	/**
53
+	 * Returns the lines where warnings should occur.
54
+	 *
55
+	 * The key of the array should represent the line number and the value
56
+	 * should represent the number of warnings that should occur on that line.
57
+	 *
58
+	 * @return array<int, int>
59
+	 */
60
+	public function getWarningList()
61
+	{
62
+		return [
63
+			71 => 1,
64
+			73 => 1,
65
+		];
66 66
 
67
-    }//end getWarningList()
67
+	}//end getWarningList()
68 68
 
69 69
 
70 70
 }//end class
Please login to merge, or discard this patch.
src/Standards/PEAR/Tests/Commenting/InlineCommentUnitTest.inc 1 patch
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -10,9 +10,9 @@
 block discarded – undo
10 10
  */
11 11
 function test()
12 12
 {
13
-    // Some code goes here.
13
+	// Some code goes here.
14 14
 
15
-    # This comment is banned.
15
+	# This comment is banned.
16 16
 
17 17
 }//end test()
18 18
 
Please login to merge, or discard this patch.
src/Standards/PEAR/Tests/Commenting/InlineCommentUnitTest.php 1 patch
Indentation   +35 added lines, -35 removed lines patch added patch discarded remove patch
@@ -15,41 +15,41 @@
 block discarded – undo
15 15
 {
16 16
 
17 17
 
18
-    /**
19
-     * Returns the lines where errors should occur.
20
-     *
21
-     * The key of the array should represent the line number and the value
22
-     * should represent the number of errors that should occur on that line.
23
-     *
24
-     * @return array<int, int>
25
-     */
26
-    public function getErrorList()
27
-    {
28
-        return [
29
-            15 => 1,
30
-            24 => 1,
31
-            25 => 1,
32
-            27 => 1,
33
-            28 => 1,
34
-            29 => 1,
35
-        ];
36
-
37
-    }//end getErrorList()
38
-
39
-
40
-    /**
41
-     * Returns the lines where warnings should occur.
42
-     *
43
-     * The key of the array should represent the line number and the value
44
-     * should represent the number of warnings that should occur on that line.
45
-     *
46
-     * @return array<int, int>
47
-     */
48
-    public function getWarningList()
49
-    {
50
-        return [];
51
-
52
-    }//end getWarningList()
18
+	/**
19
+	 * Returns the lines where errors should occur.
20
+	 *
21
+	 * The key of the array should represent the line number and the value
22
+	 * should represent the number of errors that should occur on that line.
23
+	 *
24
+	 * @return array<int, int>
25
+	 */
26
+	public function getErrorList()
27
+	{
28
+		return [
29
+			15 => 1,
30
+			24 => 1,
31
+			25 => 1,
32
+			27 => 1,
33
+			28 => 1,
34
+			29 => 1,
35
+		];
36
+
37
+	}//end getErrorList()
38
+
39
+
40
+	/**
41
+	 * Returns the lines where warnings should occur.
42
+	 *
43
+	 * The key of the array should represent the line number and the value
44
+	 * should represent the number of warnings that should occur on that line.
45
+	 *
46
+	 * @return array<int, int>
47
+	 */
48
+	public function getWarningList()
49
+	{
50
+		return [];
51
+
52
+	}//end getWarningList()
53 53
 
54 54
 
55 55
 }//end class
Please login to merge, or discard this patch.
src/Standards/PEAR/Tests/Commenting/FunctionCommentUnitTest.inc 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -14,7 +14,7 @@
 block discarded – undo
14 14
      * @return
15 15
      * @throws
16 16
      */
17
-    private function _functionCall($stackPtr, $depth=1, $index)
17
+    private function _functionCall($stackPtr, $depth = 1, $index)
18 18
     {
19 19
         return $stackPtr;
20 20
 
Please login to merge, or discard this patch.
Indentation   +222 added lines, -222 removed lines patch added patch discarded remove patch
@@ -2,148 +2,148 @@  discard block
 block discarded – undo
2 2
 class PHP_CodeSniffer_File
3 3
 {
4 4
 
5
-    /**
6
-     * A simple function comment.
7
-     *
8
-     * long desc here
9
-     *
10
-     * @param int $stackPtr   The position in @ @unknown the stack of the token
11
-     *                        that opened the scope
12
-     * @param int $detph    How many scope levels down we are.
13
-     * @param int    $index    The index
14
-     * @return
15
-     * @throws
16
-     */
17
-    private function _functionCall($stackPtr, $depth=1, $index)
18
-    {
19
-        return $stackPtr;
20
-
21
-    }//end _functionCall()
22
-
23
-    //
24
-    // Sample function comment
25
-    //
26
-    //
27
-    //
28
-    public function invalidCommentStyle()
29
-    {
30
-
31
-    }//end invalidCommentStyle()
32
-
33
-
34
-    /**
35
-     *
36
-     *
37
-     * A simple function comment
38
-     *
39
-     *
40
-     * Long description with extra blank line before and after
41
-     *
42
-     *
43
-     * @return void
44
-     */
45
-    public function extraDescriptionNewlines()
46
-    {
47
-
48
-    }//end extraDescriptionNewlines()
49
-
50
-
51
-    /**
52
-     * A simple function comment
53
-     * @return void
54
-     */
55
-    public function missingNewlinesBeforeTags()
56
-    {
57
-
58
-    }//end missingNewlinesBeforeTags()
59
-
60
-
61
-    /**
62
-     * Access tag should not be treated as a long description
63
-     *
64
-     * @access public
65
-     * @return void
66
-     */
67
-    public function accessTag()
68
-    {
69
-
70
-    }//end accessTag()
71
-
72
-    /**
73
-     * Constructor
74
-     *
75
-     * No return tag
76
-     */
77
-    function PHP_CodeSniffer_File()
78
-    {
79
-        return;
80
-    }
81
-
82
-
83
-    /**
84
-     * Destructor
85
-     *
86
-     * No return tag too
87
-     */
88
-    function _PHP_CodeSniffer_File()
89
-    {
90
-        return;
91
-    }
92
-
93
-
94
-    /**
95
-     * Destructor PHP5
96
-     */
97
-    function __destruct()
98
-    {
99
-        return;
100
-    }
101
-
102
-
103
-    function missingComment()
104
-    {
105
-        return;
106
-    }
107
-
108
-
109
-    /**
110
-     * no return tag
111
-     *
112
-     */
113
-    public function noReturn($one)
114
-    {
115
-
116
-    }//end noReturn()
117
-
118
-
119
-    /**
120
-     * Param not immediate
121
-     *
122
-     * @return
123
-     * @param   int   $threeSpaces
124
-     * @param int     $superfluous
125
-     * @param missing
126
-     * @param
127
-     */
128
-    public function missingDescription($threeSpaces)
129
-    {
130
-
131
-    }//end missingDescription()
132
-
133
-
134
-    /**
135
-     * Param not immediate
136
-     *
137
-     * @param int      $one   comment
138
-     * @param int      $two   comment
139
-     * @param string   $three comment
140
-     *
141
-     * @return void
142
-     */
143
-    public function oneSpaceAfterLongestVar($one, $two, $three)
144
-    {
145
-
146
-    }//end oneSpaceAfterLongestVar()
5
+	/**
6
+	 * A simple function comment.
7
+	 *
8
+	 * long desc here
9
+	 *
10
+	 * @param int $stackPtr   The position in @ @unknown the stack of the token
11
+	 *                        that opened the scope
12
+	 * @param int $detph    How many scope levels down we are.
13
+	 * @param int    $index    The index
14
+	 * @return
15
+	 * @throws
16
+	 */
17
+	private function _functionCall($stackPtr, $depth=1, $index)
18
+	{
19
+		return $stackPtr;
20
+
21
+	}//end _functionCall()
22
+
23
+	//
24
+	// Sample function comment
25
+	//
26
+	//
27
+	//
28
+	public function invalidCommentStyle()
29
+	{
30
+
31
+	}//end invalidCommentStyle()
32
+
33
+
34
+	/**
35
+	 *
36
+	 *
37
+	 * A simple function comment
38
+	 *
39
+	 *
40
+	 * Long description with extra blank line before and after
41
+	 *
42
+	 *
43
+	 * @return void
44
+	 */
45
+	public function extraDescriptionNewlines()
46
+	{
47
+
48
+	}//end extraDescriptionNewlines()
49
+
50
+
51
+	/**
52
+	 * A simple function comment
53
+	 * @return void
54
+	 */
55
+	public function missingNewlinesBeforeTags()
56
+	{
57
+
58
+	}//end missingNewlinesBeforeTags()
59
+
60
+
61
+	/**
62
+	 * Access tag should not be treated as a long description
63
+	 *
64
+	 * @access public
65
+	 * @return void
66
+	 */
67
+	public function accessTag()
68
+	{
69
+
70
+	}//end accessTag()
71
+
72
+	/**
73
+	 * Constructor
74
+	 *
75
+	 * No return tag
76
+	 */
77
+	function PHP_CodeSniffer_File()
78
+	{
79
+		return;
80
+	}
81
+
82
+
83
+	/**
84
+	 * Destructor
85
+	 *
86
+	 * No return tag too
87
+	 */
88
+	function _PHP_CodeSniffer_File()
89
+	{
90
+		return;
91
+	}
92
+
93
+
94
+	/**
95
+	 * Destructor PHP5
96
+	 */
97
+	function __destruct()
98
+	{
99
+		return;
100
+	}
101
+
102
+
103
+	function missingComment()
104
+	{
105
+		return;
106
+	}
107
+
108
+
109
+	/**
110
+	 * no return tag
111
+	 *
112
+	 */
113
+	public function noReturn($one)
114
+	{
115
+
116
+	}//end noReturn()
117
+
118
+
119
+	/**
120
+	 * Param not immediate
121
+	 *
122
+	 * @return
123
+	 * @param   int   $threeSpaces
124
+	 * @param int     $superfluous
125
+	 * @param missing
126
+	 * @param
127
+	 */
128
+	public function missingDescription($threeSpaces)
129
+	{
130
+
131
+	}//end missingDescription()
132
+
133
+
134
+	/**
135
+	 * Param not immediate
136
+	 *
137
+	 * @param int      $one   comment
138
+	 * @param int      $two   comment
139
+	 * @param string   $three comment
140
+	 *
141
+	 * @return void
142
+	 */
143
+	public function oneSpaceAfterLongestVar($one, $two, $three)
144
+	{
145
+
146
+	}//end oneSpaceAfterLongestVar()
147 147
 
148 148
 
149 149
 }//end class
@@ -159,19 +159,19 @@  discard block
 block discarded – undo
159 159
  */
160 160
 function functionOutsideClass(&$str, &$foo)
161 161
 {
162
-    return;
162
+	return;
163 163
 }//end functionOutsideClass()
164 164
 
165 165
 function missingCommentOutsideClass()
166 166
 {
167
-    return;
167
+	return;
168 168
 }//end missingCommentOutsideClass()
169 169
 
170 170
 
171 171
 ?><?php
172 172
 function tagBeforeComment()
173 173
 {
174
-    return;
174
+	return;
175 175
 }//end tagBeforeComment()
176 176
 
177 177
 
@@ -244,12 +244,12 @@  discard block
 block discarded – undo
244 244
 function myFunction() {}
245 245
 
246 246
 abstract class MyClass {
247
-    /**
248
-     * An abstract function.
249
-     *
250
-     * @return string[]
251
-     */
252
-    abstract protected function myFunction();
247
+	/**
248
+	 * An abstract function.
249
+	 *
250
+	 * @return string[]
251
+	 */
252
+	abstract protected function myFunction();
253 253
 }
254 254
 
255 255
 /**
@@ -271,18 +271,18 @@  discard block
 block discarded – undo
271 271
  *
272 272
  */
273 273
 function _() {
274
-    return $foo;
274
+	return $foo;
275 275
 }
276 276
 
277 277
 class Baz {
278
-    /**
279
-     * The PHP5 constructor
280
-     *
281
-     * No return tag
282
-     */
283
-    public function __construct() {
284
-
285
-    }
278
+	/**
279
+	 * The PHP5 constructor
280
+	 *
281
+	 * No return tag
282
+	 */
283
+	public function __construct() {
284
+
285
+	}
286 286
 }
287 287
 
288 288
 /**
@@ -295,7 +295,7 @@  discard block
 block discarded – undo
295 295
  * @return void
296 296
  */
297 297
 function completeStep($status, array $array = [Class1::class, 'test'], $note = '') {
298
-    echo 'foo';
298
+	echo 'foo';
299 299
 }
300 300
 
301 301
 /**
@@ -379,45 +379,45 @@  discard block
 block discarded – undo
379 379
  */
380 380
 public function setTranslator($a, &$b): void
381 381
 {
382
-    $this->translator = $translator;
382
+	$this->translator = $translator;
383 383
 }
384 384
 
385 385
 // phpcs:set PEAR.Commenting.FunctionComment minimumVisibility protected
386 386
 private function setTranslator2($a, &$b): void
387 387
 {
388
-    $this->translator = $translator;
388
+	$this->translator = $translator;
389 389
 }
390 390
 
391 391
 // phpcs:set PEAR.Commenting.FunctionComment minimumVisibility public
392 392
 protected function setTranslator3($a, &$b): void
393 393
 {
394
-    $this->translator = $translator;
394
+	$this->translator = $translator;
395 395
 }
396 396
 
397 397
 private function setTranslator4($a, &$b): void
398 398
 {
399
-    $this->translator = $translator;
399
+	$this->translator = $translator;
400 400
 }
401 401
 
402 402
 class Bar {
403
-    /**
404
-     * The PHP5 constructor
405
-     *
406
-     * @return
407
-     */
408
-    public function __construct() {
409
-
410
-    }
403
+	/**
404
+	 * The PHP5 constructor
405
+	 *
406
+	 * @return
407
+	 */
408
+	public function __construct() {
409
+
410
+	}
411 411
 }
412 412
 
413 413
 // phpcs:set PEAR.Commenting.FunctionComment specialMethods[]
414 414
 class Bar {
415
-    /**
416
-     * The PHP5 constructor
417
-     */
418
-    public function __construct() {
415
+	/**
416
+	 * The PHP5 constructor
417
+	 */
418
+	public function __construct() {
419 419
 
420
-    }
420
+	}
421 421
 }
422 422
 
423 423
 // phpcs:set PEAR.Commenting.FunctionComment specialMethods[] ignored
@@ -431,48 +431,48 @@  discard block
 block discarded – undo
431 431
 // phpcs:set PEAR.Commenting.FunctionComment specialMethods[] __construct,__destruct
432 432
 
433 433
 class Something implements JsonSerializable {
434
-    /**
435
-     * Single attribute.
436
-     *
437
-     * @return mixed
438
-     */
439
-    #[ReturnTypeWillChange]
440
-    public function jsonSerialize() {}
441
-
442
-    /**
443
-     * Multiple attributes.
444
-     *
445
-     * @return Something
446
-     */
447
-    #[AttributeA]
448
-    #[AttributeB]
449
-    public function methodName() {}
450
-
451
-    /**
452
-     * Blank line between docblock and attribute.
453
-     *
454
-     * @return mixed
455
-     */
456
-
457
-    #[ReturnTypeWillChange]
458
-    public function blankLineDetectionA() {}
459
-
460
-    /**
461
-     * Blank line between attribute and function declaration.
462
-     *
463
-     * @return mixed
464
-     */
465
-    #[ReturnTypeWillChange]
466
-
467
-    public function blankLineDetectionB() {}
468
-
469
-    /**
470
-     * Blank line between both docblock and attribute and attribute and function declaration.
471
-     *
472
-     * @return mixed
473
-     */
474
-
475
-    #[ReturnTypeWillChange]
476
-
477
-    public function blankLineDetectionC() {}
434
+	/**
435
+	 * Single attribute.
436
+	 *
437
+	 * @return mixed
438
+	 */
439
+	#[ReturnTypeWillChange]
440
+	public function jsonSerialize() {}
441
+
442
+	/**
443
+	 * Multiple attributes.
444
+	 *
445
+	 * @return Something
446
+	 */
447
+	#[AttributeA]
448
+	#[AttributeB]
449
+	public function methodName() {}
450
+
451
+	/**
452
+	 * Blank line between docblock and attribute.
453
+	 *
454
+	 * @return mixed
455
+	 */
456
+
457
+	#[ReturnTypeWillChange]
458
+	public function blankLineDetectionA() {}
459
+
460
+	/**
461
+	 * Blank line between attribute and function declaration.
462
+	 *
463
+	 * @return mixed
464
+	 */
465
+	#[ReturnTypeWillChange]
466
+
467
+	public function blankLineDetectionB() {}
468
+
469
+	/**
470
+	 * Blank line between both docblock and attribute and attribute and function declaration.
471
+	 *
472
+	 * @return mixed
473
+	 */
474
+
475
+	#[ReturnTypeWillChange]
476
+
477
+	public function blankLineDetectionC() {}
478 478
 }
Please login to merge, or discard this patch.
src/Standards/PEAR/Sniffs/WhiteSpace/ScopeClosingBraceSniff.php 2 patches
Indentation   +158 added lines, -158 removed lines patch added patch discarded remove patch
@@ -16,164 +16,164 @@
 block discarded – undo
16 16
 class ScopeClosingBraceSniff implements Sniff
17 17
 {
18 18
 
19
-    /**
20
-     * The number of spaces code should be indented.
21
-     *
22
-     * @var integer
23
-     */
24
-    public $indent = 4;
25
-
26
-
27
-     /**
28
-      * Returns an array of tokens this test wants to listen for.
29
-      *
30
-      * @return int[]
31
-      */
32
-    public function register()
33
-    {
34
-        return Tokens::$scopeOpeners;
35
-
36
-    }//end register()
37
-
38
-
39
-    /**
40
-     * Processes this test, when one of its tokens is encountered.
41
-     *
42
-     * @param \PHP_CodeSniffer\Files\File $phpcsFile All the tokens found in the document.
43
-     * @param int                         $stackPtr  The position of the current token
44
-     *                                               in the stack passed in $tokens.
45
-     *
46
-     * @return void
47
-     */
48
-    public function process(File $phpcsFile, $stackPtr)
49
-    {
50
-        $tokens = $phpcsFile->getTokens();
51
-
52
-        // If this is an inline condition (ie. there is no scope opener), then
53
-        // return, as this is not a new scope.
54
-        if (isset($tokens[$stackPtr]['scope_closer']) === false) {
55
-            return;
56
-        }
57
-
58
-        $scopeStart = $tokens[$stackPtr]['scope_opener'];
59
-        $scopeEnd   = $tokens[$stackPtr]['scope_closer'];
60
-
61
-        // If the scope closer doesn't think it belongs to this scope opener
62
-        // then the opener is sharing its closer with other tokens. We only
63
-        // want to process the closer once, so skip this one.
64
-        if (isset($tokens[$scopeEnd]['scope_condition']) === false
65
-            || $tokens[$scopeEnd]['scope_condition'] !== $stackPtr
66
-        ) {
67
-            return;
68
-        }
69
-
70
-        // We need to actually find the first piece of content on this line,
71
-        // because if this is a method with tokens before it (public, static etc)
72
-        // or an if with an else before it, then we need to start the scope
73
-        // checking from there, rather than the current token.
74
-        $lineStart = ($stackPtr - 1);
75
-        for ($lineStart; $lineStart > 0; $lineStart--) {
76
-            if (strpos($tokens[$lineStart]['content'], $phpcsFile->eolChar) !== false) {
77
-                break;
78
-            }
79
-        }
80
-
81
-        $lineStart++;
82
-
83
-        $startColumn = 1;
84
-        if ($tokens[$lineStart]['code'] === T_WHITESPACE) {
85
-            $startColumn = $tokens[($lineStart + 1)]['column'];
86
-        } else if ($tokens[$lineStart]['code'] === T_INLINE_HTML) {
87
-            $trimmed = ltrim($tokens[$lineStart]['content']);
88
-            if ($trimmed === '') {
89
-                $startColumn = $tokens[($lineStart + 1)]['column'];
90
-            } else {
91
-                $startColumn = (strlen($tokens[$lineStart]['content']) - strlen($trimmed));
92
-            }
93
-        }
94
-
95
-        // Check that the closing brace is on it's own line.
96
-        $lastContent = $phpcsFile->findPrevious(
97
-            [
98
-                T_WHITESPACE,
99
-                T_INLINE_HTML,
100
-                T_OPEN_TAG,
101
-            ],
102
-            ($scopeEnd - 1),
103
-            $scopeStart,
104
-            true
105
-        );
106
-
107
-        if ($tokens[$lastContent]['line'] === $tokens[$scopeEnd]['line']) {
108
-            $error = 'Closing brace must be on a line by itself';
109
-            $fix   = $phpcsFile->addFixableError($error, $scopeEnd, 'Line');
110
-            if ($fix === true) {
111
-                $phpcsFile->fixer->addNewlineBefore($scopeEnd);
112
-            }
113
-
114
-            return;
115
-        }
116
-
117
-        // Check now that the closing brace is lined up correctly.
118
-        $lineStart = ($scopeEnd - 1);
119
-        for ($lineStart; $lineStart > 0; $lineStart--) {
120
-            if (strpos($tokens[$lineStart]['content'], $phpcsFile->eolChar) !== false) {
121
-                break;
122
-            }
123
-        }
124
-
125
-        $lineStart++;
126
-
127
-        $braceIndent = 0;
128
-        if ($tokens[$lineStart]['code'] === T_WHITESPACE) {
129
-            $braceIndent = ($tokens[($lineStart + 1)]['column'] - 1);
130
-        } else if ($tokens[$lineStart]['code'] === T_INLINE_HTML) {
131
-            $trimmed = ltrim($tokens[$lineStart]['content']);
132
-            if ($trimmed === '') {
133
-                $braceIndent = ($tokens[($lineStart + 1)]['column'] - 1);
134
-            } else {
135
-                $braceIndent = (strlen($tokens[$lineStart]['content']) - strlen($trimmed) - 1);
136
-            }
137
-        }
138
-
139
-        $fix = false;
140
-        if ($tokens[$stackPtr]['code'] === T_CASE
141
-            || $tokens[$stackPtr]['code'] === T_DEFAULT
142
-        ) {
143
-            // BREAK statements should be indented n spaces from the
144
-            // CASE or DEFAULT statement.
145
-            $expectedIndent = ($startColumn + $this->indent - 1);
146
-            if ($braceIndent !== $expectedIndent) {
147
-                $error = 'Case breaking statement indented incorrectly; expected %s spaces, found %s';
148
-                $data  = [
149
-                    $expectedIndent,
150
-                    $braceIndent,
151
-                ];
152
-                $fix   = $phpcsFile->addFixableError($error, $scopeEnd, 'BreakIndent', $data);
153
-            }
154
-        } else {
155
-            $expectedIndent = max(0, ($startColumn - 1));
156
-            if ($braceIndent !== $expectedIndent) {
157
-                $error = 'Closing brace indented incorrectly; expected %s spaces, found %s';
158
-                $data  = [
159
-                    $expectedIndent,
160
-                    $braceIndent,
161
-                ];
162
-                $fix   = $phpcsFile->addFixableError($error, $scopeEnd, 'Indent', $data);
163
-            }
164
-        }//end if
165
-
166
-        if ($fix === true) {
167
-            $spaces = str_repeat(' ', $expectedIndent);
168
-            if ($braceIndent === 0) {
169
-                $phpcsFile->fixer->addContentBefore($lineStart, $spaces);
170
-            } else {
171
-                $phpcsFile->fixer->replaceToken($lineStart, ltrim($tokens[$lineStart]['content']));
172
-                $phpcsFile->fixer->addContentBefore($lineStart, $spaces);
173
-            }
174
-        }
175
-
176
-    }//end process()
19
+	/**
20
+	 * The number of spaces code should be indented.
21
+	 *
22
+	 * @var integer
23
+	 */
24
+	public $indent = 4;
25
+
26
+
27
+	 /**
28
+	  * Returns an array of tokens this test wants to listen for.
29
+	  *
30
+	  * @return int[]
31
+	  */
32
+	public function register()
33
+	{
34
+		return Tokens::$scopeOpeners;
35
+
36
+	}//end register()
37
+
38
+
39
+	/**
40
+	 * Processes this test, when one of its tokens is encountered.
41
+	 *
42
+	 * @param \PHP_CodeSniffer\Files\File $phpcsFile All the tokens found in the document.
43
+	 * @param int                         $stackPtr  The position of the current token
44
+	 *                                               in the stack passed in $tokens.
45
+	 *
46
+	 * @return void
47
+	 */
48
+	public function process(File $phpcsFile, $stackPtr)
49
+	{
50
+		$tokens = $phpcsFile->getTokens();
51
+
52
+		// If this is an inline condition (ie. there is no scope opener), then
53
+		// return, as this is not a new scope.
54
+		if (isset($tokens[$stackPtr]['scope_closer']) === false) {
55
+			return;
56
+		}
57
+
58
+		$scopeStart = $tokens[$stackPtr]['scope_opener'];
59
+		$scopeEnd   = $tokens[$stackPtr]['scope_closer'];
60
+
61
+		// If the scope closer doesn't think it belongs to this scope opener
62
+		// then the opener is sharing its closer with other tokens. We only
63
+		// want to process the closer once, so skip this one.
64
+		if (isset($tokens[$scopeEnd]['scope_condition']) === false
65
+			|| $tokens[$scopeEnd]['scope_condition'] !== $stackPtr
66
+		) {
67
+			return;
68
+		}
69
+
70
+		// We need to actually find the first piece of content on this line,
71
+		// because if this is a method with tokens before it (public, static etc)
72
+		// or an if with an else before it, then we need to start the scope
73
+		// checking from there, rather than the current token.
74
+		$lineStart = ($stackPtr - 1);
75
+		for ($lineStart; $lineStart > 0; $lineStart--) {
76
+			if (strpos($tokens[$lineStart]['content'], $phpcsFile->eolChar) !== false) {
77
+				break;
78
+			}
79
+		}
80
+
81
+		$lineStart++;
82
+
83
+		$startColumn = 1;
84
+		if ($tokens[$lineStart]['code'] === T_WHITESPACE) {
85
+			$startColumn = $tokens[($lineStart + 1)]['column'];
86
+		} else if ($tokens[$lineStart]['code'] === T_INLINE_HTML) {
87
+			$trimmed = ltrim($tokens[$lineStart]['content']);
88
+			if ($trimmed === '') {
89
+				$startColumn = $tokens[($lineStart + 1)]['column'];
90
+			} else {
91
+				$startColumn = (strlen($tokens[$lineStart]['content']) - strlen($trimmed));
92
+			}
93
+		}
94
+
95
+		// Check that the closing brace is on it's own line.
96
+		$lastContent = $phpcsFile->findPrevious(
97
+			[
98
+				T_WHITESPACE,
99
+				T_INLINE_HTML,
100
+				T_OPEN_TAG,
101
+			],
102
+			($scopeEnd - 1),
103
+			$scopeStart,
104
+			true
105
+		);
106
+
107
+		if ($tokens[$lastContent]['line'] === $tokens[$scopeEnd]['line']) {
108
+			$error = 'Closing brace must be on a line by itself';
109
+			$fix   = $phpcsFile->addFixableError($error, $scopeEnd, 'Line');
110
+			if ($fix === true) {
111
+				$phpcsFile->fixer->addNewlineBefore($scopeEnd);
112
+			}
113
+
114
+			return;
115
+		}
116
+
117
+		// Check now that the closing brace is lined up correctly.
118
+		$lineStart = ($scopeEnd - 1);
119
+		for ($lineStart; $lineStart > 0; $lineStart--) {
120
+			if (strpos($tokens[$lineStart]['content'], $phpcsFile->eolChar) !== false) {
121
+				break;
122
+			}
123
+		}
124
+
125
+		$lineStart++;
126
+
127
+		$braceIndent = 0;
128
+		if ($tokens[$lineStart]['code'] === T_WHITESPACE) {
129
+			$braceIndent = ($tokens[($lineStart + 1)]['column'] - 1);
130
+		} else if ($tokens[$lineStart]['code'] === T_INLINE_HTML) {
131
+			$trimmed = ltrim($tokens[$lineStart]['content']);
132
+			if ($trimmed === '') {
133
+				$braceIndent = ($tokens[($lineStart + 1)]['column'] - 1);
134
+			} else {
135
+				$braceIndent = (strlen($tokens[$lineStart]['content']) - strlen($trimmed) - 1);
136
+			}
137
+		}
138
+
139
+		$fix = false;
140
+		if ($tokens[$stackPtr]['code'] === T_CASE
141
+			|| $tokens[$stackPtr]['code'] === T_DEFAULT
142
+		) {
143
+			// BREAK statements should be indented n spaces from the
144
+			// CASE or DEFAULT statement.
145
+			$expectedIndent = ($startColumn + $this->indent - 1);
146
+			if ($braceIndent !== $expectedIndent) {
147
+				$error = 'Case breaking statement indented incorrectly; expected %s spaces, found %s';
148
+				$data  = [
149
+					$expectedIndent,
150
+					$braceIndent,
151
+				];
152
+				$fix   = $phpcsFile->addFixableError($error, $scopeEnd, 'BreakIndent', $data);
153
+			}
154
+		} else {
155
+			$expectedIndent = max(0, ($startColumn - 1));
156
+			if ($braceIndent !== $expectedIndent) {
157
+				$error = 'Closing brace indented incorrectly; expected %s spaces, found %s';
158
+				$data  = [
159
+					$expectedIndent,
160
+					$braceIndent,
161
+				];
162
+				$fix   = $phpcsFile->addFixableError($error, $scopeEnd, 'Indent', $data);
163
+			}
164
+		}//end if
165
+
166
+		if ($fix === true) {
167
+			$spaces = str_repeat(' ', $expectedIndent);
168
+			if ($braceIndent === 0) {
169
+				$phpcsFile->fixer->addContentBefore($lineStart, $spaces);
170
+			} else {
171
+				$phpcsFile->fixer->replaceToken($lineStart, ltrim($tokens[$lineStart]['content']));
172
+				$phpcsFile->fixer->addContentBefore($lineStart, $spaces);
173
+			}
174
+		}
175
+
176
+	}//end process()
177 177
 
178 178
 
179 179
 }//end class
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -149,7 +149,7 @@  discard block
 block discarded – undo
149 149
                     $expectedIndent,
150 150
                     $braceIndent,
151 151
                 ];
152
-                $fix   = $phpcsFile->addFixableError($error, $scopeEnd, 'BreakIndent', $data);
152
+                $fix = $phpcsFile->addFixableError($error, $scopeEnd, 'BreakIndent', $data);
153 153
             }
154 154
         } else {
155 155
             $expectedIndent = max(0, ($startColumn - 1));
@@ -159,7 +159,7 @@  discard block
 block discarded – undo
159 159
                     $expectedIndent,
160 160
                     $braceIndent,
161 161
                 ];
162
-                $fix   = $phpcsFile->addFixableError($error, $scopeEnd, 'Indent', $data);
162
+                $fix = $phpcsFile->addFixableError($error, $scopeEnd, 'Indent', $data);
163 163
             }
164 164
         }//end if
165 165
 
Please login to merge, or discard this patch.
php_codesniffer/src/Standards/PEAR/Sniffs/WhiteSpace/ScopeIndentSniff.php 1 patch
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -14,11 +14,11 @@
 block discarded – undo
14 14
 class ScopeIndentSniff extends GenericScopeIndentSniff
15 15
 {
16 16
 
17
-    /**
18
-     * Any scope openers that should not cause an indent.
19
-     *
20
-     * @var int[]
21
-     */
22
-    protected $nonIndentingScopes = [T_SWITCH];
17
+	/**
18
+	 * Any scope openers that should not cause an indent.
19
+	 *
20
+	 * @var int[]
21
+	 */
22
+	protected $nonIndentingScopes = [T_SWITCH];
23 23
 
24 24
 }//end class
Please login to merge, or discard this patch.
php_codesniffer/src/Standards/PEAR/Sniffs/Files/IncludingFileSniff.php 1 patch
Indentation   +112 added lines, -112 removed lines patch added patch discarded remove patch
@@ -19,118 +19,118 @@
 block discarded – undo
19 19
 {
20 20
 
21 21
 
22
-    /**
23
-     * Returns an array of tokens this test wants to listen for.
24
-     *
25
-     * @return array
26
-     */
27
-    public function register()
28
-    {
29
-        return [
30
-            T_INCLUDE_ONCE,
31
-            T_REQUIRE_ONCE,
32
-            T_REQUIRE,
33
-            T_INCLUDE,
34
-        ];
35
-
36
-    }//end register()
37
-
38
-
39
-    /**
40
-     * Processes this test, when one of its tokens is encountered.
41
-     *
42
-     * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.
43
-     * @param int                         $stackPtr  The position of the current token in the
44
-     *                                               stack passed in $tokens.
45
-     *
46
-     * @return void
47
-     */
48
-    public function process(File $phpcsFile, $stackPtr)
49
-    {
50
-        $tokens = $phpcsFile->getTokens();
51
-
52
-        $nextToken = $phpcsFile->findNext(Tokens::$emptyTokens, ($stackPtr + 1), null, true);
53
-        if ($tokens[$nextToken]['code'] === T_OPEN_PARENTHESIS) {
54
-            $error = '"%s" is a statement not a function; no parentheses are required';
55
-            $data  = [$tokens[$stackPtr]['content']];
56
-            $fix   = $phpcsFile->addFixableError($error, $stackPtr, 'BracketsNotRequired', $data);
57
-            if ($fix === true) {
58
-                $phpcsFile->fixer->beginChangeset();
59
-                $phpcsFile->fixer->replaceToken($tokens[$nextToken]['parenthesis_closer'], '');
60
-                if ($tokens[($nextToken - 1)]['code'] !== T_WHITESPACE) {
61
-                    $phpcsFile->fixer->replaceToken($nextToken, ' ');
62
-                } else {
63
-                    $phpcsFile->fixer->replaceToken($nextToken, '');
64
-                }
65
-
66
-                $phpcsFile->fixer->endChangeset();
67
-            }
68
-        }
69
-
70
-        if (count($tokens[$stackPtr]['conditions']) !== 0) {
71
-            $inCondition = true;
72
-        } else {
73
-            $inCondition = false;
74
-        }
75
-
76
-        // Check to see if this including statement is within the parenthesis
77
-        // of a condition. If that's the case then we need to process it as being
78
-        // within a condition, as they are checking the return value.
79
-        if (isset($tokens[$stackPtr]['nested_parenthesis']) === true) {
80
-            foreach ($tokens[$stackPtr]['nested_parenthesis'] as $left => $right) {
81
-                if (isset($tokens[$left]['parenthesis_owner']) === true) {
82
-                    $inCondition = true;
83
-                }
84
-            }
85
-        }
86
-
87
-        // Check to see if they are assigning the return value of this
88
-        // including call. If they are then they are probably checking it, so
89
-        // it's conditional.
90
-        $previous = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($stackPtr - 1), null, true);
91
-        if (isset(Tokens::$assignmentTokens[$tokens[$previous]['code']]) === true) {
92
-            // The have assigned the return value to it, so its conditional.
93
-            $inCondition = true;
94
-        }
95
-
96
-        $tokenCode = $tokens[$stackPtr]['code'];
97
-        if ($inCondition === true) {
98
-            // We are inside a conditional statement. We need an include_once.
99
-            if ($tokenCode === T_REQUIRE_ONCE) {
100
-                $error  = 'File is being conditionally included; ';
101
-                $error .= 'use "include_once" instead';
102
-                $fix    = $phpcsFile->addFixableError($error, $stackPtr, 'UseIncludeOnce');
103
-                if ($fix === true) {
104
-                    $phpcsFile->fixer->replaceToken($stackPtr, 'include_once');
105
-                }
106
-            } else if ($tokenCode === T_REQUIRE) {
107
-                $error  = 'File is being conditionally included; ';
108
-                $error .= 'use "include" instead';
109
-                $fix    = $phpcsFile->addFixableError($error, $stackPtr, 'UseInclude');
110
-                if ($fix === true) {
111
-                    $phpcsFile->fixer->replaceToken($stackPtr, 'include');
112
-                }
113
-            }
114
-        } else {
115
-            // We are unconditionally including, we need a require_once.
116
-            if ($tokenCode === T_INCLUDE_ONCE) {
117
-                $error  = 'File is being unconditionally included; ';
118
-                $error .= 'use "require_once" instead';
119
-                $fix    = $phpcsFile->addFixableError($error, $stackPtr, 'UseRequireOnce');
120
-                if ($fix === true) {
121
-                    $phpcsFile->fixer->replaceToken($stackPtr, 'require_once');
122
-                }
123
-            } else if ($tokenCode === T_INCLUDE) {
124
-                $error  = 'File is being unconditionally included; ';
125
-                $error .= 'use "require" instead';
126
-                $fix    = $phpcsFile->addFixableError($error, $stackPtr, 'UseRequire');
127
-                if ($fix === true) {
128
-                    $phpcsFile->fixer->replaceToken($stackPtr, 'require');
129
-                }
130
-            }
131
-        }//end if
132
-
133
-    }//end process()
22
+	/**
23
+	 * Returns an array of tokens this test wants to listen for.
24
+	 *
25
+	 * @return array
26
+	 */
27
+	public function register()
28
+	{
29
+		return [
30
+			T_INCLUDE_ONCE,
31
+			T_REQUIRE_ONCE,
32
+			T_REQUIRE,
33
+			T_INCLUDE,
34
+		];
35
+
36
+	}//end register()
37
+
38
+
39
+	/**
40
+	 * Processes this test, when one of its tokens is encountered.
41
+	 *
42
+	 * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.
43
+	 * @param int                         $stackPtr  The position of the current token in the
44
+	 *                                               stack passed in $tokens.
45
+	 *
46
+	 * @return void
47
+	 */
48
+	public function process(File $phpcsFile, $stackPtr)
49
+	{
50
+		$tokens = $phpcsFile->getTokens();
51
+
52
+		$nextToken = $phpcsFile->findNext(Tokens::$emptyTokens, ($stackPtr + 1), null, true);
53
+		if ($tokens[$nextToken]['code'] === T_OPEN_PARENTHESIS) {
54
+			$error = '"%s" is a statement not a function; no parentheses are required';
55
+			$data  = [$tokens[$stackPtr]['content']];
56
+			$fix   = $phpcsFile->addFixableError($error, $stackPtr, 'BracketsNotRequired', $data);
57
+			if ($fix === true) {
58
+				$phpcsFile->fixer->beginChangeset();
59
+				$phpcsFile->fixer->replaceToken($tokens[$nextToken]['parenthesis_closer'], '');
60
+				if ($tokens[($nextToken - 1)]['code'] !== T_WHITESPACE) {
61
+					$phpcsFile->fixer->replaceToken($nextToken, ' ');
62
+				} else {
63
+					$phpcsFile->fixer->replaceToken($nextToken, '');
64
+				}
65
+
66
+				$phpcsFile->fixer->endChangeset();
67
+			}
68
+		}
69
+
70
+		if (count($tokens[$stackPtr]['conditions']) !== 0) {
71
+			$inCondition = true;
72
+		} else {
73
+			$inCondition = false;
74
+		}
75
+
76
+		// Check to see if this including statement is within the parenthesis
77
+		// of a condition. If that's the case then we need to process it as being
78
+		// within a condition, as they are checking the return value.
79
+		if (isset($tokens[$stackPtr]['nested_parenthesis']) === true) {
80
+			foreach ($tokens[$stackPtr]['nested_parenthesis'] as $left => $right) {
81
+				if (isset($tokens[$left]['parenthesis_owner']) === true) {
82
+					$inCondition = true;
83
+				}
84
+			}
85
+		}
86
+
87
+		// Check to see if they are assigning the return value of this
88
+		// including call. If they are then they are probably checking it, so
89
+		// it's conditional.
90
+		$previous = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($stackPtr - 1), null, true);
91
+		if (isset(Tokens::$assignmentTokens[$tokens[$previous]['code']]) === true) {
92
+			// The have assigned the return value to it, so its conditional.
93
+			$inCondition = true;
94
+		}
95
+
96
+		$tokenCode = $tokens[$stackPtr]['code'];
97
+		if ($inCondition === true) {
98
+			// We are inside a conditional statement. We need an include_once.
99
+			if ($tokenCode === T_REQUIRE_ONCE) {
100
+				$error  = 'File is being conditionally included; ';
101
+				$error .= 'use "include_once" instead';
102
+				$fix    = $phpcsFile->addFixableError($error, $stackPtr, 'UseIncludeOnce');
103
+				if ($fix === true) {
104
+					$phpcsFile->fixer->replaceToken($stackPtr, 'include_once');
105
+				}
106
+			} else if ($tokenCode === T_REQUIRE) {
107
+				$error  = 'File is being conditionally included; ';
108
+				$error .= 'use "include" instead';
109
+				$fix    = $phpcsFile->addFixableError($error, $stackPtr, 'UseInclude');
110
+				if ($fix === true) {
111
+					$phpcsFile->fixer->replaceToken($stackPtr, 'include');
112
+				}
113
+			}
114
+		} else {
115
+			// We are unconditionally including, we need a require_once.
116
+			if ($tokenCode === T_INCLUDE_ONCE) {
117
+				$error  = 'File is being unconditionally included; ';
118
+				$error .= 'use "require_once" instead';
119
+				$fix    = $phpcsFile->addFixableError($error, $stackPtr, 'UseRequireOnce');
120
+				if ($fix === true) {
121
+					$phpcsFile->fixer->replaceToken($stackPtr, 'require_once');
122
+				}
123
+			} else if ($tokenCode === T_INCLUDE) {
124
+				$error  = 'File is being unconditionally included; ';
125
+				$error .= 'use "require" instead';
126
+				$fix    = $phpcsFile->addFixableError($error, $stackPtr, 'UseRequire');
127
+				if ($fix === true) {
128
+					$phpcsFile->fixer->replaceToken($stackPtr, 'require');
129
+				}
130
+			}
131
+		}//end if
132
+
133
+	}//end process()
134 134
 
135 135
 
136 136
 }//end class
Please login to merge, or discard this patch.
php_codesniffer/src/Standards/PEAR/Sniffs/Classes/ClassDeclarationSniff.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -81,7 +81,7 @@
 block discarded – undo
81 81
                     $tokens[$stackPtr]['content'],
82 82
                     ($braceLine - $classLine - 1),
83 83
                 ];
84
-                $fix   = $phpcsFile->addFixableError($error, $curlyBrace, 'OpenBraceWrongLine', $data);
84
+                $fix = $phpcsFile->addFixableError($error, $curlyBrace, 'OpenBraceWrongLine', $data);
85 85
                 if ($fix === true) {
86 86
                     $phpcsFile->fixer->beginChangeset();
87 87
                     for ($i = ($curlyBrace - 1); $i > $lastContent; $i--) {
Please login to merge, or discard this patch.
Indentation   +128 added lines, -128 removed lines patch added patch discarded remove patch
@@ -16,134 +16,134 @@
 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_CLASS,
28
-            T_INTERFACE,
29
-            T_TRAIT,
30
-        ];
31
-
32
-    }//end register()
33
-
34
-
35
-    /**
36
-     * Processes this test, when one of its tokens is encountered.
37
-     *
38
-     * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.
39
-     * @param integer                     $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
-        $errorData = [strtolower($tokens[$stackPtr]['content'])];
48
-
49
-        if (isset($tokens[$stackPtr]['scope_opener']) === false) {
50
-            $error = 'Possible parse error: %s missing opening or closing brace';
51
-            $phpcsFile->addWarning($error, $stackPtr, 'MissingBrace', $errorData);
52
-            return;
53
-        }
54
-
55
-        $curlyBrace  = $tokens[$stackPtr]['scope_opener'];
56
-        $lastContent = $phpcsFile->findPrevious(T_WHITESPACE, ($curlyBrace - 1), $stackPtr, true);
57
-        $classLine   = $tokens[$lastContent]['line'];
58
-        $braceLine   = $tokens[$curlyBrace]['line'];
59
-        if ($braceLine === $classLine) {
60
-            $phpcsFile->recordMetric($stackPtr, 'Class opening brace placement', 'same line');
61
-            $error = 'Opening brace of a %s must be on the line after the definition';
62
-            $fix   = $phpcsFile->addFixableError($error, $curlyBrace, 'OpenBraceNewLine', $errorData);
63
-            if ($fix === true) {
64
-                $phpcsFile->fixer->beginChangeset();
65
-                if ($tokens[($curlyBrace - 1)]['code'] === T_WHITESPACE) {
66
-                    $phpcsFile->fixer->replaceToken(($curlyBrace - 1), '');
67
-                }
68
-
69
-                $phpcsFile->fixer->addNewlineBefore($curlyBrace);
70
-                $phpcsFile->fixer->endChangeset();
71
-            }
72
-
73
-            return;
74
-        } else {
75
-            $phpcsFile->recordMetric($stackPtr, 'Class opening brace placement', 'new line');
76
-
77
-            if ($braceLine > ($classLine + 1)) {
78
-                $error = 'Opening brace of a %s must be on the line following the %s declaration; found %s line(s)';
79
-                $data  = [
80
-                    $tokens[$stackPtr]['content'],
81
-                    $tokens[$stackPtr]['content'],
82
-                    ($braceLine - $classLine - 1),
83
-                ];
84
-                $fix   = $phpcsFile->addFixableError($error, $curlyBrace, 'OpenBraceWrongLine', $data);
85
-                if ($fix === true) {
86
-                    $phpcsFile->fixer->beginChangeset();
87
-                    for ($i = ($curlyBrace - 1); $i > $lastContent; $i--) {
88
-                        if ($tokens[$i]['line'] === ($tokens[$curlyBrace]['line'] + 1)) {
89
-                            break;
90
-                        }
91
-
92
-                        $phpcsFile->fixer->replaceToken($i, '');
93
-                    }
94
-
95
-                    $phpcsFile->fixer->endChangeset();
96
-                }
97
-
98
-                return;
99
-            }//end if
100
-        }//end if
101
-
102
-        if ($tokens[($curlyBrace + 1)]['content'] !== $phpcsFile->eolChar) {
103
-            $error = 'Opening %s brace must be on a line by itself';
104
-
105
-            $nextNonWhitespace = $phpcsFile->findNext(T_WHITESPACE, ($curlyBrace + 1), null, true);
106
-            if ($tokens[$nextNonWhitespace]['code'] === T_PHPCS_IGNORE) {
107
-                // Don't auto-fix if the next thing is a PHPCS ignore annotation.
108
-                $phpcsFile->addError($error, $curlyBrace, 'OpenBraceNotAlone', $errorData);
109
-            } else {
110
-                $fix = $phpcsFile->addFixableError($error, $curlyBrace, 'OpenBraceNotAlone', $errorData);
111
-                if ($fix === true) {
112
-                    $phpcsFile->fixer->addNewline($curlyBrace);
113
-                }
114
-            }
115
-        }
116
-
117
-        if ($tokens[($curlyBrace - 1)]['code'] === T_WHITESPACE) {
118
-            $prevContent = $tokens[($curlyBrace - 1)]['content'];
119
-            if ($prevContent === $phpcsFile->eolChar) {
120
-                $spaces = 0;
121
-            } else {
122
-                $spaces = $tokens[($curlyBrace - 1)]['length'];
123
-            }
124
-
125
-            $first    = $phpcsFile->findFirstOnLine(T_WHITESPACE, $stackPtr, true);
126
-            $expected = ($tokens[$first]['column'] - 1);
127
-            if ($spaces !== $expected) {
128
-                $error = 'Expected %s spaces before opening brace; %s found';
129
-                $data  = [
130
-                    $expected,
131
-                    $spaces,
132
-                ];
133
-
134
-                $fix = $phpcsFile->addFixableError($error, $curlyBrace, 'SpaceBeforeBrace', $data);
135
-                if ($fix === true) {
136
-                    $indent = str_repeat(' ', $expected);
137
-                    if ($spaces === 0) {
138
-                        $phpcsFile->fixer->addContentBefore($curlyBrace, $indent);
139
-                    } else {
140
-                        $phpcsFile->fixer->replaceToken(($curlyBrace - 1), $indent);
141
-                    }
142
-                }
143
-            }
144
-        }//end if
145
-
146
-    }//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 [
27
+			T_CLASS,
28
+			T_INTERFACE,
29
+			T_TRAIT,
30
+		];
31
+
32
+	}//end register()
33
+
34
+
35
+	/**
36
+	 * Processes this test, when one of its tokens is encountered.
37
+	 *
38
+	 * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.
39
+	 * @param integer                     $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
+		$errorData = [strtolower($tokens[$stackPtr]['content'])];
48
+
49
+		if (isset($tokens[$stackPtr]['scope_opener']) === false) {
50
+			$error = 'Possible parse error: %s missing opening or closing brace';
51
+			$phpcsFile->addWarning($error, $stackPtr, 'MissingBrace', $errorData);
52
+			return;
53
+		}
54
+
55
+		$curlyBrace  = $tokens[$stackPtr]['scope_opener'];
56
+		$lastContent = $phpcsFile->findPrevious(T_WHITESPACE, ($curlyBrace - 1), $stackPtr, true);
57
+		$classLine   = $tokens[$lastContent]['line'];
58
+		$braceLine   = $tokens[$curlyBrace]['line'];
59
+		if ($braceLine === $classLine) {
60
+			$phpcsFile->recordMetric($stackPtr, 'Class opening brace placement', 'same line');
61
+			$error = 'Opening brace of a %s must be on the line after the definition';
62
+			$fix   = $phpcsFile->addFixableError($error, $curlyBrace, 'OpenBraceNewLine', $errorData);
63
+			if ($fix === true) {
64
+				$phpcsFile->fixer->beginChangeset();
65
+				if ($tokens[($curlyBrace - 1)]['code'] === T_WHITESPACE) {
66
+					$phpcsFile->fixer->replaceToken(($curlyBrace - 1), '');
67
+				}
68
+
69
+				$phpcsFile->fixer->addNewlineBefore($curlyBrace);
70
+				$phpcsFile->fixer->endChangeset();
71
+			}
72
+
73
+			return;
74
+		} else {
75
+			$phpcsFile->recordMetric($stackPtr, 'Class opening brace placement', 'new line');
76
+
77
+			if ($braceLine > ($classLine + 1)) {
78
+				$error = 'Opening brace of a %s must be on the line following the %s declaration; found %s line(s)';
79
+				$data  = [
80
+					$tokens[$stackPtr]['content'],
81
+					$tokens[$stackPtr]['content'],
82
+					($braceLine - $classLine - 1),
83
+				];
84
+				$fix   = $phpcsFile->addFixableError($error, $curlyBrace, 'OpenBraceWrongLine', $data);
85
+				if ($fix === true) {
86
+					$phpcsFile->fixer->beginChangeset();
87
+					for ($i = ($curlyBrace - 1); $i > $lastContent; $i--) {
88
+						if ($tokens[$i]['line'] === ($tokens[$curlyBrace]['line'] + 1)) {
89
+							break;
90
+						}
91
+
92
+						$phpcsFile->fixer->replaceToken($i, '');
93
+					}
94
+
95
+					$phpcsFile->fixer->endChangeset();
96
+				}
97
+
98
+				return;
99
+			}//end if
100
+		}//end if
101
+
102
+		if ($tokens[($curlyBrace + 1)]['content'] !== $phpcsFile->eolChar) {
103
+			$error = 'Opening %s brace must be on a line by itself';
104
+
105
+			$nextNonWhitespace = $phpcsFile->findNext(T_WHITESPACE, ($curlyBrace + 1), null, true);
106
+			if ($tokens[$nextNonWhitespace]['code'] === T_PHPCS_IGNORE) {
107
+				// Don't auto-fix if the next thing is a PHPCS ignore annotation.
108
+				$phpcsFile->addError($error, $curlyBrace, 'OpenBraceNotAlone', $errorData);
109
+			} else {
110
+				$fix = $phpcsFile->addFixableError($error, $curlyBrace, 'OpenBraceNotAlone', $errorData);
111
+				if ($fix === true) {
112
+					$phpcsFile->fixer->addNewline($curlyBrace);
113
+				}
114
+			}
115
+		}
116
+
117
+		if ($tokens[($curlyBrace - 1)]['code'] === T_WHITESPACE) {
118
+			$prevContent = $tokens[($curlyBrace - 1)]['content'];
119
+			if ($prevContent === $phpcsFile->eolChar) {
120
+				$spaces = 0;
121
+			} else {
122
+				$spaces = $tokens[($curlyBrace - 1)]['length'];
123
+			}
124
+
125
+			$first    = $phpcsFile->findFirstOnLine(T_WHITESPACE, $stackPtr, true);
126
+			$expected = ($tokens[$first]['column'] - 1);
127
+			if ($spaces !== $expected) {
128
+				$error = 'Expected %s spaces before opening brace; %s found';
129
+				$data  = [
130
+					$expected,
131
+					$spaces,
132
+				];
133
+
134
+				$fix = $phpcsFile->addFixableError($error, $curlyBrace, 'SpaceBeforeBrace', $data);
135
+				if ($fix === true) {
136
+					$indent = str_repeat(' ', $expected);
137
+					if ($spaces === 0) {
138
+						$phpcsFile->fixer->addContentBefore($curlyBrace, $indent);
139
+					} else {
140
+						$phpcsFile->fixer->replaceToken(($curlyBrace - 1), $indent);
141
+					}
142
+				}
143
+			}
144
+		}//end if
145
+
146
+	}//end process()
147 147
 
148 148
 
149 149
 }//end class
Please login to merge, or discard this patch.
Standards/Generic/Tests/NamingConventions/UpperCaseConstantNameUnitTest.php 1 patch
Indentation   +36 added lines, -36 removed lines patch added patch discarded remove patch
@@ -15,42 +15,42 @@
 block discarded – undo
15 15
 {
16 16
 
17 17
 
18
-    /**
19
-     * Returns the lines where errors should occur.
20
-     *
21
-     * The key of the array should represent the line number and the value
22
-     * should represent the number of errors that should occur on that line.
23
-     *
24
-     * @return array<int, int>
25
-     */
26
-    public function getErrorList()
27
-    {
28
-        return [
29
-            8  => 1,
30
-            10 => 1,
31
-            12 => 1,
32
-            14 => 1,
33
-            19 => 1,
34
-            28 => 1,
35
-            30 => 1,
36
-        ];
37
-
38
-    }//end getErrorList()
39
-
40
-
41
-    /**
42
-     * Returns the lines where warnings should occur.
43
-     *
44
-     * The key of the array should represent the line number and the value
45
-     * should represent the number of warnings that should occur on that line.
46
-     *
47
-     * @return array<int, int>
48
-     */
49
-    public function getWarningList()
50
-    {
51
-        return [];
52
-
53
-    }//end getWarningList()
18
+	/**
19
+	 * Returns the lines where errors should occur.
20
+	 *
21
+	 * The key of the array should represent the line number and the value
22
+	 * should represent the number of errors that should occur on that line.
23
+	 *
24
+	 * @return array<int, int>
25
+	 */
26
+	public function getErrorList()
27
+	{
28
+		return [
29
+			8  => 1,
30
+			10 => 1,
31
+			12 => 1,
32
+			14 => 1,
33
+			19 => 1,
34
+			28 => 1,
35
+			30 => 1,
36
+		];
37
+
38
+	}//end getErrorList()
39
+
40
+
41
+	/**
42
+	 * Returns the lines where warnings should occur.
43
+	 *
44
+	 * The key of the array should represent the line number and the value
45
+	 * should represent the number of warnings that should occur on that line.
46
+	 *
47
+	 * @return array<int, int>
48
+	 */
49
+	public function getWarningList()
50
+	{
51
+		return [];
52
+
53
+	}//end getWarningList()
54 54
 
55 55
 
56 56
 }//end class
Please login to merge, or discard this patch.