Completed
Push — develop ( 572bc7...60d03e )
by Zack
25:22 queued 04:21
created
src/Standards/Generic/Tests/VersionControl/GitMergeConflictUnitTest.3.inc 6 patches
Doc Comments   +1 added lines, -19 removed lines patch added patch discarded remove patch
@@ -22,22 +22,4 @@
 block discarded – undo
22 22
 <<<<<<< HEAD
23 23
 $a = 1;
24 24
 =======
25
-$a = 2;
26
->>>>>>> master
27
-
28
-/*
29
- * The above tests are based on "normal" tokens.
30
- * The below test checks that once the tokenizer breaks down because of
31
- * unexpected merge conflict boundaries - i.e. after the first merge conflict
32
- * opener in non-comment, non-heredoc/nowdoc, non-inline HTML code -, subsequent
33
- * merge conflict boundaries will still be detected correctly.
34
- */
35
-?>
36
-
37
-<div class="abc">
38
-<<<<<<< HEAD
39
-	<p id="test-this">Testing a merge conflict.</p>
40
-=======
41
-	<p id="test-that">Another text string.</p>
42
->>>>>>> ref/heads/feature-branch
43
-</div>
25
+$a
44 26
\ No newline at end of file
Please login to merge, or discard this patch.
Indentation   +1 added lines, -19 removed lines patch added patch discarded remove patch
@@ -22,22 +22,4 @@
 block discarded – undo
22 22
 <<<<<<< HEAD
23 23
 $a = 1;
24 24
 =======
25
-$a = 2;
26
->>>>>>> master
27
-
28
-/*
29
- * The above tests are based on "normal" tokens.
30
- * The below test checks that once the tokenizer breaks down because of
31
- * unexpected merge conflict boundaries - i.e. after the first merge conflict
32
- * opener in non-comment, non-heredoc/nowdoc, non-inline HTML code -, subsequent
33
- * merge conflict boundaries will still be detected correctly.
34
- */
35
-?>
36
-
37
-<div class="abc">
38
-<<<<<<< HEAD
39
-	<p id="test-this">Testing a merge conflict.</p>
40
-=======
41
-	<p id="test-that">Another text string.</p>
42
->>>>>>> ref/heads/feature-branch
43
-</div>
25
+$a
44 26
\ No newline at end of file
Please login to merge, or discard this patch.
Switch Indentation   +1 added lines, -19 removed lines patch added patch discarded remove patch
@@ -22,22 +22,4 @@
 block discarded – undo
22 22
 <<<<<<< HEAD
23 23
 $a = 1;
24 24
 =======
25
-$a = 2;
26
->>>>>>> master
27
-
28
-/*
29
- * The above tests are based on "normal" tokens.
30
- * The below test checks that once the tokenizer breaks down because of
31
- * unexpected merge conflict boundaries - i.e. after the first merge conflict
32
- * opener in non-comment, non-heredoc/nowdoc, non-inline HTML code -, subsequent
33
- * merge conflict boundaries will still be detected correctly.
34
- */
35
-?>
36
-
37
-<div class="abc">
38
-<<<<<<< HEAD
39
-	<p id="test-this">Testing a merge conflict.</p>
40
-=======
41
-	<p id="test-that">Another text string.</p>
42
->>>>>>> ref/heads/feature-branch
43
-</div>
25
+$a
44 26
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +2 added lines, -20 removed lines patch added patch discarded remove patch
@@ -19,25 +19,7 @@
 block discarded – undo
19 19
 <?php
20 20
 
21 21
 // Break the tokenizer.
22
-<<<<<<< HEAD
22
+<< << <<< HEAD
23 23
 $a = 1;
24 24
 =======
25
-$a = 2;
26
->>>>>>> master
27
-
28
-/*
29
- * The above tests are based on "normal" tokens.
30
- * The below test checks that once the tokenizer breaks down because of
31
- * unexpected merge conflict boundaries - i.e. after the first merge conflict
32
- * opener in non-comment, non-heredoc/nowdoc, non-inline HTML code -, subsequent
33
- * merge conflict boundaries will still be detected correctly.
34
- */
35
-?>
36
-
37
-<div class="abc">
38
-<<<<<<< HEAD
39
-	<p id="test-this">Testing a merge conflict.</p>
40
-=======
41
-	<p id="test-that">Another text string.</p>
42
->>>>>>> ref/heads/feature-branch
43
-</div>
25
+$a
44 26
\ No newline at end of file
Please login to merge, or discard this patch.
Braces   +1 added lines, -19 removed lines patch added patch discarded remove patch
@@ -22,22 +22,4 @@
 block discarded – undo
22 22
 <<<<<<< HEAD
23 23
 $a = 1;
24 24
 =======
25
-$a = 2;
26
->>>>>>> master
27
-
28
-/*
29
- * The above tests are based on "normal" tokens.
30
- * The below test checks that once the tokenizer breaks down because of
31
- * unexpected merge conflict boundaries - i.e. after the first merge conflict
32
- * opener in non-comment, non-heredoc/nowdoc, non-inline HTML code -, subsequent
33
- * merge conflict boundaries will still be detected correctly.
34
- */
35
-?>
36
-
37
-<div class="abc">
38
-<<<<<<< HEAD
39
-	<p id="test-this">Testing a merge conflict.</p>
40
-=======
41
-	<p id="test-that">Another text string.</p>
42
->>>>>>> ref/heads/feature-branch
43
-</div>
25
+$a
44 26
\ No newline at end of file
Please login to merge, or discard this patch.
Upper-Lower-Casing   +1 added lines, -19 removed lines patch added patch discarded remove patch
@@ -22,22 +22,4 @@
 block discarded – undo
22 22
 <<<<<<< HEAD
23 23
 $a = 1;
24 24
 =======
25
-$a = 2;
26
->>>>>>> master
27
-
28
-/*
29
- * The above tests are based on "normal" tokens.
30
- * The below test checks that once the tokenizer breaks down because of
31
- * unexpected merge conflict boundaries - i.e. after the first merge conflict
32
- * opener in non-comment, non-heredoc/nowdoc, non-inline HTML code -, subsequent
33
- * merge conflict boundaries will still be detected correctly.
34
- */
35
-?>
36
-
37
-<div class="abc">
38
-<<<<<<< HEAD
39
-	<p id="test-this">Testing a merge conflict.</p>
40
-=======
41
-	<p id="test-that">Another text string.</p>
42
->>>>>>> ref/heads/feature-branch
43
-</div>
25
+$a
44 26
\ No newline at end of file
Please login to merge, or discard this patch.
src/Standards/Generic/Tests/VersionControl/GitMergeConflictUnitTest.4.inc 6 patches
Doc Comments   +1 added lines, -5 removed lines patch added patch discarded remove patch
@@ -64,8 +64,4 @@
 block discarded – undo
64 64
 <<<<<<< HEAD
65 65
 can be problematic.
66 66
 EOD;
67
-$a = 1;
68
-=======
69
-should also be detected.
70
-EOT;
71
->>>>>>> ref/heads/other-branchname
67
+$a
72 68
\ No newline at end of file
Please login to merge, or discard this patch.
Indentation   +1 added lines, -5 removed lines patch added patch discarded remove patch
@@ -64,8 +64,4 @@
 block discarded – undo
64 64
 <<<<<<< HEAD
65 65
 can be problematic.
66 66
 EOD;
67
-$a = 1;
68
-=======
69
-should also be detected.
70
-EOT;
71
->>>>>>> ref/heads/other-branchname
67
+$a
72 68
\ No newline at end of file
Please login to merge, or discard this patch.
Switch Indentation   +1 added lines, -5 removed lines patch added patch discarded remove patch
@@ -64,8 +64,4 @@
 block discarded – undo
64 64
 <<<<<<< HEAD
65 65
 can be problematic.
66 66
 EOD;
67
-$a = 1;
68
-=======
69
-should also be detected.
70
-EOT;
71
->>>>>>> ref/heads/other-branchname
67
+$a
72 68
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +3 added lines, -7 removed lines patch added patch discarded remove patch
@@ -22,11 +22,11 @@  discard block
 block discarded – undo
22 22
 =======
23 23
 should also be detected.
24 24
 EOT;
25
->>>>>>> ref/heads/other-branchname
25
+>> >> >> > ref / heads / other - branchname
26 26
 
27 27
 // Merge conflict starter outside with a closer inside of the heredoc.
28 28
 // This breaks the tokenizer.
29
-<<<<<<< HEAD
29
+<< << <<< HEAD
30 30
 $string =
31 31
 <<<EOT
32 32
 Merge conflicts in heredocs
@@ -64,8 +64,4 @@  discard block
 block discarded – undo
64 64
 <<<<<<< HEAD
65 65
 can be problematic.
66 66
 EOD;
67
-$a = 1;
68
-=======
69
-should also be detected.
70
-EOT;
71
->>>>>>> ref/heads/other-branchname
67
+$a
72 68
\ No newline at end of file
Please login to merge, or discard this patch.
Braces   +1 added lines, -5 removed lines patch added patch discarded remove patch
@@ -64,8 +64,4 @@
 block discarded – undo
64 64
 <<<<<<< HEAD
65 65
 can be problematic.
66 66
 EOD;
67
-$a = 1;
68
-=======
69
-should also be detected.
70
-EOT;
71
->>>>>>> ref/heads/other-branchname
67
+$a
72 68
\ No newline at end of file
Please login to merge, or discard this patch.
Upper-Lower-Casing   +3 added lines, -7 removed lines patch added patch discarded remove patch
@@ -9,7 +9,7 @@  discard block
 block discarded – undo
9 9
 should also be detected.
10 10
 >>>>>>> ref/heads/other-branchname
11 11
 And now they are.
12
-EOD;
12
+eod;
13 13
 
14 14
 // Heredoc with a merge conflict starter, the closer is outside the heredoc.
15 15
 $string =
@@ -21,7 +21,7 @@  discard block
 block discarded – undo
21 21
 $a = 1;
22 22
 =======
23 23
 should also be detected.
24
-EOT;
24
+eot;
25 25
 >>>>>>> ref/heads/other-branchname
26 26
 
27 27
 // Merge conflict starter outside with a closer inside of the heredoc.
@@ -64,8 +64,4 @@  discard block
 block discarded – undo
64 64
 <<<<<<< HEAD
65 65
 can be problematic.
66 66
 EOD;
67
-$a = 1;
68
-=======
69
-should also be detected.
70
-EOT;
71
->>>>>>> ref/heads/other-branchname
67
+$a
72 68
\ No newline at end of file
Please login to merge, or discard this patch.
src/Standards/Generic/Tests/VersionControl/GitMergeConflictUnitTest.5.inc 6 patches
Doc Comments   +1 added lines, -10 removed lines patch added patch discarded remove patch
@@ -22,13 +22,4 @@
 block discarded – undo
22 22
  * merge conflict boundaries will still be detected correctly.
23 23
  */
24 24
 
25
-$string =
26
-<<<'EOD'
27
-can be problematic.
28
-<<<<<<< HEAD
29
-were previously not detected.
30
-=======
31
-should also be detected.
32
->>>>>>> ref/heads/other-branchname
33
-And now they are.
34
-EOD;
25
+$string
35 26
\ No newline at end of file
Please login to merge, or discard this patch.
Indentation   +1 added lines, -10 removed lines patch added patch discarded remove patch
@@ -22,13 +22,4 @@
 block discarded – undo
22 22
  * merge conflict boundaries will still be detected correctly.
23 23
  */
24 24
 
25
-$string =
26
-<<<'EOD'
27
-can be problematic.
28
-<<<<<<< HEAD
29
-were previously not detected.
30
-=======
31
-should also be detected.
32
->>>>>>> ref/heads/other-branchname
33
-And now they are.
34
-EOD;
25
+$string
35 26
\ No newline at end of file
Please login to merge, or discard this patch.
Switch Indentation   +1 added lines, -10 removed lines patch added patch discarded remove patch
@@ -22,13 +22,4 @@
 block discarded – undo
22 22
  * merge conflict boundaries will still be detected correctly.
23 23
  */
24 24
 
25
-$string =
26
-<<<'EOD'
27
-can be problematic.
28
-<<<<<<< HEAD
29
-were previously not detected.
30
-=======
31
-should also be detected.
32
->>>>>>> ref/heads/other-branchname
33
-And now they are.
34
-EOD;
25
+$string
35 26
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +2 added lines, -11 removed lines patch added patch discarded remove patch
@@ -12,7 +12,7 @@  discard block
 block discarded – undo
12 12
 EOD;
13 13
 
14 14
 // Break the tokenizer.
15
-<<<<<<< HEAD
15
+<< << <<< HEAD
16 16
 
17 17
 /*
18 18
  * The above tests are based on "normal" tokens.
@@ -22,13 +22,4 @@  discard block
 block discarded – undo
22 22
  * merge conflict boundaries will still be detected correctly.
23 23
  */
24 24
 
25
-$string =
26
-<<<'EOD'
27
-can be problematic.
28
-<<<<<<< HEAD
29
-were previously not detected.
30
-=======
31
-should also be detected.
32
->>>>>>> ref/heads/other-branchname
33
-And now they are.
34
-EOD;
25
+$string
35 26
\ No newline at end of file
Please login to merge, or discard this patch.
Braces   +1 added lines, -10 removed lines patch added patch discarded remove patch
@@ -22,13 +22,4 @@
 block discarded – undo
22 22
  * merge conflict boundaries will still be detected correctly.
23 23
  */
24 24
 
25
-$string =
26
-<<<'EOD'
27
-can be problematic.
28
-<<<<<<< HEAD
29
-were previously not detected.
30
-=======
31
-should also be detected.
32
->>>>>>> ref/heads/other-branchname
33
-And now they are.
34
-EOD;
25
+$string
35 26
\ No newline at end of file
Please login to merge, or discard this patch.
Upper-Lower-Casing   +2 added lines, -11 removed lines patch added patch discarded remove patch
@@ -9,7 +9,7 @@  discard block
 block discarded – undo
9 9
 should also be detected.
10 10
 >>>>>>> ref/heads/other-branchname
11 11
 And now they are.
12
-EOD;
12
+eod;
13 13
 
14 14
 // Break the tokenizer.
15 15
 <<<<<<< HEAD
@@ -22,13 +22,4 @@  discard block
 block discarded – undo
22 22
  * merge conflict boundaries will still be detected correctly.
23 23
  */
24 24
 
25
-$string =
26
-<<<'EOD'
27
-can be problematic.
28
-<<<<<<< HEAD
29
-were previously not detected.
30
-=======
31
-should also be detected.
32
->>>>>>> ref/heads/other-branchname
33
-And now they are.
34
-EOD;
25
+$string
35 26
\ No newline at end of file
Please login to merge, or discard this patch.
src/Standards/Generic/Tests/VersionControl/GitMergeConflictUnitTest.6.inc 6 patches
Doc Comments   +1 added lines, -10 removed lines patch added patch discarded remove patch
@@ -22,13 +22,4 @@
 block discarded – undo
22 22
  * merge conflict boundaries will still be detected correctly.
23 23
  */
24 24
 
25
-$string =
26
-		<<<"EOD"
27
-		Merge conflicts in PHP 7.3 indented heredocs
28
-<<<<<<< HEAD
29
-		can be problematic.
30
-=======
31
-		should also be detected.
32
->>>>>>> ref/heads/other-branchname
33
-		And now they are.
34
-		EOD;
25
+$string
35 26
\ No newline at end of file
Please login to merge, or discard this patch.
Indentation   +1 added lines, -10 removed lines patch added patch discarded remove patch
@@ -22,13 +22,4 @@
 block discarded – undo
22 22
  * merge conflict boundaries will still be detected correctly.
23 23
  */
24 24
 
25
-$string =
26
-		<<<"EOD"
27
-		Merge conflicts in PHP 7.3 indented heredocs
28
-<<<<<<< HEAD
29
-		can be problematic.
30
-=======
31
-		should also be detected.
32
->>>>>>> ref/heads/other-branchname
33
-		And now they are.
34
-		EOD;
25
+$string
35 26
\ No newline at end of file
Please login to merge, or discard this patch.
Switch Indentation   +1 added lines, -10 removed lines patch added patch discarded remove patch
@@ -22,13 +22,4 @@
 block discarded – undo
22 22
  * merge conflict boundaries will still be detected correctly.
23 23
  */
24 24
 
25
-$string =
26
-		<<<"EOD"
27
-		Merge conflicts in PHP 7.3 indented heredocs
28
-<<<<<<< HEAD
29
-		can be problematic.
30
-=======
31
-		should also be detected.
32
->>>>>>> ref/heads/other-branchname
33
-		And now they are.
34
-		EOD;
25
+$string
35 26
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +1 added lines, -10 removed lines patch added patch discarded remove patch
@@ -22,13 +22,4 @@
 block discarded – undo
22 22
  * merge conflict boundaries will still be detected correctly.
23 23
  */
24 24
 
25
-$string =
26
-		<<<"EOD"
27
-		Merge conflicts in PHP 7.3 indented heredocs
28
-<<<<<<< HEAD
29
-		can be problematic.
30
-=======
31
-		should also be detected.
32
->>>>>>> ref/heads/other-branchname
33
-		And now they are.
34
-		EOD;
25
+$string
35 26
\ No newline at end of file
Please login to merge, or discard this patch.
Braces   +1 added lines, -10 removed lines patch added patch discarded remove patch
@@ -22,13 +22,4 @@
 block discarded – undo
22 22
  * merge conflict boundaries will still be detected correctly.
23 23
  */
24 24
 
25
-$string =
26
-		<<<"EOD"
27
-		Merge conflicts in PHP 7.3 indented heredocs
28
-<<<<<<< HEAD
29
-		can be problematic.
30
-=======
31
-		should also be detected.
32
->>>>>>> ref/heads/other-branchname
33
-		And now they are.
34
-		EOD;
25
+$string
35 26
\ No newline at end of file
Please login to merge, or discard this patch.
Upper-Lower-Casing   +1 added lines, -10 removed lines patch added patch discarded remove patch
@@ -22,13 +22,4 @@
 block discarded – undo
22 22
  * merge conflict boundaries will still be detected correctly.
23 23
  */
24 24
 
25
-$string =
26
-		<<<"EOD"
27
-		Merge conflicts in PHP 7.3 indented heredocs
28
-<<<<<<< HEAD
29
-		can be problematic.
30
-=======
31
-		should also be detected.
32
->>>>>>> ref/heads/other-branchname
33
-		And now they are.
34
-		EOD;
25
+$string
35 26
\ No newline at end of file
Please login to merge, or discard this patch.
src/Standards/MySource/Sniffs/Channels/IncludeOwnSystemSniff.php 5 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -19,7 +19,7 @@  discard block
 block discarded – undo
19 19
     /**
20 20
      * Returns an array of tokens this test wants to listen for.
21 21
      *
22
-     * @return array
22
+     * @return integer[]
23 23
      */
24 24
     public function register()
25 25
     {
@@ -82,7 +82,7 @@  discard block
 block discarded – undo
82 82
      * @param int                         $stackPtr  The position in the tokens array of the
83 83
      *                                               potentially included class.
84 84
      *
85
-     * @return string
85
+     * @return boolean
86 86
      */
87 87
     protected function getIncludedClassFromToken(
88 88
         $phpcsFile,
Please login to merge, or discard this patch.
Indentation   +77 added lines, -77 removed lines patch added patch discarded remove patch
@@ -16,83 +16,83 @@
 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_DOUBLE_COLON];
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
-        $fileName = $phpcsFile->getFilename();
43
-        $matches  = [];
44
-        if (preg_match('|/systems/(.*)/([^/]+)?actions.inc$|i', $fileName, $matches) === 0) {
45
-            // Not an actions file.
46
-            return;
47
-        }
48
-
49
-        $ownClass = $matches[2];
50
-        $tokens   = $phpcsFile->getTokens();
51
-
52
-        $typeName = $phpcsFile->findNext(T_CONSTANT_ENCAPSED_STRING, ($stackPtr + 2), null, false, true);
53
-        $typeName = trim($tokens[$typeName]['content'], " '");
54
-        switch (strtolower($tokens[($stackPtr + 1)]['content'])) {
55
-        case 'includesystem' :
56
-            $included = strtolower($typeName);
57
-            break;
58
-        case 'includeasset' :
59
-            $included = strtolower($typeName).'assettype';
60
-            break;
61
-        case 'includewidget' :
62
-            $included = strtolower($typeName).'widgettype';
63
-            break;
64
-        default:
65
-            return;
66
-        }
67
-
68
-        if ($included === strtolower($ownClass)) {
69
-            $error = "You do not need to include \"%s\" from within the system's own actions file";
70
-            $data  = [$ownClass];
71
-            $phpcsFile->addError($error, $stackPtr, 'NotRequired', $data);
72
-        }
73
-
74
-    }//end process()
75
-
76
-
77
-    /**
78
-     * Determines the included class name from given token.
79
-     *
80
-     * @param \PHP_CodeSniffer\Files\File $phpcsFile The file where this token was found.
81
-     * @param array                       $tokens    The array of file tokens.
82
-     * @param int                         $stackPtr  The position in the tokens array of the
83
-     *                                               potentially included class.
84
-     *
85
-     * @return string
86
-     */
87
-    protected function getIncludedClassFromToken(
88
-        $phpcsFile,
89
-        array $tokens,
90
-        $stackPtr
91
-    ) {
92
-
93
-        return false;
94
-
95
-    }//end getIncludedClassFromToken()
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_DOUBLE_COLON];
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
+		$fileName = $phpcsFile->getFilename();
43
+		$matches  = [];
44
+		if (preg_match('|/systems/(.*)/([^/]+)?actions.inc$|i', $fileName, $matches) === 0) {
45
+			// Not an actions file.
46
+			return;
47
+		}
48
+
49
+		$ownClass = $matches[2];
50
+		$tokens   = $phpcsFile->getTokens();
51
+
52
+		$typeName = $phpcsFile->findNext(T_CONSTANT_ENCAPSED_STRING, ($stackPtr + 2), null, false, true);
53
+		$typeName = trim($tokens[$typeName]['content'], " '");
54
+		switch (strtolower($tokens[($stackPtr + 1)]['content'])) {
55
+		case 'includesystem' :
56
+			$included = strtolower($typeName);
57
+			break;
58
+		case 'includeasset' :
59
+			$included = strtolower($typeName).'assettype';
60
+			break;
61
+		case 'includewidget' :
62
+			$included = strtolower($typeName).'widgettype';
63
+			break;
64
+		default:
65
+			return;
66
+		}
67
+
68
+		if ($included === strtolower($ownClass)) {
69
+			$error = "You do not need to include \"%s\" from within the system's own actions file";
70
+			$data  = [$ownClass];
71
+			$phpcsFile->addError($error, $stackPtr, 'NotRequired', $data);
72
+		}
73
+
74
+	}//end process()
75
+
76
+
77
+	/**
78
+	 * Determines the included class name from given token.
79
+	 *
80
+	 * @param \PHP_CodeSniffer\Files\File $phpcsFile The file where this token was found.
81
+	 * @param array                       $tokens    The array of file tokens.
82
+	 * @param int                         $stackPtr  The position in the tokens array of the
83
+	 *                                               potentially included class.
84
+	 *
85
+	 * @return string
86
+	 */
87
+	protected function getIncludedClassFromToken(
88
+		$phpcsFile,
89
+		array $tokens,
90
+		$stackPtr
91
+	) {
92
+
93
+		return false;
94
+
95
+	}//end getIncludedClassFromToken()
96 96
 
97 97
 
98 98
 }//end class
Please login to merge, or discard this patch.
Switch Indentation   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -52,17 +52,17 @@
 block discarded – undo
52 52
         $typeName = $phpcsFile->findNext(T_CONSTANT_ENCAPSED_STRING, ($stackPtr + 2), null, false, true);
53 53
         $typeName = trim($tokens[$typeName]['content'], " '");
54 54
         switch (strtolower($tokens[($stackPtr + 1)]['content'])) {
55
-        case 'includesystem' :
56
-            $included = strtolower($typeName);
57
-            break;
58
-        case 'includeasset' :
59
-            $included = strtolower($typeName).'assettype';
60
-            break;
61
-        case 'includewidget' :
62
-            $included = strtolower($typeName).'widgettype';
63
-            break;
64
-        default:
65
-            return;
55
+        	case 'includesystem' :
56
+            	$included = strtolower($typeName);
57
+            	break;
58
+        	case 'includeasset' :
59
+            	$included = strtolower($typeName).'assettype';
60
+            	break;
61
+        	case 'includewidget' :
62
+            	$included = strtolower($typeName).'widgettype';
63
+            	break;
64
+        	default:
65
+            	return;
66 66
         }
67 67
 
68 68
         if ($included === strtolower($ownClass)) {
Please login to merge, or discard this patch.
Spacing   +14 added lines, -14 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_DOUBLE_COLON];
26
+        return [ T_DOUBLE_COLON ];
27 27
 
28 28
     }//end register()
29 29
 
@@ -37,38 +37,38 @@  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 42
         $fileName = $phpcsFile->getFilename();
43
-        $matches  = [];
44
-        if (preg_match('|/systems/(.*)/([^/]+)?actions.inc$|i', $fileName, $matches) === 0) {
43
+        $matches  = [ ];
44
+        if ( preg_match( '|/systems/(.*)/([^/]+)?actions.inc$|i', $fileName, $matches ) === 0 ) {
45 45
             // Not an actions file.
46 46
             return;
47 47
         }
48 48
 
49
-        $ownClass = $matches[2];
49
+        $ownClass = $matches[ 2 ];
50 50
         $tokens   = $phpcsFile->getTokens();
51 51
 
52
-        $typeName = $phpcsFile->findNext(T_CONSTANT_ENCAPSED_STRING, ($stackPtr + 2), null, false, true);
53
-        $typeName = trim($tokens[$typeName]['content'], " '");
54
-        switch (strtolower($tokens[($stackPtr + 1)]['content'])) {
52
+        $typeName = $phpcsFile->findNext( T_CONSTANT_ENCAPSED_STRING, ( $stackPtr + 2 ), null, false, true );
53
+        $typeName = trim( $tokens[ $typeName ][ 'content' ], " '" );
54
+        switch ( strtolower( $tokens[ ( $stackPtr + 1 ) ][ 'content' ] ) ) {
55 55
         case 'includesystem' :
56
-            $included = strtolower($typeName);
56
+            $included = strtolower( $typeName );
57 57
             break;
58 58
         case 'includeasset' :
59
-            $included = strtolower($typeName).'assettype';
59
+            $included = strtolower( $typeName ) . 'assettype';
60 60
             break;
61 61
         case 'includewidget' :
62
-            $included = strtolower($typeName).'widgettype';
62
+            $included = strtolower( $typeName ) . 'widgettype';
63 63
             break;
64 64
         default:
65 65
             return;
66 66
         }
67 67
 
68
-        if ($included === strtolower($ownClass)) {
68
+        if ( $included === strtolower( $ownClass ) ) {
69 69
             $error = "You do not need to include \"%s\" from within the system's own actions file";
70
-            $data  = [$ownClass];
71
-            $phpcsFile->addError($error, $stackPtr, 'NotRequired', $data);
70
+            $data  = [ $ownClass ];
71
+            $phpcsFile->addError( $error, $stackPtr, 'NotRequired', $data );
72 72
         }
73 73
 
74 74
     }//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 IncludeOwnSystemSniff implements Sniff
16
-{
15
+class IncludeOwnSystemSniff 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_DOUBLE_COLON];
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
         $fileName = $phpcsFile->getFilename();
43 40
         $matches  = [];
44 41
         if (preg_match('|/systems/(.*)/([^/]+)?actions.inc$|i', $fileName, $matches) === 0) {
Please login to merge, or discard this patch.
src/Standards/MySource/Tests/Channels/DisallowSelfActionsUnitTest.inc 4 patches
Doc Comments   +3 added lines patch added patch discarded remove patch
@@ -35,6 +35,9 @@
 block discarded – undo
35 35
 
36 36
 abstract class AbstractEditingScreenModeWidgetActions extends AbstractEditingModeWidgetActions {
37 37
 
38
+    /**
39
+     * @param string $systemName
40
+     */
38 41
     public static function getScreens($systemName)
39 42
     {
40 43
 
Please login to merge, or discard this patch.
Indentation   +37 added lines, -37 removed lines patch added patch discarded remove patch
@@ -2,50 +2,50 @@
 block discarded – undo
2 2
 class SomethingActions
3 3
 {
4 4
 
5
-    private static function _x()
6
-    {
7
-    }
8
-
9
-
10
-    public static function y()
11
-    {
12
-        self::z();
13
-        static::z();
14
-        SomethingActions::z();
15
-        static::_x();
16
-        self::a();
17
-        static::a();
18
-    }
19
-
20
-
21
-    public static function z()
22
-    {
23
-    }
24
-
25
-    protected static function a()
26
-    {
27
-        self::a(); // recursion, yay!
28
-        self::z();
29
-        static::y();
30
-        self::b();
31
-        echo self::$_myVar;
32
-        echo static::$yourVar;
33
-    }
5
+	private static function _x()
6
+	{
7
+	}
8
+
9
+
10
+	public static function y()
11
+	{
12
+		self::z();
13
+		static::z();
14
+		SomethingActions::z();
15
+		static::_x();
16
+		self::a();
17
+		static::a();
18
+	}
19
+
20
+
21
+	public static function z()
22
+	{
23
+	}
24
+
25
+	protected static function a()
26
+	{
27
+		self::a(); // recursion, yay!
28
+		self::z();
29
+		static::y();
30
+		self::b();
31
+		echo self::$_myVar;
32
+		echo static::$yourVar;
33
+	}
34 34
 }
35 35
 
36 36
 abstract class AbstractEditingScreenModeWidgetActions extends AbstractEditingModeWidgetActions {
37 37
 
38
-    public static function getScreens($systemName)
39
-    {
38
+	public static function getScreens($systemName)
39
+	{
40 40
 
41
-    }//end getScreens()
41
+	}//end getScreens()
42 42
 
43
-    public static function setHelpScreenTitle()
44
-    {
45
-        // This is allowed because we are in an abstract class.
46
-        $screens = self::getScreens('');
43
+	public static function setHelpScreenTitle()
44
+	{
45
+		// This is allowed because we are in an abstract class.
46
+		$screens = self::getScreens('');
47 47
 
48
-    }//end setHelpScreenTitle()
48
+	}//end setHelpScreenTitle()
49 49
 
50 50
 }//end class
51 51
 ?>
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -35,7 +35,7 @@  discard block
 block discarded – undo
35 35
 
36 36
 abstract class AbstractEditingScreenModeWidgetActions extends AbstractEditingModeWidgetActions {
37 37
 
38
-    public static function getScreens($systemName)
38
+    public static function getScreens( $systemName )
39 39
     {
40 40
 
41 41
     }//end getScreens()
@@ -43,7 +43,7 @@  discard block
 block discarded – undo
43 43
     public static function setHelpScreenTitle()
44 44
     {
45 45
         // This is allowed because we are in an abstract class.
46
-        $screens = self::getScreens('');
46
+        $screens = self::getScreens( '' );
47 47
 
48 48
     }//end setHelpScreenTitle()
49 49
 
Please login to merge, or discard this patch.
Braces   +7 added lines, -14 removed lines patch added patch discarded remove patch
@@ -1,14 +1,11 @@  discard block
 block discarded – undo
1 1
 <?php
2
-class SomethingActions
3
-{
2
+class SomethingActions {
4 3
 
5
-    private static function _x()
6
-    {
4
+    private static function _x() {
7 5
     }
8 6
 
9 7
 
10
-    public static function y()
11
-    {
8
+    public static function y() {
12 9
         self::z();
13 10
         static::z();
14 11
         SomethingActions::z();
@@ -18,12 +15,10 @@  discard block
 block discarded – undo
18 15
     }
19 16
 
20 17
 
21
-    public static function z()
22
-    {
18
+    public static function z() {
23 19
     }
24 20
 
25
-    protected static function a()
26
-    {
21
+    protected static function a() {
27 22
         self::a(); // recursion, yay!
28 23
         self::z();
29 24
         static::y();
@@ -35,13 +30,11 @@  discard block
 block discarded – undo
35 30
 
36 31
 abstract class AbstractEditingScreenModeWidgetActions extends AbstractEditingModeWidgetActions {
37 32
 
38
-    public static function getScreens($systemName)
39
-    {
33
+    public static function getScreens($systemName) {
40 34
 
41 35
     }//end getScreens()
42 36
 
43
-    public static function setHelpScreenTitle()
44
-    {
37
+    public static function setHelpScreenTitle() {
45 38
         // This is allowed because we are in an abstract class.
46 39
         $screens = self::getScreens('');
47 40
 
Please login to merge, or discard this patch.
src/Standards/PEAR/Tests/Commenting/FunctionCommentUnitTest.inc 4 patches
Doc Comments   +2 added lines, -3 removed lines patch added patch discarded remove patch
@@ -9,10 +9,10 @@  discard block
 block discarded – undo
9 9
      *
10 10
      * @param int $stackPtr   The position in @ @unknown the stack of the token
11 11
      *                        that opened the scope
12
-     * @param int $detph    How many scope levels down we are.
12
+     * @param int $depth    How many scope levels down we are.
13 13
      * @param int    $index    The index
14 14
      * @return
15
-     * @throws
15
+     integer @throws
16 16
      */
17 17
     private function _functionCall($stackPtr, $depth=1, $index)
18 18
     {
@@ -121,7 +121,6 @@  discard block
 block discarded – undo
121 121
      *
122 122
      * @return
123 123
      * @param   int   $threeSpaces
124
-     * @param int     $superfluous
125 124
      * @param missing
126 125
      * @param
127 126
      */
Please login to merge, or discard this patch.
Indentation   +161 added lines, -161 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
 /**
Please login to merge, or discard this patch.
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -14,7 +14,7 @@  discard block
 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
 
@@ -110,7 +110,7 @@  discard block
 block discarded – undo
110 110
      * no return tag
111 111
      *
112 112
      */
113
-    public function noReturn($one)
113
+    public function noReturn( $one )
114 114
     {
115 115
 
116 116
     }//end noReturn()
@@ -125,7 +125,7 @@  discard block
 block discarded – undo
125 125
      * @param missing
126 126
      * @param
127 127
      */
128
-    public function missingDescription($threeSpaces)
128
+    public function missingDescription( $threeSpaces )
129 129
     {
130 130
 
131 131
     }//end missingDescription()
@@ -140,7 +140,7 @@  discard block
 block discarded – undo
140 140
      *
141 141
      * @return void
142 142
      */
143
-    public function oneSpaceAfterLongestVar($one, $two, $three)
143
+    public function oneSpaceAfterLongestVar( $one, $two, $three )
144 144
     {
145 145
 
146 146
     }//end oneSpaceAfterLongestVar()
@@ -157,7 +157,7 @@  discard block
 block discarded – undo
157 157
  *
158 158
  * @return void
159 159
  */
160
-function functionOutsideClass(&$str, &$foo)
160
+function functionOutsideClass( &$str, &$foo )
161 161
 {
162 162
     return;
163 163
 }//end functionOutsideClass()
@@ -195,7 +195,7 @@  discard block
 block discarded – undo
195 195
  * @return void
196 196
  * @fine  Unknown tag
197 197
  */
198
-function missingTwoParamComment($one, $two, $three)
198
+function missingTwoParamComment( $one, $two, $three )
199 199
 {
200 200
 
201 201
 }//end missingTwoParamComment()
@@ -217,7 +217,7 @@  discard block
 block discarded – undo
217 217
  * @access public
218 218
  * @return bool
219 219
  */
220
-function myFunction($arg1) {}
220
+function myFunction( $arg1 ) {}
221 221
 
222 222
 
223 223
 /**
@@ -231,7 +231,7 @@  discard block
 block discarded – undo
231 231
 
232 232
 echo $blah;
233 233
 
234
-function myFunction($arg1) {}
234
+function myFunction( $arg1 ) {}
235 235
 
236 236
 /**
237 237
  * Test function.
@@ -261,7 +261,7 @@  discard block
 block discarded – undo
261 261
  *
262 262
  * @return void
263 263
  */
264
-function foo(&$tokens, $tokenizer, $eolChar)
264
+function foo( &$tokens, $tokenizer, $eolChar )
265 265
 {
266 266
 
267 267
 }//end foo()
@@ -294,7 +294,7 @@  discard block
 block discarded – undo
294 294
  *
295 295
  * @return void
296 296
  */
297
-function completeStep($status, array $array = [Class1::class, 'test'], $note = '') {
297
+function completeStep( $status, array $array = [ Class1::class, 'test' ], $note = '' ) {
298 298
     echo 'foo';
299 299
 }
300 300
 
@@ -306,7 +306,7 @@  discard block
 block discarded – undo
306 306
  *
307 307
  * @return void
308 308
  */
309
-function myFunction(string $name1, string ...$name2) {
309
+function myFunction( string $name1, string ...$name2 ) {
310 310
 }
311 311
 
312 312
 
@@ -318,7 +318,7 @@  discard block
 block discarded – undo
318 318
  *
319 319
  * @return void
320 320
  */
321
-function myFunction(string $name1, string ...$name2) {
321
+function myFunction( string $name1, string ...$name2 ) {
322 322
 }
323 323
 
324 324
 /**
@@ -333,7 +333,7 @@  discard block
 block discarded – undo
333 333
  *   Return value
334 334
  *
335 335
  */
336
-function foo($bar) {
336
+function foo( $bar ) {
337 337
 }
338 338
 
339 339
 /**
@@ -348,7 +348,7 @@  discard block
 block discarded – undo
348 348
  * @return void
349 349
  * @see    register()
350 350
  */
351
-function process(File $phpcsFile, $stackPtr)
351
+function process( File $phpcsFile, $stackPtr )
352 352
 {
353 353
 
354 354
 }//end process()
@@ -366,7 +366,7 @@  discard block
 block discarded – undo
366 366
  * @return void
367 367
  * @see    register()
368 368
  */
369
-function process(File $phpcsFile, $stackPtr)
369
+function process( File $phpcsFile, $stackPtr )
370 370
 {
371 371
 
372 372
 }//end process()
Please login to merge, or discard this patch.
Braces   +22 added lines, -44 removed lines patch added patch discarded remove patch
@@ -1,6 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-class PHP_CodeSniffer_File
3
-{
2
+class PHP_CodeSniffer_File {
4 3
 
5 4
     /**
6 5
      * A simple function comment.
@@ -14,8 +13,7 @@  discard block
 block discarded – undo
14 13
      * @return
15 14
      * @throws
16 15
      */
17
-    private function _functionCall($stackPtr, $depth=1, $index)
18
-    {
16
+    private function _functionCall($stackPtr, $depth=1, $index) {
19 17
         return $stackPtr;
20 18
 
21 19
     }//end _functionCall()
@@ -25,8 +23,7 @@  discard block
 block discarded – undo
25 23
     //
26 24
     //
27 25
     //
28
-    public function invalidCommentStyle()
29
-    {
26
+    public function invalidCommentStyle() {
30 27
 
31 28
     }//end invalidCommentStyle()
32 29
 
@@ -42,8 +39,7 @@  discard block
 block discarded – undo
42 39
      *
43 40
      * @return void
44 41
      */
45
-    public function extraDescriptionNewlines()
46
-    {
42
+    public function extraDescriptionNewlines() {
47 43
 
48 44
     }//end extraDescriptionNewlines()
49 45
 
@@ -52,8 +48,7 @@  discard block
 block discarded – undo
52 48
      * A simple function comment
53 49
      * @return void
54 50
      */
55
-    public function missingNewlinesBeforeTags()
56
-    {
51
+    public function missingNewlinesBeforeTags() {
57 52
 
58 53
     }//end missingNewlinesBeforeTags()
59 54
 
@@ -64,8 +59,7 @@  discard block
 block discarded – undo
64 59
      * @access public
65 60
      * @return void
66 61
      */
67
-    public function accessTag()
68
-    {
62
+    public function accessTag() {
69 63
 
70 64
     }//end accessTag()
71 65
 
@@ -74,8 +68,7 @@  discard block
 block discarded – undo
74 68
      *
75 69
      * No return tag
76 70
      */
77
-    function PHP_CodeSniffer_File()
78
-    {
71
+    function PHP_CodeSniffer_File() {
79 72
         return;
80 73
     }
81 74
 
@@ -85,8 +78,7 @@  discard block
 block discarded – undo
85 78
      *
86 79
      * No return tag too
87 80
      */
88
-    function _PHP_CodeSniffer_File()
89
-    {
81
+    function _PHP_CodeSniffer_File() {
90 82
         return;
91 83
     }
92 84
 
@@ -94,14 +86,12 @@  discard block
 block discarded – undo
94 86
     /**
95 87
      * Destructor PHP5
96 88
      */
97
-    function __destruct()
98
-    {
89
+    function __destruct() {
99 90
         return;
100 91
     }
101 92
 
102 93
 
103
-    function missingComment()
104
-    {
94
+    function missingComment() {
105 95
         return;
106 96
     }
107 97
 
@@ -110,8 +100,7 @@  discard block
 block discarded – undo
110 100
      * no return tag
111 101
      *
112 102
      */
113
-    public function noReturn($one)
114
-    {
103
+    public function noReturn($one) {
115 104
 
116 105
     }//end noReturn()
117 106
 
@@ -125,8 +114,7 @@  discard block
 block discarded – undo
125 114
      * @param missing
126 115
      * @param
127 116
      */
128
-    public function missingDescription($threeSpaces)
129
-    {
117
+    public function missingDescription($threeSpaces) {
130 118
 
131 119
     }//end missingDescription()
132 120
 
@@ -140,8 +128,7 @@  discard block
 block discarded – undo
140 128
      *
141 129
      * @return void
142 130
      */
143
-    public function oneSpaceAfterLongestVar($one, $two, $three)
144
-    {
131
+    public function oneSpaceAfterLongestVar($one, $two, $three) {
145 132
 
146 133
     }//end oneSpaceAfterLongestVar()
147 134
 
@@ -157,20 +144,17 @@  discard block
 block discarded – undo
157 144
  *
158 145
  * @return void
159 146
  */
160
-function functionOutsideClass(&$str, &$foo)
161
-{
147
+function functionOutsideClass(&$str, &$foo) {
162 148
     return;
163 149
 }//end functionOutsideClass()
164 150
 
165
-function missingCommentOutsideClass()
166
-{
151
+function missingCommentOutsideClass() {
167 152
     return;
168 153
 }//end missingCommentOutsideClass()
169 154
 
170 155
 
171 156
 ?><?php
172
-function tagBeforeComment()
173
-{
157
+function tagBeforeComment() {
174 158
     return;
175 159
 }//end tagBeforeComment()
176 160
 
@@ -181,8 +165,7 @@  discard block
 block discarded – undo
181 165
  *
182 166
  *
183 167
  */
184
-function noReturnOutsideClass()
185
-{
168
+function noReturnOutsideClass() {
186 169
 
187 170
 }//end noReturnOutsideClass()
188 171
 
@@ -195,8 +178,7 @@  discard block
 block discarded – undo
195 178
  * @return void
196 179
  * @fine  Unknown tag
197 180
  */
198
-function missingTwoParamComment($one, $two, $three)
199
-{
181
+function missingTwoParamComment($one, $two, $three) {
200 182
 
201 183
 }//end missingTwoParamComment()
202 184
 
@@ -204,8 +186,7 @@  discard block
 block discarded – undo
204 186
 /**
205 187
  *
206 188
  */
207
-function emptyFunctionDocComment()
208
-{
189
+function emptyFunctionDocComment() {
209 190
 }//end emptyFunctionDocComment()
210 191
 
211 192
 
@@ -261,8 +242,7 @@  discard block
 block discarded – undo
261 242
  *
262 243
  * @return void
263 244
  */
264
-function foo(&$tokens, $tokenizer, $eolChar)
265
-{
245
+function foo(&$tokens, $tokenizer, $eolChar) {
266 246
 
267 247
 }//end foo()
268 248
 
@@ -348,8 +328,7 @@  discard block
 block discarded – undo
348 328
  * @return void
349 329
  * @see    register()
350 330
  */
351
-function process(File $phpcsFile, $stackPtr)
352
-{
331
+function process(File $phpcsFile, $stackPtr) {
353 332
 
354 333
 }//end process()
355 334
 
@@ -366,7 +345,6 @@  discard block
 block discarded – undo
366 345
  * @return void
367 346
  * @see    register()
368 347
  */
369
-function process(File $phpcsFile, $stackPtr)
370
-{
348
+function process(File $phpcsFile, $stackPtr) {
371 349
 
372 350
 }//end process()
Please login to merge, or discard this patch.
php_codesniffer/src/Standards/PSR1/Sniffs/Files/SideEffectsSniff.php 4 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -20,7 +20,7 @@  discard block
 block discarded – undo
20 20
     /**
21 21
      * Returns an array of tokens this test wants to listen for.
22 22
      *
23
-     * @return array
23
+     * @return integer[]
24 24
      */
25 25
     public function register()
26 26
     {
@@ -36,7 +36,7 @@  discard block
 block discarded – undo
36 36
      * @param int                         $stackPtr  The position of the current token in
37 37
      *                                               the token stack.
38 38
      *
39
-     * @return void
39
+     * @return integer
40 40
      */
41 41
     public function process(File $phpcsFile, $stackPtr)
42 42
     {
Please login to merge, or discard this patch.
Indentation   +259 added lines, -259 removed lines patch added patch discarded remove patch
@@ -17,265 +17,265 @@
 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 [T_OPEN_TAG];
28
-
29
-    }//end register()
30
-
31
-
32
-    /**
33
-     * Processes this sniff, 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 token stack.
38
-     *
39
-     * @return void
40
-     */
41
-    public function process(File $phpcsFile, $stackPtr)
42
-    {
43
-        $tokens = $phpcsFile->getTokens();
44
-        $result = $this->searchForConflict($phpcsFile, 0, ($phpcsFile->numTokens - 1), $tokens);
45
-
46
-        if ($result['symbol'] !== null && $result['effect'] !== null) {
47
-            $error = 'A file should declare new symbols (classes, functions, constants, etc.) and cause no other side effects, or it should execute logic with side effects, but should not do both. The first symbol is defined on line %s and the first side effect is on line %s.';
48
-            $data  = [
49
-                $tokens[$result['symbol']]['line'],
50
-                $tokens[$result['effect']]['line'],
51
-            ];
52
-            $phpcsFile->addWarning($error, 0, 'FoundWithSymbols', $data);
53
-            $phpcsFile->recordMetric($stackPtr, 'Declarations and side effects mixed', 'yes');
54
-        } else {
55
-            $phpcsFile->recordMetric($stackPtr, 'Declarations and side effects mixed', 'no');
56
-        }
57
-
58
-        // Ignore the rest of the file.
59
-        return ($phpcsFile->numTokens + 1);
60
-
61
-    }//end process()
62
-
63
-
64
-    /**
65
-     * Searches for symbol declarations and side effects.
66
-     *
67
-     * Returns the positions of both the first symbol declared and the first
68
-     * side effect in the file. A NULL value for either indicates nothing was
69
-     * found.
70
-     *
71
-     * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.
72
-     * @param int                         $start     The token to start searching from.
73
-     * @param int                         $end       The token to search to.
74
-     * @param array                       $tokens    The stack of tokens that make up
75
-     *                                               the file.
76
-     *
77
-     * @return array
78
-     */
79
-    private function searchForConflict($phpcsFile, $start, $end, $tokens)
80
-    {
81
-        $symbols = [
82
-            T_CLASS     => T_CLASS,
83
-            T_INTERFACE => T_INTERFACE,
84
-            T_TRAIT     => T_TRAIT,
85
-            T_FUNCTION  => T_FUNCTION,
86
-        ];
87
-
88
-        $conditions = [
89
-            T_IF     => T_IF,
90
-            T_ELSE   => T_ELSE,
91
-            T_ELSEIF => T_ELSEIF,
92
-        ];
93
-
94
-        $checkAnnotations = $phpcsFile->config->annotations;
95
-
96
-        $firstSymbol = null;
97
-        $firstEffect = null;
98
-        for ($i = $start; $i <= $end; $i++) {
99
-            // Respect phpcs:disable comments.
100
-            if ($checkAnnotations === true
101
-                && $tokens[$i]['code'] === T_PHPCS_DISABLE
102
-                && (empty($tokens[$i]['sniffCodes']) === true
103
-                || isset($tokens[$i]['sniffCodes']['PSR1']) === true
104
-                || isset($tokens[$i]['sniffCodes']['PSR1.Files']) === true
105
-                || isset($tokens[$i]['sniffCodes']['PSR1.Files.SideEffects']) === true)
106
-            ) {
107
-                do {
108
-                    $i = $phpcsFile->findNext(T_PHPCS_ENABLE, ($i + 1));
109
-                } while ($i !== false
110
-                    && empty($tokens[$i]['sniffCodes']) === false
111
-                    && isset($tokens[$i]['sniffCodes']['PSR1']) === false
112
-                    && isset($tokens[$i]['sniffCodes']['PSR1.Files']) === false
113
-                    && isset($tokens[$i]['sniffCodes']['PSR1.Files.SideEffects']) === false);
114
-
115
-                if ($i === false) {
116
-                    // The entire rest of the file is disabled,
117
-                    // so return what we have so far.
118
-                    break;
119
-                }
120
-
121
-                continue;
122
-            }
123
-
124
-            // Ignore whitespace and comments.
125
-            if (isset(Tokens::$emptyTokens[$tokens[$i]['code']]) === true) {
126
-                continue;
127
-            }
128
-
129
-            // Ignore PHP tags.
130
-            if ($tokens[$i]['code'] === T_OPEN_TAG
131
-                || $tokens[$i]['code'] === T_CLOSE_TAG
132
-            ) {
133
-                continue;
134
-            }
135
-
136
-            // Ignore shebang.
137
-            if (substr($tokens[$i]['content'], 0, 2) === '#!') {
138
-                continue;
139
-            }
140
-
141
-            // Ignore logical operators.
142
-            if (isset(Tokens::$booleanOperators[$tokens[$i]['code']]) === true) {
143
-                continue;
144
-            }
145
-
146
-            // Ignore entire namespace, declare, const and use statements.
147
-            if ($tokens[$i]['code'] === T_NAMESPACE
148
-                || $tokens[$i]['code'] === T_USE
149
-                || $tokens[$i]['code'] === T_DECLARE
150
-                || $tokens[$i]['code'] === T_CONST
151
-            ) {
152
-                if (isset($tokens[$i]['scope_opener']) === true) {
153
-                    $i = $tokens[$i]['scope_closer'];
154
-                } else {
155
-                    $semicolon = $phpcsFile->findNext(T_SEMICOLON, ($i + 1));
156
-                    if ($semicolon !== false) {
157
-                        $i = $semicolon;
158
-                    }
159
-                }
160
-
161
-                continue;
162
-            }
163
-
164
-            // Ignore function/class prefixes.
165
-            if (isset(Tokens::$methodPrefixes[$tokens[$i]['code']]) === true) {
166
-                continue;
167
-            }
168
-
169
-            // Ignore anon classes.
170
-            if ($tokens[$i]['code'] === T_ANON_CLASS) {
171
-                $i = $tokens[$i]['scope_closer'];
172
-                continue;
173
-            }
174
-
175
-            // Detect and skip over symbols.
176
-            if (isset($symbols[$tokens[$i]['code']]) === true
177
-                && isset($tokens[$i]['scope_closer']) === true
178
-            ) {
179
-                if ($firstSymbol === null) {
180
-                    $firstSymbol = $i;
181
-                }
182
-
183
-                $i = $tokens[$i]['scope_closer'];
184
-                continue;
185
-            } else if ($tokens[$i]['code'] === T_STRING
186
-                && strtolower($tokens[$i]['content']) === 'define'
187
-            ) {
188
-                $prev = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($i - 1), null, true);
189
-                if ($tokens[$prev]['code'] !== T_OBJECT_OPERATOR
190
-                    && $tokens[$prev]['code'] !== T_DOUBLE_COLON
191
-                    && $tokens[$prev]['code'] !== T_FUNCTION
192
-                ) {
193
-                    if ($firstSymbol === null) {
194
-                        $firstSymbol = $i;
195
-                    }
196
-
197
-                    $semicolon = $phpcsFile->findNext(T_SEMICOLON, ($i + 1));
198
-                    if ($semicolon !== false) {
199
-                        $i = $semicolon;
200
-                    }
201
-
202
-                    continue;
203
-                }
204
-            }//end if
205
-
206
-            // Special case for defined() as it can be used to see
207
-            // if a constant (a symbol) should be defined or not and
208
-            // doesn't need to use a full conditional block.
209
-            if ($tokens[$i]['code'] === T_STRING
210
-                && strtolower($tokens[$i]['content']) === 'defined'
211
-            ) {
212
-                $openBracket = $phpcsFile->findNext(Tokens::$emptyTokens, ($i + 1), null, true);
213
-                if ($tokens[$openBracket]['code'] === T_OPEN_PARENTHESIS
214
-                    && isset($tokens[$openBracket]['parenthesis_closer']) === true
215
-                ) {
216
-                    $prev = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($i - 1), null, true);
217
-                    if ($tokens[$prev]['code'] !== T_OBJECT_OPERATOR
218
-                        && $tokens[$prev]['code'] !== T_DOUBLE_COLON
219
-                        && $tokens[$prev]['code'] !== T_FUNCTION
220
-                    ) {
221
-                        $i = $tokens[$openBracket]['parenthesis_closer'];
222
-                        continue;
223
-                    }
224
-                }
225
-            }//end if
226
-
227
-            // Conditional statements are allowed in symbol files as long as the
228
-            // contents is only a symbol definition. So don't count these as effects
229
-            // in this case.
230
-            if (isset($conditions[$tokens[$i]['code']]) === true) {
231
-                if (isset($tokens[$i]['scope_opener']) === false) {
232
-                    // Probably an "else if", so just ignore.
233
-                    continue;
234
-                }
235
-
236
-                $result = $this->searchForConflict(
237
-                    $phpcsFile,
238
-                    ($tokens[$i]['scope_opener'] + 1),
239
-                    ($tokens[$i]['scope_closer'] - 1),
240
-                    $tokens
241
-                );
242
-
243
-                if ($result['symbol'] !== null) {
244
-                    if ($firstSymbol === null) {
245
-                        $firstSymbol = $result['symbol'];
246
-                    }
247
-
248
-                    if ($result['effect'] !== null) {
249
-                        // Found a conflict.
250
-                        $firstEffect = $result['effect'];
251
-                        break;
252
-                    }
253
-                }
254
-
255
-                if ($firstEffect === null) {
256
-                    $firstEffect = $result['effect'];
257
-                }
258
-
259
-                $i = $tokens[$i]['scope_closer'];
260
-                continue;
261
-            }//end if
262
-
263
-            if ($firstEffect === null) {
264
-                $firstEffect = $i;
265
-            }
266
-
267
-            if ($firstSymbol !== null) {
268
-                // We have a conflict we have to report, so no point continuing.
269
-                break;
270
-            }
271
-        }//end for
272
-
273
-        return [
274
-            'symbol' => $firstSymbol,
275
-            'effect' => $firstEffect,
276
-        ];
277
-
278
-    }//end searchForConflict()
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 [T_OPEN_TAG];
28
+
29
+	}//end register()
30
+
31
+
32
+	/**
33
+	 * Processes this sniff, 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 token stack.
38
+	 *
39
+	 * @return void
40
+	 */
41
+	public function process(File $phpcsFile, $stackPtr)
42
+	{
43
+		$tokens = $phpcsFile->getTokens();
44
+		$result = $this->searchForConflict($phpcsFile, 0, ($phpcsFile->numTokens - 1), $tokens);
45
+
46
+		if ($result['symbol'] !== null && $result['effect'] !== null) {
47
+			$error = 'A file should declare new symbols (classes, functions, constants, etc.) and cause no other side effects, or it should execute logic with side effects, but should not do both. The first symbol is defined on line %s and the first side effect is on line %s.';
48
+			$data  = [
49
+				$tokens[$result['symbol']]['line'],
50
+				$tokens[$result['effect']]['line'],
51
+			];
52
+			$phpcsFile->addWarning($error, 0, 'FoundWithSymbols', $data);
53
+			$phpcsFile->recordMetric($stackPtr, 'Declarations and side effects mixed', 'yes');
54
+		} else {
55
+			$phpcsFile->recordMetric($stackPtr, 'Declarations and side effects mixed', 'no');
56
+		}
57
+
58
+		// Ignore the rest of the file.
59
+		return ($phpcsFile->numTokens + 1);
60
+
61
+	}//end process()
62
+
63
+
64
+	/**
65
+	 * Searches for symbol declarations and side effects.
66
+	 *
67
+	 * Returns the positions of both the first symbol declared and the first
68
+	 * side effect in the file. A NULL value for either indicates nothing was
69
+	 * found.
70
+	 *
71
+	 * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.
72
+	 * @param int                         $start     The token to start searching from.
73
+	 * @param int                         $end       The token to search to.
74
+	 * @param array                       $tokens    The stack of tokens that make up
75
+	 *                                               the file.
76
+	 *
77
+	 * @return array
78
+	 */
79
+	private function searchForConflict($phpcsFile, $start, $end, $tokens)
80
+	{
81
+		$symbols = [
82
+			T_CLASS     => T_CLASS,
83
+			T_INTERFACE => T_INTERFACE,
84
+			T_TRAIT     => T_TRAIT,
85
+			T_FUNCTION  => T_FUNCTION,
86
+		];
87
+
88
+		$conditions = [
89
+			T_IF     => T_IF,
90
+			T_ELSE   => T_ELSE,
91
+			T_ELSEIF => T_ELSEIF,
92
+		];
93
+
94
+		$checkAnnotations = $phpcsFile->config->annotations;
95
+
96
+		$firstSymbol = null;
97
+		$firstEffect = null;
98
+		for ($i = $start; $i <= $end; $i++) {
99
+			// Respect phpcs:disable comments.
100
+			if ($checkAnnotations === true
101
+				&& $tokens[$i]['code'] === T_PHPCS_DISABLE
102
+				&& (empty($tokens[$i]['sniffCodes']) === true
103
+				|| isset($tokens[$i]['sniffCodes']['PSR1']) === true
104
+				|| isset($tokens[$i]['sniffCodes']['PSR1.Files']) === true
105
+				|| isset($tokens[$i]['sniffCodes']['PSR1.Files.SideEffects']) === true)
106
+			) {
107
+				do {
108
+					$i = $phpcsFile->findNext(T_PHPCS_ENABLE, ($i + 1));
109
+				} while ($i !== false
110
+					&& empty($tokens[$i]['sniffCodes']) === false
111
+					&& isset($tokens[$i]['sniffCodes']['PSR1']) === false
112
+					&& isset($tokens[$i]['sniffCodes']['PSR1.Files']) === false
113
+					&& isset($tokens[$i]['sniffCodes']['PSR1.Files.SideEffects']) === false);
114
+
115
+				if ($i === false) {
116
+					// The entire rest of the file is disabled,
117
+					// so return what we have so far.
118
+					break;
119
+				}
120
+
121
+				continue;
122
+			}
123
+
124
+			// Ignore whitespace and comments.
125
+			if (isset(Tokens::$emptyTokens[$tokens[$i]['code']]) === true) {
126
+				continue;
127
+			}
128
+
129
+			// Ignore PHP tags.
130
+			if ($tokens[$i]['code'] === T_OPEN_TAG
131
+				|| $tokens[$i]['code'] === T_CLOSE_TAG
132
+			) {
133
+				continue;
134
+			}
135
+
136
+			// Ignore shebang.
137
+			if (substr($tokens[$i]['content'], 0, 2) === '#!') {
138
+				continue;
139
+			}
140
+
141
+			// Ignore logical operators.
142
+			if (isset(Tokens::$booleanOperators[$tokens[$i]['code']]) === true) {
143
+				continue;
144
+			}
145
+
146
+			// Ignore entire namespace, declare, const and use statements.
147
+			if ($tokens[$i]['code'] === T_NAMESPACE
148
+				|| $tokens[$i]['code'] === T_USE
149
+				|| $tokens[$i]['code'] === T_DECLARE
150
+				|| $tokens[$i]['code'] === T_CONST
151
+			) {
152
+				if (isset($tokens[$i]['scope_opener']) === true) {
153
+					$i = $tokens[$i]['scope_closer'];
154
+				} else {
155
+					$semicolon = $phpcsFile->findNext(T_SEMICOLON, ($i + 1));
156
+					if ($semicolon !== false) {
157
+						$i = $semicolon;
158
+					}
159
+				}
160
+
161
+				continue;
162
+			}
163
+
164
+			// Ignore function/class prefixes.
165
+			if (isset(Tokens::$methodPrefixes[$tokens[$i]['code']]) === true) {
166
+				continue;
167
+			}
168
+
169
+			// Ignore anon classes.
170
+			if ($tokens[$i]['code'] === T_ANON_CLASS) {
171
+				$i = $tokens[$i]['scope_closer'];
172
+				continue;
173
+			}
174
+
175
+			// Detect and skip over symbols.
176
+			if (isset($symbols[$tokens[$i]['code']]) === true
177
+				&& isset($tokens[$i]['scope_closer']) === true
178
+			) {
179
+				if ($firstSymbol === null) {
180
+					$firstSymbol = $i;
181
+				}
182
+
183
+				$i = $tokens[$i]['scope_closer'];
184
+				continue;
185
+			} else if ($tokens[$i]['code'] === T_STRING
186
+				&& strtolower($tokens[$i]['content']) === 'define'
187
+			) {
188
+				$prev = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($i - 1), null, true);
189
+				if ($tokens[$prev]['code'] !== T_OBJECT_OPERATOR
190
+					&& $tokens[$prev]['code'] !== T_DOUBLE_COLON
191
+					&& $tokens[$prev]['code'] !== T_FUNCTION
192
+				) {
193
+					if ($firstSymbol === null) {
194
+						$firstSymbol = $i;
195
+					}
196
+
197
+					$semicolon = $phpcsFile->findNext(T_SEMICOLON, ($i + 1));
198
+					if ($semicolon !== false) {
199
+						$i = $semicolon;
200
+					}
201
+
202
+					continue;
203
+				}
204
+			}//end if
205
+
206
+			// Special case for defined() as it can be used to see
207
+			// if a constant (a symbol) should be defined or not and
208
+			// doesn't need to use a full conditional block.
209
+			if ($tokens[$i]['code'] === T_STRING
210
+				&& strtolower($tokens[$i]['content']) === 'defined'
211
+			) {
212
+				$openBracket = $phpcsFile->findNext(Tokens::$emptyTokens, ($i + 1), null, true);
213
+				if ($tokens[$openBracket]['code'] === T_OPEN_PARENTHESIS
214
+					&& isset($tokens[$openBracket]['parenthesis_closer']) === true
215
+				) {
216
+					$prev = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($i - 1), null, true);
217
+					if ($tokens[$prev]['code'] !== T_OBJECT_OPERATOR
218
+						&& $tokens[$prev]['code'] !== T_DOUBLE_COLON
219
+						&& $tokens[$prev]['code'] !== T_FUNCTION
220
+					) {
221
+						$i = $tokens[$openBracket]['parenthesis_closer'];
222
+						continue;
223
+					}
224
+				}
225
+			}//end if
226
+
227
+			// Conditional statements are allowed in symbol files as long as the
228
+			// contents is only a symbol definition. So don't count these as effects
229
+			// in this case.
230
+			if (isset($conditions[$tokens[$i]['code']]) === true) {
231
+				if (isset($tokens[$i]['scope_opener']) === false) {
232
+					// Probably an "else if", so just ignore.
233
+					continue;
234
+				}
235
+
236
+				$result = $this->searchForConflict(
237
+					$phpcsFile,
238
+					($tokens[$i]['scope_opener'] + 1),
239
+					($tokens[$i]['scope_closer'] - 1),
240
+					$tokens
241
+				);
242
+
243
+				if ($result['symbol'] !== null) {
244
+					if ($firstSymbol === null) {
245
+						$firstSymbol = $result['symbol'];
246
+					}
247
+
248
+					if ($result['effect'] !== null) {
249
+						// Found a conflict.
250
+						$firstEffect = $result['effect'];
251
+						break;
252
+					}
253
+				}
254
+
255
+				if ($firstEffect === null) {
256
+					$firstEffect = $result['effect'];
257
+				}
258
+
259
+				$i = $tokens[$i]['scope_closer'];
260
+				continue;
261
+			}//end if
262
+
263
+			if ($firstEffect === null) {
264
+				$firstEffect = $i;
265
+			}
266
+
267
+			if ($firstSymbol !== null) {
268
+				// We have a conflict we have to report, so no point continuing.
269
+				break;
270
+			}
271
+		}//end for
272
+
273
+		return [
274
+			'symbol' => $firstSymbol,
275
+			'effect' => $firstEffect,
276
+		];
277
+
278
+	}//end searchForConflict()
279 279
 
280 280
 
281 281
 }//end class
Please login to merge, or discard this patch.
Spacing   +79 added lines, -79 removed lines patch added patch discarded remove patch
@@ -24,7 +24,7 @@  discard block
 block discarded – undo
24 24
      */
25 25
     public function register()
26 26
     {
27
-        return [T_OPEN_TAG];
27
+        return [ T_OPEN_TAG ];
28 28
 
29 29
     }//end register()
30 30
 
@@ -38,25 +38,25 @@  discard block
 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
-        $result = $this->searchForConflict($phpcsFile, 0, ($phpcsFile->numTokens - 1), $tokens);
44
+        $result = $this->searchForConflict( $phpcsFile, 0, ( $phpcsFile->numTokens - 1 ), $tokens );
45 45
 
46
-        if ($result['symbol'] !== null && $result['effect'] !== null) {
46
+        if ( $result[ 'symbol' ] !== null && $result[ 'effect' ] !== null ) {
47 47
             $error = 'A file should declare new symbols (classes, functions, constants, etc.) and cause no other side effects, or it should execute logic with side effects, but should not do both. The first symbol is defined on line %s and the first side effect is on line %s.';
48 48
             $data  = [
49
-                $tokens[$result['symbol']]['line'],
50
-                $tokens[$result['effect']]['line'],
49
+                $tokens[ $result[ 'symbol' ] ][ 'line' ],
50
+                $tokens[ $result[ 'effect' ] ][ 'line' ],
51 51
             ];
52
-            $phpcsFile->addWarning($error, 0, 'FoundWithSymbols', $data);
53
-            $phpcsFile->recordMetric($stackPtr, 'Declarations and side effects mixed', 'yes');
52
+            $phpcsFile->addWarning( $error, 0, 'FoundWithSymbols', $data );
53
+            $phpcsFile->recordMetric( $stackPtr, 'Declarations and side effects mixed', 'yes' );
54 54
         } else {
55
-            $phpcsFile->recordMetric($stackPtr, 'Declarations and side effects mixed', 'no');
55
+            $phpcsFile->recordMetric( $stackPtr, 'Declarations and side effects mixed', 'no' );
56 56
         }
57 57
 
58 58
         // Ignore the rest of the file.
59
-        return ($phpcsFile->numTokens + 1);
59
+        return ( $phpcsFile->numTokens + 1 );
60 60
 
61 61
     }//end process()
62 62
 
@@ -76,7 +76,7 @@  discard block
 block discarded – undo
76 76
      *
77 77
      * @return array
78 78
      */
79
-    private function searchForConflict($phpcsFile, $start, $end, $tokens)
79
+    private function searchForConflict( $phpcsFile, $start, $end, $tokens )
80 80
     {
81 81
         $symbols = [
82 82
             T_CLASS     => T_CLASS,
@@ -95,24 +95,24 @@  discard block
 block discarded – undo
95 95
 
96 96
         $firstSymbol = null;
97 97
         $firstEffect = null;
98
-        for ($i = $start; $i <= $end; $i++) {
98
+        for ( $i = $start; $i <= $end; $i++ ) {
99 99
             // Respect phpcs:disable comments.
100
-            if ($checkAnnotations === true
101
-                && $tokens[$i]['code'] === T_PHPCS_DISABLE
102
-                && (empty($tokens[$i]['sniffCodes']) === true
103
-                || isset($tokens[$i]['sniffCodes']['PSR1']) === true
104
-                || isset($tokens[$i]['sniffCodes']['PSR1.Files']) === true
105
-                || isset($tokens[$i]['sniffCodes']['PSR1.Files.SideEffects']) === true)
100
+            if ( $checkAnnotations === true
101
+                && $tokens[ $i ][ 'code' ] === T_PHPCS_DISABLE
102
+                && ( empty( $tokens[ $i ][ 'sniffCodes' ] ) === true
103
+                || isset( $tokens[ $i ][ 'sniffCodes' ][ 'PSR1' ] ) === true
104
+                || isset( $tokens[ $i ][ 'sniffCodes' ][ 'PSR1.Files' ] ) === true
105
+                || isset( $tokens[ $i ][ 'sniffCodes' ][ 'PSR1.Files.SideEffects' ] ) === true )
106 106
             ) {
107 107
                 do {
108
-                    $i = $phpcsFile->findNext(T_PHPCS_ENABLE, ($i + 1));
109
-                } while ($i !== false
110
-                    && empty($tokens[$i]['sniffCodes']) === false
111
-                    && isset($tokens[$i]['sniffCodes']['PSR1']) === false
112
-                    && isset($tokens[$i]['sniffCodes']['PSR1.Files']) === false
113
-                    && isset($tokens[$i]['sniffCodes']['PSR1.Files.SideEffects']) === false);
114
-
115
-                if ($i === false) {
108
+                    $i = $phpcsFile->findNext( T_PHPCS_ENABLE, ( $i + 1 ) );
109
+                } while ( $i !== false
110
+                    && empty( $tokens[ $i ][ 'sniffCodes' ] ) === false
111
+                    && isset( $tokens[ $i ][ 'sniffCodes' ][ 'PSR1' ] ) === false
112
+                    && isset( $tokens[ $i ][ 'sniffCodes' ][ 'PSR1.Files' ] ) === false
113
+                    && isset( $tokens[ $i ][ 'sniffCodes' ][ 'PSR1.Files.SideEffects' ] ) === false );
114
+
115
+                if ( $i === false ) {
116 116
                     // The entire rest of the file is disabled,
117 117
                     // so return what we have so far.
118 118
                     break;
@@ -122,38 +122,38 @@  discard block
 block discarded – undo
122 122
             }
123 123
 
124 124
             // Ignore whitespace and comments.
125
-            if (isset(Tokens::$emptyTokens[$tokens[$i]['code']]) === true) {
125
+            if ( isset( Tokens::$emptyTokens[ $tokens[ $i ][ 'code' ] ] ) === true ) {
126 126
                 continue;
127 127
             }
128 128
 
129 129
             // Ignore PHP tags.
130
-            if ($tokens[$i]['code'] === T_OPEN_TAG
131
-                || $tokens[$i]['code'] === T_CLOSE_TAG
130
+            if ( $tokens[ $i ][ 'code' ] === T_OPEN_TAG
131
+                || $tokens[ $i ][ 'code' ] === T_CLOSE_TAG
132 132
             ) {
133 133
                 continue;
134 134
             }
135 135
 
136 136
             // Ignore shebang.
137
-            if (substr($tokens[$i]['content'], 0, 2) === '#!') {
137
+            if ( substr( $tokens[ $i ][ 'content' ], 0, 2 ) === '#!' ) {
138 138
                 continue;
139 139
             }
140 140
 
141 141
             // Ignore logical operators.
142
-            if (isset(Tokens::$booleanOperators[$tokens[$i]['code']]) === true) {
142
+            if ( isset( Tokens::$booleanOperators[ $tokens[ $i ][ 'code' ] ] ) === true ) {
143 143
                 continue;
144 144
             }
145 145
 
146 146
             // Ignore entire namespace, declare, const and use statements.
147
-            if ($tokens[$i]['code'] === T_NAMESPACE
148
-                || $tokens[$i]['code'] === T_USE
149
-                || $tokens[$i]['code'] === T_DECLARE
150
-                || $tokens[$i]['code'] === T_CONST
147
+            if ( $tokens[ $i ][ 'code' ] === T_NAMESPACE
148
+                || $tokens[ $i ][ 'code' ] === T_USE
149
+                || $tokens[ $i ][ 'code' ] === T_DECLARE
150
+                || $tokens[ $i ][ 'code' ] === T_CONST
151 151
             ) {
152
-                if (isset($tokens[$i]['scope_opener']) === true) {
153
-                    $i = $tokens[$i]['scope_closer'];
152
+                if ( isset( $tokens[ $i ][ 'scope_opener' ] ) === true ) {
153
+                    $i = $tokens[ $i ][ 'scope_closer' ];
154 154
                 } else {
155
-                    $semicolon = $phpcsFile->findNext(T_SEMICOLON, ($i + 1));
156
-                    if ($semicolon !== false) {
155
+                    $semicolon = $phpcsFile->findNext( T_SEMICOLON, ( $i + 1 ) );
156
+                    if ( $semicolon !== false ) {
157 157
                         $i = $semicolon;
158 158
                     }
159 159
                 }
@@ -162,40 +162,40 @@  discard block
 block discarded – undo
162 162
             }
163 163
 
164 164
             // Ignore function/class prefixes.
165
-            if (isset(Tokens::$methodPrefixes[$tokens[$i]['code']]) === true) {
165
+            if ( isset( Tokens::$methodPrefixes[ $tokens[ $i ][ 'code' ] ] ) === true ) {
166 166
                 continue;
167 167
             }
168 168
 
169 169
             // Ignore anon classes.
170
-            if ($tokens[$i]['code'] === T_ANON_CLASS) {
171
-                $i = $tokens[$i]['scope_closer'];
170
+            if ( $tokens[ $i ][ 'code' ] === T_ANON_CLASS ) {
171
+                $i = $tokens[ $i ][ 'scope_closer' ];
172 172
                 continue;
173 173
             }
174 174
 
175 175
             // Detect and skip over symbols.
176
-            if (isset($symbols[$tokens[$i]['code']]) === true
177
-                && isset($tokens[$i]['scope_closer']) === true
176
+            if ( isset( $symbols[ $tokens[ $i ][ 'code' ] ] ) === true
177
+                && isset( $tokens[ $i ][ 'scope_closer' ] ) === true
178 178
             ) {
179
-                if ($firstSymbol === null) {
179
+                if ( $firstSymbol === null ) {
180 180
                     $firstSymbol = $i;
181 181
                 }
182 182
 
183
-                $i = $tokens[$i]['scope_closer'];
183
+                $i = $tokens[ $i ][ 'scope_closer' ];
184 184
                 continue;
185
-            } else if ($tokens[$i]['code'] === T_STRING
186
-                && strtolower($tokens[$i]['content']) === 'define'
185
+            } else if ( $tokens[ $i ][ 'code' ] === T_STRING
186
+                && strtolower( $tokens[ $i ][ 'content' ] ) === 'define'
187 187
             ) {
188
-                $prev = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($i - 1), null, true);
189
-                if ($tokens[$prev]['code'] !== T_OBJECT_OPERATOR
190
-                    && $tokens[$prev]['code'] !== T_DOUBLE_COLON
191
-                    && $tokens[$prev]['code'] !== T_FUNCTION
188
+                $prev = $phpcsFile->findPrevious( Tokens::$emptyTokens, ( $i - 1 ), null, true );
189
+                if ( $tokens[ $prev ][ 'code' ] !== T_OBJECT_OPERATOR
190
+                    && $tokens[ $prev ][ 'code' ] !== T_DOUBLE_COLON
191
+                    && $tokens[ $prev ][ 'code' ] !== T_FUNCTION
192 192
                 ) {
193
-                    if ($firstSymbol === null) {
193
+                    if ( $firstSymbol === null ) {
194 194
                         $firstSymbol = $i;
195 195
                     }
196 196
 
197
-                    $semicolon = $phpcsFile->findNext(T_SEMICOLON, ($i + 1));
198
-                    if ($semicolon !== false) {
197
+                    $semicolon = $phpcsFile->findNext( T_SEMICOLON, ( $i + 1 ) );
198
+                    if ( $semicolon !== false ) {
199 199
                         $i = $semicolon;
200 200
                     }
201 201
 
@@ -206,19 +206,19 @@  discard block
 block discarded – undo
206 206
             // Special case for defined() as it can be used to see
207 207
             // if a constant (a symbol) should be defined or not and
208 208
             // doesn't need to use a full conditional block.
209
-            if ($tokens[$i]['code'] === T_STRING
210
-                && strtolower($tokens[$i]['content']) === 'defined'
209
+            if ( $tokens[ $i ][ 'code' ] === T_STRING
210
+                && strtolower( $tokens[ $i ][ 'content' ] ) === 'defined'
211 211
             ) {
212
-                $openBracket = $phpcsFile->findNext(Tokens::$emptyTokens, ($i + 1), null, true);
213
-                if ($tokens[$openBracket]['code'] === T_OPEN_PARENTHESIS
214
-                    && isset($tokens[$openBracket]['parenthesis_closer']) === true
212
+                $openBracket = $phpcsFile->findNext( Tokens::$emptyTokens, ( $i + 1 ), null, true );
213
+                if ( $tokens[ $openBracket ][ 'code' ] === T_OPEN_PARENTHESIS
214
+                    && isset( $tokens[ $openBracket ][ 'parenthesis_closer' ] ) === true
215 215
                 ) {
216
-                    $prev = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($i - 1), null, true);
217
-                    if ($tokens[$prev]['code'] !== T_OBJECT_OPERATOR
218
-                        && $tokens[$prev]['code'] !== T_DOUBLE_COLON
219
-                        && $tokens[$prev]['code'] !== T_FUNCTION
216
+                    $prev = $phpcsFile->findPrevious( Tokens::$emptyTokens, ( $i - 1 ), null, true );
217
+                    if ( $tokens[ $prev ][ 'code' ] !== T_OBJECT_OPERATOR
218
+                        && $tokens[ $prev ][ 'code' ] !== T_DOUBLE_COLON
219
+                        && $tokens[ $prev ][ 'code' ] !== T_FUNCTION
220 220
                     ) {
221
-                        $i = $tokens[$openBracket]['parenthesis_closer'];
221
+                        $i = $tokens[ $openBracket ][ 'parenthesis_closer' ];
222 222
                         continue;
223 223
                     }
224 224
                 }
@@ -227,44 +227,44 @@  discard block
 block discarded – undo
227 227
             // Conditional statements are allowed in symbol files as long as the
228 228
             // contents is only a symbol definition. So don't count these as effects
229 229
             // in this case.
230
-            if (isset($conditions[$tokens[$i]['code']]) === true) {
231
-                if (isset($tokens[$i]['scope_opener']) === false) {
230
+            if ( isset( $conditions[ $tokens[ $i ][ 'code' ] ] ) === true ) {
231
+                if ( isset( $tokens[ $i ][ 'scope_opener' ] ) === false ) {
232 232
                     // Probably an "else if", so just ignore.
233 233
                     continue;
234 234
                 }
235 235
 
236 236
                 $result = $this->searchForConflict(
237 237
                     $phpcsFile,
238
-                    ($tokens[$i]['scope_opener'] + 1),
239
-                    ($tokens[$i]['scope_closer'] - 1),
238
+                    ( $tokens[ $i ][ 'scope_opener' ] + 1 ),
239
+                    ( $tokens[ $i ][ 'scope_closer' ] - 1 ),
240 240
                     $tokens
241 241
                 );
242 242
 
243
-                if ($result['symbol'] !== null) {
244
-                    if ($firstSymbol === null) {
245
-                        $firstSymbol = $result['symbol'];
243
+                if ( $result[ 'symbol' ] !== null ) {
244
+                    if ( $firstSymbol === null ) {
245
+                        $firstSymbol = $result[ 'symbol' ];
246 246
                     }
247 247
 
248
-                    if ($result['effect'] !== null) {
248
+                    if ( $result[ 'effect' ] !== null ) {
249 249
                         // Found a conflict.
250
-                        $firstEffect = $result['effect'];
250
+                        $firstEffect = $result[ 'effect' ];
251 251
                         break;
252 252
                     }
253 253
                 }
254 254
 
255
-                if ($firstEffect === null) {
256
-                    $firstEffect = $result['effect'];
255
+                if ( $firstEffect === null ) {
256
+                    $firstEffect = $result[ 'effect' ];
257 257
                 }
258 258
 
259
-                $i = $tokens[$i]['scope_closer'];
259
+                $i = $tokens[ $i ][ 'scope_closer' ];
260 260
                 continue;
261 261
             }//end if
262 262
 
263
-            if ($firstEffect === null) {
263
+            if ( $firstEffect === null ) {
264 264
                 $firstEffect = $i;
265 265
             }
266 266
 
267
-            if ($firstSymbol !== null) {
267
+            if ( $firstSymbol !== null ) {
268 268
                 // We have a conflict we have to report, so no point continuing.
269 269
                 break;
270 270
             }
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 SideEffectsSniff implements Sniff
17
-{
16
+class SideEffectsSniff 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 [T_OPEN_TAG];
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
         $result = $this->searchForConflict($phpcsFile, 0, ($phpcsFile->numTokens - 1), $tokens);
45 42
 
@@ -76,8 +73,7 @@  discard block
 block discarded – undo
76 73
      *
77 74
      * @return array
78 75
      */
79
-    private function searchForConflict($phpcsFile, $start, $end, $tokens)
80
-    {
76
+    private function searchForConflict($phpcsFile, $start, $end, $tokens) {
81 77
         $symbols = [
82 78
             T_CLASS     => T_CLASS,
83 79
             T_INTERFACE => T_INTERFACE,
Please login to merge, or discard this patch.
src/Standards/Squiz/Sniffs/Commenting/InlineCommentSniff.php 4 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -49,7 +49,7 @@
 block discarded – undo
49 49
      * @param int                         $stackPtr  The position of the current token in the
50 50
      *                                               stack passed in $tokens.
51 51
      *
52
-     * @return void
52
+     * @return null|integer
53 53
      */
54 54
     public function process(File $phpcsFile, $stackPtr)
55 55
     {
Please login to merge, or discard this patch.
Indentation   +322 added lines, -322 removed lines patch added patch discarded remove patch
@@ -16,328 +16,328 @@
 block discarded – undo
16 16
 class InlineCommentSniff 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
-    /**
31
-     * Returns an array of tokens this test wants to listen for.
32
-     *
33
-     * @return array
34
-     */
35
-    public function register()
36
-    {
37
-        return [
38
-            T_COMMENT,
39
-            T_DOC_COMMENT_OPEN_TAG,
40
-        ];
41
-
42
-    }//end register()
43
-
44
-
45
-    /**
46
-     * Processes this test, when one of its tokens is encountered.
47
-     *
48
-     * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.
49
-     * @param int                         $stackPtr  The position of the current token in the
50
-     *                                               stack passed in $tokens.
51
-     *
52
-     * @return void
53
-     */
54
-    public function process(File $phpcsFile, $stackPtr)
55
-    {
56
-        $tokens = $phpcsFile->getTokens();
57
-
58
-        // If this is a function/class/interface doc block comment, skip it.
59
-        // We are only interested in inline doc block comments, which are
60
-        // not allowed.
61
-        if ($tokens[$stackPtr]['code'] === T_DOC_COMMENT_OPEN_TAG) {
62
-            $nextToken = $phpcsFile->findNext(
63
-                Tokens::$emptyTokens,
64
-                ($stackPtr + 1),
65
-                null,
66
-                true
67
-            );
68
-
69
-            $ignore = [
70
-                T_CLASS,
71
-                T_INTERFACE,
72
-                T_TRAIT,
73
-                T_FUNCTION,
74
-                T_CLOSURE,
75
-                T_PUBLIC,
76
-                T_PRIVATE,
77
-                T_PROTECTED,
78
-                T_FINAL,
79
-                T_STATIC,
80
-                T_ABSTRACT,
81
-                T_CONST,
82
-                T_PROPERTY,
83
-                T_INCLUDE,
84
-                T_INCLUDE_ONCE,
85
-                T_REQUIRE,
86
-                T_REQUIRE_ONCE,
87
-            ];
88
-
89
-            if (in_array($tokens[$nextToken]['code'], $ignore, true) === true) {
90
-                return;
91
-            }
92
-
93
-            if ($phpcsFile->tokenizerType === 'JS') {
94
-                // We allow block comments if a function or object
95
-                // is being assigned to a variable.
96
-                $ignore    = Tokens::$emptyTokens;
97
-                $ignore[]  = T_EQUAL;
98
-                $ignore[]  = T_STRING;
99
-                $ignore[]  = T_OBJECT_OPERATOR;
100
-                $nextToken = $phpcsFile->findNext($ignore, ($nextToken + 1), null, true);
101
-                if ($tokens[$nextToken]['code'] === T_FUNCTION
102
-                    || $tokens[$nextToken]['code'] === T_CLOSURE
103
-                    || $tokens[$nextToken]['code'] === T_OBJECT
104
-                    || $tokens[$nextToken]['code'] === T_PROTOTYPE
105
-                ) {
106
-                    return;
107
-                }
108
-            }
109
-
110
-            $prevToken = $phpcsFile->findPrevious(
111
-                Tokens::$emptyTokens,
112
-                ($stackPtr - 1),
113
-                null,
114
-                true
115
-            );
116
-
117
-            if ($tokens[$prevToken]['code'] === T_OPEN_TAG) {
118
-                return;
119
-            }
120
-
121
-            if ($tokens[$stackPtr]['content'] === '/**') {
122
-                $error = 'Inline doc block comments are not allowed; use "/* Comment */" or "// Comment" instead';
123
-                $phpcsFile->addError($error, $stackPtr, 'DocBlock');
124
-            }
125
-        }//end if
126
-
127
-        if ($tokens[$stackPtr]['content']{0} === '#') {
128
-            $error = 'Perl-style comments are not allowed; use "// Comment" instead';
129
-            $fix   = $phpcsFile->addFixableError($error, $stackPtr, 'WrongStyle');
130
-            if ($fix === true) {
131
-                $comment = ltrim($tokens[$stackPtr]['content'], "# \t");
132
-                $phpcsFile->fixer->replaceToken($stackPtr, "// $comment");
133
-            }
134
-        }
135
-
136
-        // We don't want end of block comments. Check if the last token before the
137
-        // comment is a closing curly brace.
138
-        $previousContent = $phpcsFile->findPrevious(T_WHITESPACE, ($stackPtr - 1), null, true);
139
-        if ($tokens[$previousContent]['line'] === $tokens[$stackPtr]['line']) {
140
-            if ($tokens[$previousContent]['code'] === T_CLOSE_CURLY_BRACKET) {
141
-                return;
142
-            }
143
-
144
-            // Special case for JS files.
145
-            if ($tokens[$previousContent]['code'] === T_COMMA
146
-                || $tokens[$previousContent]['code'] === T_SEMICOLON
147
-            ) {
148
-                $lastContent = $phpcsFile->findPrevious(T_WHITESPACE, ($previousContent - 1), null, true);
149
-                if ($tokens[$lastContent]['code'] === T_CLOSE_CURLY_BRACKET) {
150
-                    return;
151
-                }
152
-            }
153
-        }
154
-
155
-        // Only want inline comments.
156
-        if (substr($tokens[$stackPtr]['content'], 0, 2) !== '//') {
157
-            return;
158
-        }
159
-
160
-        $commentTokens = [$stackPtr];
161
-
162
-        $nextComment = $stackPtr;
163
-        $lastComment = $stackPtr;
164
-        while (($nextComment = $phpcsFile->findNext(T_COMMENT, ($nextComment + 1), null, false)) !== false) {
165
-            if ($tokens[$nextComment]['line'] !== ($tokens[$lastComment]['line'] + 1)) {
166
-                break;
167
-            }
168
-
169
-            // Only want inline comments.
170
-            if (substr($tokens[$nextComment]['content'], 0, 2) !== '//') {
171
-                break;
172
-            }
173
-
174
-            // There is a comment on the very next line. If there is
175
-            // no code between the comments, they are part of the same
176
-            // comment block.
177
-            $prevNonWhitespace = $phpcsFile->findPrevious(T_WHITESPACE, ($nextComment - 1), $lastComment, true);
178
-            if ($prevNonWhitespace !== $lastComment) {
179
-                break;
180
-            }
181
-
182
-            $commentTokens[] = $nextComment;
183
-            $lastComment     = $nextComment;
184
-        }//end while
185
-
186
-        $commentText = '';
187
-        foreach ($commentTokens as $lastCommentToken) {
188
-            $comment = rtrim($tokens[$lastCommentToken]['content']);
189
-
190
-            if (trim(substr($comment, 2)) === '') {
191
-                continue;
192
-            }
193
-
194
-            $spaceCount = 0;
195
-            $tabFound   = false;
196
-
197
-            $commentLength = strlen($comment);
198
-            for ($i = 2; $i < $commentLength; $i++) {
199
-                if ($comment[$i] === "\t") {
200
-                    $tabFound = true;
201
-                    break;
202
-                }
203
-
204
-                if ($comment[$i] !== ' ') {
205
-                    break;
206
-                }
207
-
208
-                $spaceCount++;
209
-            }
210
-
211
-            $fix = false;
212
-            if ($tabFound === true) {
213
-                $error = 'Tab found before comment text; expected "// %s" but found "%s"';
214
-                $data  = [
215
-                    ltrim(substr($comment, 2)),
216
-                    $comment,
217
-                ];
218
-                $fix   = $phpcsFile->addFixableError($error, $lastCommentToken, 'TabBefore', $data);
219
-            } else if ($spaceCount === 0) {
220
-                $error = 'No space found before comment text; expected "// %s" but found "%s"';
221
-                $data  = [
222
-                    substr($comment, 2),
223
-                    $comment,
224
-                ];
225
-                $fix   = $phpcsFile->addFixableError($error, $lastCommentToken, 'NoSpaceBefore', $data);
226
-            } else if ($spaceCount > 1) {
227
-                $error = 'Expected 1 space before comment text but found %s; use block comment if you need indentation';
228
-                $data  = [
229
-                    $spaceCount,
230
-                    substr($comment, (2 + $spaceCount)),
231
-                    $comment,
232
-                ];
233
-                $fix   = $phpcsFile->addFixableError($error, $lastCommentToken, 'SpacingBefore', $data);
234
-            }//end if
235
-
236
-            if ($fix === true) {
237
-                $newComment = '// '.ltrim($tokens[$lastCommentToken]['content'], "/\t ");
238
-                $phpcsFile->fixer->replaceToken($lastCommentToken, $newComment);
239
-            }
240
-
241
-            $commentText .= trim(substr($tokens[$lastCommentToken]['content'], 2));
242
-        }//end foreach
243
-
244
-        if ($commentText === '') {
245
-            $error = 'Blank comments are not allowed';
246
-            $fix   = $phpcsFile->addFixableError($error, $stackPtr, 'Empty');
247
-            if ($fix === true) {
248
-                $phpcsFile->fixer->replaceToken($stackPtr, '');
249
-            }
250
-
251
-            return ($lastCommentToken + 1);
252
-        }
253
-
254
-        if (preg_match('/^\p{Ll}/u', $commentText) === 1) {
255
-            $error = 'Inline comments must start with a capital letter';
256
-            $phpcsFile->addError($error, $stackPtr, 'NotCapital');
257
-        }
258
-
259
-        // Only check the end of comment character if the start of the comment
260
-        // is a letter, indicating that the comment is just standard text.
261
-        if (preg_match('/^\p{L}/u', $commentText) === 1) {
262
-            $commentCloser   = $commentText[(strlen($commentText) - 1)];
263
-            $acceptedClosers = [
264
-                'full-stops'        => '.',
265
-                'exclamation marks' => '!',
266
-                'or question marks' => '?',
267
-            ];
268
-
269
-            if (in_array($commentCloser, $acceptedClosers, true) === false) {
270
-                $error = 'Inline comments must end in %s';
271
-                $ender = '';
272
-                foreach ($acceptedClosers as $closerName => $symbol) {
273
-                    $ender .= ' '.$closerName.',';
274
-                }
275
-
276
-                $ender = trim($ender, ' ,');
277
-                $data  = [$ender];
278
-                $phpcsFile->addError($error, $lastCommentToken, 'InvalidEndChar', $data);
279
-            }
280
-        }
281
-
282
-        // Finally, the line below the last comment cannot be empty if this inline
283
-        // comment is on a line by itself.
284
-        if ($tokens[$previousContent]['line'] < $tokens[$stackPtr]['line']) {
285
-            $next = $phpcsFile->findNext(T_WHITESPACE, ($lastCommentToken + 1), null, true);
286
-            if ($next === false) {
287
-                // Ignore if the comment is the last non-whitespace token in a file.
288
-                return ($lastCommentToken + 1);
289
-            }
290
-
291
-            if ($tokens[$next]['code'] === T_DOC_COMMENT_OPEN_TAG) {
292
-                // If this inline comment is followed by a docblock,
293
-                // ignore spacing as docblock/function etc spacing rules
294
-                // are likely to conflict with our rules.
295
-                return ($lastCommentToken + 1);
296
-            }
297
-
298
-            $errorCode = 'SpacingAfter';
299
-
300
-            if (isset($tokens[$stackPtr]['conditions']) === true) {
301
-                $conditions   = $tokens[$stackPtr]['conditions'];
302
-                $type         = end($conditions);
303
-                $conditionPtr = key($conditions);
304
-
305
-                if (($type === T_FUNCTION || $type === T_CLOSURE)
306
-                    && $tokens[$conditionPtr]['scope_closer'] === $next
307
-                ) {
308
-                    $errorCode = 'SpacingAfterAtFunctionEnd';
309
-                }
310
-            }
311
-
312
-            for ($i = ($lastCommentToken + 1); $i < $phpcsFile->numTokens; $i++) {
313
-                if ($tokens[$i]['line'] === ($tokens[$lastCommentToken]['line'] + 1)) {
314
-                    if ($tokens[$i]['code'] !== T_WHITESPACE) {
315
-                        return ($lastCommentToken + 1);
316
-                    }
317
-                } else if ($tokens[$i]['line'] > ($tokens[$lastCommentToken]['line'] + 1)) {
318
-                    break;
319
-                }
320
-            }
321
-
322
-            $error = 'There must be no blank line following an inline comment';
323
-            $fix   = $phpcsFile->addFixableError($error, $lastCommentToken, $errorCode);
324
-            if ($fix === true) {
325
-                $phpcsFile->fixer->beginChangeset();
326
-                for ($i = ($lastCommentToken + 1); $i < $next; $i++) {
327
-                    if ($tokens[$i]['line'] === $tokens[$next]['line']) {
328
-                        break;
329
-                    }
330
-
331
-                    $phpcsFile->fixer->replaceToken($i, '');
332
-                }
333
-
334
-                $phpcsFile->fixer->endChangeset();
335
-            }
336
-        }//end if
337
-
338
-        return ($lastCommentToken + 1);
339
-
340
-    }//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
+	/**
31
+	 * Returns an array of tokens this test wants to listen for.
32
+	 *
33
+	 * @return array
34
+	 */
35
+	public function register()
36
+	{
37
+		return [
38
+			T_COMMENT,
39
+			T_DOC_COMMENT_OPEN_TAG,
40
+		];
41
+
42
+	}//end register()
43
+
44
+
45
+	/**
46
+	 * Processes this test, when one of its tokens is encountered.
47
+	 *
48
+	 * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.
49
+	 * @param int                         $stackPtr  The position of the current token in the
50
+	 *                                               stack passed in $tokens.
51
+	 *
52
+	 * @return void
53
+	 */
54
+	public function process(File $phpcsFile, $stackPtr)
55
+	{
56
+		$tokens = $phpcsFile->getTokens();
57
+
58
+		// If this is a function/class/interface doc block comment, skip it.
59
+		// We are only interested in inline doc block comments, which are
60
+		// not allowed.
61
+		if ($tokens[$stackPtr]['code'] === T_DOC_COMMENT_OPEN_TAG) {
62
+			$nextToken = $phpcsFile->findNext(
63
+				Tokens::$emptyTokens,
64
+				($stackPtr + 1),
65
+				null,
66
+				true
67
+			);
68
+
69
+			$ignore = [
70
+				T_CLASS,
71
+				T_INTERFACE,
72
+				T_TRAIT,
73
+				T_FUNCTION,
74
+				T_CLOSURE,
75
+				T_PUBLIC,
76
+				T_PRIVATE,
77
+				T_PROTECTED,
78
+				T_FINAL,
79
+				T_STATIC,
80
+				T_ABSTRACT,
81
+				T_CONST,
82
+				T_PROPERTY,
83
+				T_INCLUDE,
84
+				T_INCLUDE_ONCE,
85
+				T_REQUIRE,
86
+				T_REQUIRE_ONCE,
87
+			];
88
+
89
+			if (in_array($tokens[$nextToken]['code'], $ignore, true) === true) {
90
+				return;
91
+			}
92
+
93
+			if ($phpcsFile->tokenizerType === 'JS') {
94
+				// We allow block comments if a function or object
95
+				// is being assigned to a variable.
96
+				$ignore    = Tokens::$emptyTokens;
97
+				$ignore[]  = T_EQUAL;
98
+				$ignore[]  = T_STRING;
99
+				$ignore[]  = T_OBJECT_OPERATOR;
100
+				$nextToken = $phpcsFile->findNext($ignore, ($nextToken + 1), null, true);
101
+				if ($tokens[$nextToken]['code'] === T_FUNCTION
102
+					|| $tokens[$nextToken]['code'] === T_CLOSURE
103
+					|| $tokens[$nextToken]['code'] === T_OBJECT
104
+					|| $tokens[$nextToken]['code'] === T_PROTOTYPE
105
+				) {
106
+					return;
107
+				}
108
+			}
109
+
110
+			$prevToken = $phpcsFile->findPrevious(
111
+				Tokens::$emptyTokens,
112
+				($stackPtr - 1),
113
+				null,
114
+				true
115
+			);
116
+
117
+			if ($tokens[$prevToken]['code'] === T_OPEN_TAG) {
118
+				return;
119
+			}
120
+
121
+			if ($tokens[$stackPtr]['content'] === '/**') {
122
+				$error = 'Inline doc block comments are not allowed; use "/* Comment */" or "// Comment" instead';
123
+				$phpcsFile->addError($error, $stackPtr, 'DocBlock');
124
+			}
125
+		}//end if
126
+
127
+		if ($tokens[$stackPtr]['content']{0} === '#') {
128
+			$error = 'Perl-style comments are not allowed; use "// Comment" instead';
129
+			$fix   = $phpcsFile->addFixableError($error, $stackPtr, 'WrongStyle');
130
+			if ($fix === true) {
131
+				$comment = ltrim($tokens[$stackPtr]['content'], "# \t");
132
+				$phpcsFile->fixer->replaceToken($stackPtr, "// $comment");
133
+			}
134
+		}
135
+
136
+		// We don't want end of block comments. Check if the last token before the
137
+		// comment is a closing curly brace.
138
+		$previousContent = $phpcsFile->findPrevious(T_WHITESPACE, ($stackPtr - 1), null, true);
139
+		if ($tokens[$previousContent]['line'] === $tokens[$stackPtr]['line']) {
140
+			if ($tokens[$previousContent]['code'] === T_CLOSE_CURLY_BRACKET) {
141
+				return;
142
+			}
143
+
144
+			// Special case for JS files.
145
+			if ($tokens[$previousContent]['code'] === T_COMMA
146
+				|| $tokens[$previousContent]['code'] === T_SEMICOLON
147
+			) {
148
+				$lastContent = $phpcsFile->findPrevious(T_WHITESPACE, ($previousContent - 1), null, true);
149
+				if ($tokens[$lastContent]['code'] === T_CLOSE_CURLY_BRACKET) {
150
+					return;
151
+				}
152
+			}
153
+		}
154
+
155
+		// Only want inline comments.
156
+		if (substr($tokens[$stackPtr]['content'], 0, 2) !== '//') {
157
+			return;
158
+		}
159
+
160
+		$commentTokens = [$stackPtr];
161
+
162
+		$nextComment = $stackPtr;
163
+		$lastComment = $stackPtr;
164
+		while (($nextComment = $phpcsFile->findNext(T_COMMENT, ($nextComment + 1), null, false)) !== false) {
165
+			if ($tokens[$nextComment]['line'] !== ($tokens[$lastComment]['line'] + 1)) {
166
+				break;
167
+			}
168
+
169
+			// Only want inline comments.
170
+			if (substr($tokens[$nextComment]['content'], 0, 2) !== '//') {
171
+				break;
172
+			}
173
+
174
+			// There is a comment on the very next line. If there is
175
+			// no code between the comments, they are part of the same
176
+			// comment block.
177
+			$prevNonWhitespace = $phpcsFile->findPrevious(T_WHITESPACE, ($nextComment - 1), $lastComment, true);
178
+			if ($prevNonWhitespace !== $lastComment) {
179
+				break;
180
+			}
181
+
182
+			$commentTokens[] = $nextComment;
183
+			$lastComment     = $nextComment;
184
+		}//end while
185
+
186
+		$commentText = '';
187
+		foreach ($commentTokens as $lastCommentToken) {
188
+			$comment = rtrim($tokens[$lastCommentToken]['content']);
189
+
190
+			if (trim(substr($comment, 2)) === '') {
191
+				continue;
192
+			}
193
+
194
+			$spaceCount = 0;
195
+			$tabFound   = false;
196
+
197
+			$commentLength = strlen($comment);
198
+			for ($i = 2; $i < $commentLength; $i++) {
199
+				if ($comment[$i] === "\t") {
200
+					$tabFound = true;
201
+					break;
202
+				}
203
+
204
+				if ($comment[$i] !== ' ') {
205
+					break;
206
+				}
207
+
208
+				$spaceCount++;
209
+			}
210
+
211
+			$fix = false;
212
+			if ($tabFound === true) {
213
+				$error = 'Tab found before comment text; expected "// %s" but found "%s"';
214
+				$data  = [
215
+					ltrim(substr($comment, 2)),
216
+					$comment,
217
+				];
218
+				$fix   = $phpcsFile->addFixableError($error, $lastCommentToken, 'TabBefore', $data);
219
+			} else if ($spaceCount === 0) {
220
+				$error = 'No space found before comment text; expected "// %s" but found "%s"';
221
+				$data  = [
222
+					substr($comment, 2),
223
+					$comment,
224
+				];
225
+				$fix   = $phpcsFile->addFixableError($error, $lastCommentToken, 'NoSpaceBefore', $data);
226
+			} else if ($spaceCount > 1) {
227
+				$error = 'Expected 1 space before comment text but found %s; use block comment if you need indentation';
228
+				$data  = [
229
+					$spaceCount,
230
+					substr($comment, (2 + $spaceCount)),
231
+					$comment,
232
+				];
233
+				$fix   = $phpcsFile->addFixableError($error, $lastCommentToken, 'SpacingBefore', $data);
234
+			}//end if
235
+
236
+			if ($fix === true) {
237
+				$newComment = '// '.ltrim($tokens[$lastCommentToken]['content'], "/\t ");
238
+				$phpcsFile->fixer->replaceToken($lastCommentToken, $newComment);
239
+			}
240
+
241
+			$commentText .= trim(substr($tokens[$lastCommentToken]['content'], 2));
242
+		}//end foreach
243
+
244
+		if ($commentText === '') {
245
+			$error = 'Blank comments are not allowed';
246
+			$fix   = $phpcsFile->addFixableError($error, $stackPtr, 'Empty');
247
+			if ($fix === true) {
248
+				$phpcsFile->fixer->replaceToken($stackPtr, '');
249
+			}
250
+
251
+			return ($lastCommentToken + 1);
252
+		}
253
+
254
+		if (preg_match('/^\p{Ll}/u', $commentText) === 1) {
255
+			$error = 'Inline comments must start with a capital letter';
256
+			$phpcsFile->addError($error, $stackPtr, 'NotCapital');
257
+		}
258
+
259
+		// Only check the end of comment character if the start of the comment
260
+		// is a letter, indicating that the comment is just standard text.
261
+		if (preg_match('/^\p{L}/u', $commentText) === 1) {
262
+			$commentCloser   = $commentText[(strlen($commentText) - 1)];
263
+			$acceptedClosers = [
264
+				'full-stops'        => '.',
265
+				'exclamation marks' => '!',
266
+				'or question marks' => '?',
267
+			];
268
+
269
+			if (in_array($commentCloser, $acceptedClosers, true) === false) {
270
+				$error = 'Inline comments must end in %s';
271
+				$ender = '';
272
+				foreach ($acceptedClosers as $closerName => $symbol) {
273
+					$ender .= ' '.$closerName.',';
274
+				}
275
+
276
+				$ender = trim($ender, ' ,');
277
+				$data  = [$ender];
278
+				$phpcsFile->addError($error, $lastCommentToken, 'InvalidEndChar', $data);
279
+			}
280
+		}
281
+
282
+		// Finally, the line below the last comment cannot be empty if this inline
283
+		// comment is on a line by itself.
284
+		if ($tokens[$previousContent]['line'] < $tokens[$stackPtr]['line']) {
285
+			$next = $phpcsFile->findNext(T_WHITESPACE, ($lastCommentToken + 1), null, true);
286
+			if ($next === false) {
287
+				// Ignore if the comment is the last non-whitespace token in a file.
288
+				return ($lastCommentToken + 1);
289
+			}
290
+
291
+			if ($tokens[$next]['code'] === T_DOC_COMMENT_OPEN_TAG) {
292
+				// If this inline comment is followed by a docblock,
293
+				// ignore spacing as docblock/function etc spacing rules
294
+				// are likely to conflict with our rules.
295
+				return ($lastCommentToken + 1);
296
+			}
297
+
298
+			$errorCode = 'SpacingAfter';
299
+
300
+			if (isset($tokens[$stackPtr]['conditions']) === true) {
301
+				$conditions   = $tokens[$stackPtr]['conditions'];
302
+				$type         = end($conditions);
303
+				$conditionPtr = key($conditions);
304
+
305
+				if (($type === T_FUNCTION || $type === T_CLOSURE)
306
+					&& $tokens[$conditionPtr]['scope_closer'] === $next
307
+				) {
308
+					$errorCode = 'SpacingAfterAtFunctionEnd';
309
+				}
310
+			}
311
+
312
+			for ($i = ($lastCommentToken + 1); $i < $phpcsFile->numTokens; $i++) {
313
+				if ($tokens[$i]['line'] === ($tokens[$lastCommentToken]['line'] + 1)) {
314
+					if ($tokens[$i]['code'] !== T_WHITESPACE) {
315
+						return ($lastCommentToken + 1);
316
+					}
317
+				} else if ($tokens[$i]['line'] > ($tokens[$lastCommentToken]['line'] + 1)) {
318
+					break;
319
+				}
320
+			}
321
+
322
+			$error = 'There must be no blank line following an inline comment';
323
+			$fix   = $phpcsFile->addFixableError($error, $lastCommentToken, $errorCode);
324
+			if ($fix === true) {
325
+				$phpcsFile->fixer->beginChangeset();
326
+				for ($i = ($lastCommentToken + 1); $i < $next; $i++) {
327
+					if ($tokens[$i]['line'] === $tokens[$next]['line']) {
328
+						break;
329
+					}
330
+
331
+					$phpcsFile->fixer->replaceToken($i, '');
332
+				}
333
+
334
+				$phpcsFile->fixer->endChangeset();
335
+			}
336
+		}//end if
337
+
338
+		return ($lastCommentToken + 1);
339
+
340
+	}//end process()
341 341
 
342 342
 
343 343
 }//end class
Please login to merge, or discard this patch.
Spacing   +95 added lines, -95 removed lines patch added patch discarded remove patch
@@ -51,17 +51,17 @@  discard block
 block discarded – undo
51 51
      *
52 52
      * @return void
53 53
      */
54
-    public function process(File $phpcsFile, $stackPtr)
54
+    public function process( File $phpcsFile, $stackPtr )
55 55
     {
56 56
         $tokens = $phpcsFile->getTokens();
57 57
 
58 58
         // If this is a function/class/interface doc block comment, skip it.
59 59
         // We are only interested in inline doc block comments, which are
60 60
         // not allowed.
61
-        if ($tokens[$stackPtr]['code'] === T_DOC_COMMENT_OPEN_TAG) {
61
+        if ( $tokens[ $stackPtr ][ 'code' ] === T_DOC_COMMENT_OPEN_TAG ) {
62 62
             $nextToken = $phpcsFile->findNext(
63 63
                 Tokens::$emptyTokens,
64
-                ($stackPtr + 1),
64
+                ( $stackPtr + 1 ),
65 65
                 null,
66 66
                 true
67 67
             );
@@ -86,22 +86,22 @@  discard block
 block discarded – undo
86 86
                 T_REQUIRE_ONCE,
87 87
             ];
88 88
 
89
-            if (in_array($tokens[$nextToken]['code'], $ignore, true) === true) {
89
+            if ( in_array( $tokens[ $nextToken ][ 'code' ], $ignore, true ) === true ) {
90 90
                 return;
91 91
             }
92 92
 
93
-            if ($phpcsFile->tokenizerType === 'JS') {
93
+            if ( $phpcsFile->tokenizerType === 'JS' ) {
94 94
                 // We allow block comments if a function or object
95 95
                 // is being assigned to a variable.
96 96
                 $ignore    = Tokens::$emptyTokens;
97
-                $ignore[]  = T_EQUAL;
98
-                $ignore[]  = T_STRING;
99
-                $ignore[]  = T_OBJECT_OPERATOR;
100
-                $nextToken = $phpcsFile->findNext($ignore, ($nextToken + 1), null, true);
101
-                if ($tokens[$nextToken]['code'] === T_FUNCTION
102
-                    || $tokens[$nextToken]['code'] === T_CLOSURE
103
-                    || $tokens[$nextToken]['code'] === T_OBJECT
104
-                    || $tokens[$nextToken]['code'] === T_PROTOTYPE
97
+                $ignore[ ]  = T_EQUAL;
98
+                $ignore[ ]  = T_STRING;
99
+                $ignore[ ]  = T_OBJECT_OPERATOR;
100
+                $nextToken = $phpcsFile->findNext( $ignore, ( $nextToken + 1 ), null, true );
101
+                if ( $tokens[ $nextToken ][ 'code' ] === T_FUNCTION
102
+                    || $tokens[ $nextToken ][ 'code' ] === T_CLOSURE
103
+                    || $tokens[ $nextToken ][ 'code' ] === T_OBJECT
104
+                    || $tokens[ $nextToken ][ 'code' ] === T_PROTOTYPE
105 105
                 ) {
106 106
                     return;
107 107
                 }
@@ -109,99 +109,99 @@  discard block
 block discarded – undo
109 109
 
110 110
             $prevToken = $phpcsFile->findPrevious(
111 111
                 Tokens::$emptyTokens,
112
-                ($stackPtr - 1),
112
+                ( $stackPtr - 1 ),
113 113
                 null,
114 114
                 true
115 115
             );
116 116
 
117
-            if ($tokens[$prevToken]['code'] === T_OPEN_TAG) {
117
+            if ( $tokens[ $prevToken ][ 'code' ] === T_OPEN_TAG ) {
118 118
                 return;
119 119
             }
120 120
 
121
-            if ($tokens[$stackPtr]['content'] === '/**') {
121
+            if ( $tokens[ $stackPtr ][ 'content' ] === '/**' ) {
122 122
                 $error = 'Inline doc block comments are not allowed; use "/* Comment */" or "// Comment" instead';
123
-                $phpcsFile->addError($error, $stackPtr, 'DocBlock');
123
+                $phpcsFile->addError( $error, $stackPtr, 'DocBlock' );
124 124
             }
125 125
         }//end if
126 126
 
127
-        if ($tokens[$stackPtr]['content']{0} === '#') {
127
+        if ( $tokens[ $stackPtr ][ 'content' ]{0} === '#' ) {
128 128
             $error = 'Perl-style comments are not allowed; use "// Comment" instead';
129
-            $fix   = $phpcsFile->addFixableError($error, $stackPtr, 'WrongStyle');
130
-            if ($fix === true) {
131
-                $comment = ltrim($tokens[$stackPtr]['content'], "# \t");
132
-                $phpcsFile->fixer->replaceToken($stackPtr, "// $comment");
129
+            $fix   = $phpcsFile->addFixableError( $error, $stackPtr, 'WrongStyle' );
130
+            if ( $fix === true ) {
131
+                $comment = ltrim( $tokens[ $stackPtr ][ 'content' ], "# \t" );
132
+                $phpcsFile->fixer->replaceToken( $stackPtr, "// $comment" );
133 133
             }
134 134
         }
135 135
 
136 136
         // We don't want end of block comments. Check if the last token before the
137 137
         // comment is a closing curly brace.
138
-        $previousContent = $phpcsFile->findPrevious(T_WHITESPACE, ($stackPtr - 1), null, true);
139
-        if ($tokens[$previousContent]['line'] === $tokens[$stackPtr]['line']) {
140
-            if ($tokens[$previousContent]['code'] === T_CLOSE_CURLY_BRACKET) {
138
+        $previousContent = $phpcsFile->findPrevious( T_WHITESPACE, ( $stackPtr - 1 ), null, true );
139
+        if ( $tokens[ $previousContent ][ 'line' ] === $tokens[ $stackPtr ][ 'line' ] ) {
140
+            if ( $tokens[ $previousContent ][ 'code' ] === T_CLOSE_CURLY_BRACKET ) {
141 141
                 return;
142 142
             }
143 143
 
144 144
             // Special case for JS files.
145
-            if ($tokens[$previousContent]['code'] === T_COMMA
146
-                || $tokens[$previousContent]['code'] === T_SEMICOLON
145
+            if ( $tokens[ $previousContent ][ 'code' ] === T_COMMA
146
+                || $tokens[ $previousContent ][ 'code' ] === T_SEMICOLON
147 147
             ) {
148
-                $lastContent = $phpcsFile->findPrevious(T_WHITESPACE, ($previousContent - 1), null, true);
149
-                if ($tokens[$lastContent]['code'] === T_CLOSE_CURLY_BRACKET) {
148
+                $lastContent = $phpcsFile->findPrevious( T_WHITESPACE, ( $previousContent - 1 ), null, true );
149
+                if ( $tokens[ $lastContent ][ 'code' ] === T_CLOSE_CURLY_BRACKET ) {
150 150
                     return;
151 151
                 }
152 152
             }
153 153
         }
154 154
 
155 155
         // Only want inline comments.
156
-        if (substr($tokens[$stackPtr]['content'], 0, 2) !== '//') {
156
+        if ( substr( $tokens[ $stackPtr ][ 'content' ], 0, 2 ) !== '//' ) {
157 157
             return;
158 158
         }
159 159
 
160
-        $commentTokens = [$stackPtr];
160
+        $commentTokens = [ $stackPtr ];
161 161
 
162 162
         $nextComment = $stackPtr;
163 163
         $lastComment = $stackPtr;
164
-        while (($nextComment = $phpcsFile->findNext(T_COMMENT, ($nextComment + 1), null, false)) !== false) {
165
-            if ($tokens[$nextComment]['line'] !== ($tokens[$lastComment]['line'] + 1)) {
164
+        while ( ( $nextComment = $phpcsFile->findNext( T_COMMENT, ( $nextComment + 1 ), null, false ) ) !== false ) {
165
+            if ( $tokens[ $nextComment ][ 'line' ] !== ( $tokens[ $lastComment ][ 'line' ] + 1 ) ) {
166 166
                 break;
167 167
             }
168 168
 
169 169
             // Only want inline comments.
170
-            if (substr($tokens[$nextComment]['content'], 0, 2) !== '//') {
170
+            if ( substr( $tokens[ $nextComment ][ 'content' ], 0, 2 ) !== '//' ) {
171 171
                 break;
172 172
             }
173 173
 
174 174
             // There is a comment on the very next line. If there is
175 175
             // no code between the comments, they are part of the same
176 176
             // comment block.
177
-            $prevNonWhitespace = $phpcsFile->findPrevious(T_WHITESPACE, ($nextComment - 1), $lastComment, true);
178
-            if ($prevNonWhitespace !== $lastComment) {
177
+            $prevNonWhitespace = $phpcsFile->findPrevious( T_WHITESPACE, ( $nextComment - 1 ), $lastComment, true );
178
+            if ( $prevNonWhitespace !== $lastComment ) {
179 179
                 break;
180 180
             }
181 181
 
182
-            $commentTokens[] = $nextComment;
182
+            $commentTokens[ ] = $nextComment;
183 183
             $lastComment     = $nextComment;
184 184
         }//end while
185 185
 
186 186
         $commentText = '';
187
-        foreach ($commentTokens as $lastCommentToken) {
188
-            $comment = rtrim($tokens[$lastCommentToken]['content']);
187
+        foreach ( $commentTokens as $lastCommentToken ) {
188
+            $comment = rtrim( $tokens[ $lastCommentToken ][ 'content' ] );
189 189
 
190
-            if (trim(substr($comment, 2)) === '') {
190
+            if ( trim( substr( $comment, 2 ) ) === '' ) {
191 191
                 continue;
192 192
             }
193 193
 
194 194
             $spaceCount = 0;
195 195
             $tabFound   = false;
196 196
 
197
-            $commentLength = strlen($comment);
198
-            for ($i = 2; $i < $commentLength; $i++) {
199
-                if ($comment[$i] === "\t") {
197
+            $commentLength = strlen( $comment );
198
+            for ( $i = 2; $i < $commentLength; $i++ ) {
199
+                if ( $comment[ $i ] === "\t" ) {
200 200
                     $tabFound = true;
201 201
                     break;
202 202
                 }
203 203
 
204
-                if ($comment[$i] !== ' ') {
204
+                if ( $comment[ $i ] !== ' ' ) {
205 205
                     break;
206 206
                 }
207 207
 
@@ -209,133 +209,133 @@  discard block
 block discarded – undo
209 209
             }
210 210
 
211 211
             $fix = false;
212
-            if ($tabFound === true) {
212
+            if ( $tabFound === true ) {
213 213
                 $error = 'Tab found before comment text; expected "// %s" but found "%s"';
214 214
                 $data  = [
215
-                    ltrim(substr($comment, 2)),
215
+                    ltrim( substr( $comment, 2 ) ),
216 216
                     $comment,
217 217
                 ];
218
-                $fix   = $phpcsFile->addFixableError($error, $lastCommentToken, 'TabBefore', $data);
219
-            } else if ($spaceCount === 0) {
218
+                $fix   = $phpcsFile->addFixableError( $error, $lastCommentToken, 'TabBefore', $data );
219
+            } else if ( $spaceCount === 0 ) {
220 220
                 $error = 'No space found before comment text; expected "// %s" but found "%s"';
221 221
                 $data  = [
222
-                    substr($comment, 2),
222
+                    substr( $comment, 2 ),
223 223
                     $comment,
224 224
                 ];
225
-                $fix   = $phpcsFile->addFixableError($error, $lastCommentToken, 'NoSpaceBefore', $data);
226
-            } else if ($spaceCount > 1) {
225
+                $fix   = $phpcsFile->addFixableError( $error, $lastCommentToken, 'NoSpaceBefore', $data );
226
+            } else if ( $spaceCount > 1 ) {
227 227
                 $error = 'Expected 1 space before comment text but found %s; use block comment if you need indentation';
228 228
                 $data  = [
229 229
                     $spaceCount,
230
-                    substr($comment, (2 + $spaceCount)),
230
+                    substr( $comment, ( 2 + $spaceCount ) ),
231 231
                     $comment,
232 232
                 ];
233
-                $fix   = $phpcsFile->addFixableError($error, $lastCommentToken, 'SpacingBefore', $data);
233
+                $fix = $phpcsFile->addFixableError( $error, $lastCommentToken, 'SpacingBefore', $data );
234 234
             }//end if
235 235
 
236
-            if ($fix === true) {
237
-                $newComment = '// '.ltrim($tokens[$lastCommentToken]['content'], "/\t ");
238
-                $phpcsFile->fixer->replaceToken($lastCommentToken, $newComment);
236
+            if ( $fix === true ) {
237
+                $newComment = '// ' . ltrim( $tokens[ $lastCommentToken ][ 'content' ], "/\t " );
238
+                $phpcsFile->fixer->replaceToken( $lastCommentToken, $newComment );
239 239
             }
240 240
 
241
-            $commentText .= trim(substr($tokens[$lastCommentToken]['content'], 2));
241
+            $commentText .= trim( substr( $tokens[ $lastCommentToken ][ 'content' ], 2 ) );
242 242
         }//end foreach
243 243
 
244
-        if ($commentText === '') {
244
+        if ( $commentText === '' ) {
245 245
             $error = 'Blank comments are not allowed';
246
-            $fix   = $phpcsFile->addFixableError($error, $stackPtr, 'Empty');
247
-            if ($fix === true) {
248
-                $phpcsFile->fixer->replaceToken($stackPtr, '');
246
+            $fix   = $phpcsFile->addFixableError( $error, $stackPtr, 'Empty' );
247
+            if ( $fix === true ) {
248
+                $phpcsFile->fixer->replaceToken( $stackPtr, '' );
249 249
             }
250 250
 
251
-            return ($lastCommentToken + 1);
251
+            return ( $lastCommentToken + 1 );
252 252
         }
253 253
 
254
-        if (preg_match('/^\p{Ll}/u', $commentText) === 1) {
254
+        if ( preg_match( '/^\p{Ll}/u', $commentText ) === 1 ) {
255 255
             $error = 'Inline comments must start with a capital letter';
256
-            $phpcsFile->addError($error, $stackPtr, 'NotCapital');
256
+            $phpcsFile->addError( $error, $stackPtr, 'NotCapital' );
257 257
         }
258 258
 
259 259
         // Only check the end of comment character if the start of the comment
260 260
         // is a letter, indicating that the comment is just standard text.
261
-        if (preg_match('/^\p{L}/u', $commentText) === 1) {
262
-            $commentCloser   = $commentText[(strlen($commentText) - 1)];
261
+        if ( preg_match( '/^\p{L}/u', $commentText ) === 1 ) {
262
+            $commentCloser   = $commentText[ ( strlen( $commentText ) - 1 ) ];
263 263
             $acceptedClosers = [
264 264
                 'full-stops'        => '.',
265 265
                 'exclamation marks' => '!',
266 266
                 'or question marks' => '?',
267 267
             ];
268 268
 
269
-            if (in_array($commentCloser, $acceptedClosers, true) === false) {
269
+            if ( in_array( $commentCloser, $acceptedClosers, true ) === false ) {
270 270
                 $error = 'Inline comments must end in %s';
271 271
                 $ender = '';
272
-                foreach ($acceptedClosers as $closerName => $symbol) {
273
-                    $ender .= ' '.$closerName.',';
272
+                foreach ( $acceptedClosers as $closerName => $symbol ) {
273
+                    $ender .= ' ' . $closerName . ',';
274 274
                 }
275 275
 
276
-                $ender = trim($ender, ' ,');
277
-                $data  = [$ender];
278
-                $phpcsFile->addError($error, $lastCommentToken, 'InvalidEndChar', $data);
276
+                $ender = trim( $ender, ' ,' );
277
+                $data  = [ $ender ];
278
+                $phpcsFile->addError( $error, $lastCommentToken, 'InvalidEndChar', $data );
279 279
             }
280 280
         }
281 281
 
282 282
         // Finally, the line below the last comment cannot be empty if this inline
283 283
         // comment is on a line by itself.
284
-        if ($tokens[$previousContent]['line'] < $tokens[$stackPtr]['line']) {
285
-            $next = $phpcsFile->findNext(T_WHITESPACE, ($lastCommentToken + 1), null, true);
286
-            if ($next === false) {
284
+        if ( $tokens[ $previousContent ][ 'line' ] < $tokens[ $stackPtr ][ 'line' ] ) {
285
+            $next = $phpcsFile->findNext( T_WHITESPACE, ( $lastCommentToken + 1 ), null, true );
286
+            if ( $next === false ) {
287 287
                 // Ignore if the comment is the last non-whitespace token in a file.
288
-                return ($lastCommentToken + 1);
288
+                return ( $lastCommentToken + 1 );
289 289
             }
290 290
 
291
-            if ($tokens[$next]['code'] === T_DOC_COMMENT_OPEN_TAG) {
291
+            if ( $tokens[ $next ][ 'code' ] === T_DOC_COMMENT_OPEN_TAG ) {
292 292
                 // If this inline comment is followed by a docblock,
293 293
                 // ignore spacing as docblock/function etc spacing rules
294 294
                 // are likely to conflict with our rules.
295
-                return ($lastCommentToken + 1);
295
+                return ( $lastCommentToken + 1 );
296 296
             }
297 297
 
298 298
             $errorCode = 'SpacingAfter';
299 299
 
300
-            if (isset($tokens[$stackPtr]['conditions']) === true) {
301
-                $conditions   = $tokens[$stackPtr]['conditions'];
302
-                $type         = end($conditions);
303
-                $conditionPtr = key($conditions);
300
+            if ( isset( $tokens[ $stackPtr ][ 'conditions' ] ) === true ) {
301
+                $conditions   = $tokens[ $stackPtr ][ 'conditions' ];
302
+                $type         = end( $conditions );
303
+                $conditionPtr = key( $conditions );
304 304
 
305
-                if (($type === T_FUNCTION || $type === T_CLOSURE)
306
-                    && $tokens[$conditionPtr]['scope_closer'] === $next
305
+                if ( ( $type === T_FUNCTION || $type === T_CLOSURE )
306
+                    && $tokens[ $conditionPtr ][ 'scope_closer' ] === $next
307 307
                 ) {
308 308
                     $errorCode = 'SpacingAfterAtFunctionEnd';
309 309
                 }
310 310
             }
311 311
 
312
-            for ($i = ($lastCommentToken + 1); $i < $phpcsFile->numTokens; $i++) {
313
-                if ($tokens[$i]['line'] === ($tokens[$lastCommentToken]['line'] + 1)) {
314
-                    if ($tokens[$i]['code'] !== T_WHITESPACE) {
315
-                        return ($lastCommentToken + 1);
312
+            for ( $i = ( $lastCommentToken + 1 ); $i < $phpcsFile->numTokens; $i++ ) {
313
+                if ( $tokens[ $i ][ 'line' ] === ( $tokens[ $lastCommentToken ][ 'line' ] + 1 ) ) {
314
+                    if ( $tokens[ $i ][ 'code' ] !== T_WHITESPACE ) {
315
+                        return ( $lastCommentToken + 1 );
316 316
                     }
317
-                } else if ($tokens[$i]['line'] > ($tokens[$lastCommentToken]['line'] + 1)) {
317
+                } else if ( $tokens[ $i ][ 'line' ] > ( $tokens[ $lastCommentToken ][ 'line' ] + 1 ) ) {
318 318
                     break;
319 319
                 }
320 320
             }
321 321
 
322 322
             $error = 'There must be no blank line following an inline comment';
323
-            $fix   = $phpcsFile->addFixableError($error, $lastCommentToken, $errorCode);
324
-            if ($fix === true) {
323
+            $fix   = $phpcsFile->addFixableError( $error, $lastCommentToken, $errorCode );
324
+            if ( $fix === true ) {
325 325
                 $phpcsFile->fixer->beginChangeset();
326
-                for ($i = ($lastCommentToken + 1); $i < $next; $i++) {
327
-                    if ($tokens[$i]['line'] === $tokens[$next]['line']) {
326
+                for ( $i = ( $lastCommentToken + 1 ); $i < $next; $i++ ) {
327
+                    if ( $tokens[ $i ][ 'line' ] === $tokens[ $next ][ 'line' ] ) {
328 328
                         break;
329 329
                     }
330 330
 
331
-                    $phpcsFile->fixer->replaceToken($i, '');
331
+                    $phpcsFile->fixer->replaceToken( $i, '' );
332 332
                 }
333 333
 
334 334
                 $phpcsFile->fixer->endChangeset();
335 335
             }
336 336
         }//end if
337 337
 
338
-        return ($lastCommentToken + 1);
338
+        return ( $lastCommentToken + 1 );
339 339
 
340 340
     }//end process()
341 341
 
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 InlineCommentSniff implements Sniff
17
-{
16
+class InlineCommentSniff implements Sniff {
18 17
 
19 18
     /**
20 19
      * A list of tokenizers this sniff supports.
@@ -32,8 +31,7 @@  discard block
 block discarded – undo
32 31
      *
33 32
      * @return array
34 33
      */
35
-    public function register()
36
-    {
34
+    public function register() {
37 35
         return [
38 36
             T_COMMENT,
39 37
             T_DOC_COMMENT_OPEN_TAG,
@@ -51,8 +49,7 @@  discard block
 block discarded – undo
51 49
      *
52 50
      * @return void
53 51
      */
54
-    public function process(File $phpcsFile, $stackPtr)
55
-    {
52
+    public function process(File $phpcsFile, $stackPtr) {
56 53
         $tokens = $phpcsFile->getTokens();
57 54
 
58 55
         // If this is a function/class/interface doc block comment, skip it.
Please login to merge, or discard this patch.