Completed
Branch dev (588c07)
by
unknown
24:15 queued 17:27
created
src/Standards/Generic/Sniffs/Arrays/DisallowShortArraySyntaxSniff.php 1 patch
Indentation   +40 added lines, -40 removed lines patch added patch discarded remove patch
@@ -16,46 +16,46 @@
 block discarded – undo
16 16
 {
17 17
 
18 18
 
19
-    /**
20
-     * Registers the tokens that this sniff wants to listen for.
21
-     *
22
-     * @return int[]
23
-     */
24
-    public function register()
25
-    {
26
-        return [T_OPEN_SHORT_ARRAY];
27
-
28
-    }//end register()
29
-
30
-
31
-    /**
32
-     * Processes this test, 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
36
-     *                                               in the stack passed in $tokens.
37
-     *
38
-     * @return void
39
-     */
40
-    public function process(File $phpcsFile, $stackPtr)
41
-    {
42
-        $phpcsFile->recordMetric($stackPtr, 'Short array syntax used', 'yes');
43
-
44
-        $error = 'Short array syntax is not allowed';
45
-        $fix   = $phpcsFile->addFixableError($error, $stackPtr, 'Found');
46
-
47
-        if ($fix === true) {
48
-            $tokens = $phpcsFile->getTokens();
49
-            $opener = $tokens[$stackPtr]['bracket_opener'];
50
-            $closer = $tokens[$stackPtr]['bracket_closer'];
51
-
52
-            $phpcsFile->fixer->beginChangeset();
53
-            $phpcsFile->fixer->replaceToken($opener, 'array(');
54
-            $phpcsFile->fixer->replaceToken($closer, ')');
55
-            $phpcsFile->fixer->endChangeset();
56
-        }
57
-
58
-    }//end process()
19
+	/**
20
+	 * Registers the tokens that this sniff wants to listen for.
21
+	 *
22
+	 * @return int[]
23
+	 */
24
+	public function register()
25
+	{
26
+		return [T_OPEN_SHORT_ARRAY];
27
+
28
+	}//end register()
29
+
30
+
31
+	/**
32
+	 * Processes this test, 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
36
+	 *                                               in the stack passed in $tokens.
37
+	 *
38
+	 * @return void
39
+	 */
40
+	public function process(File $phpcsFile, $stackPtr)
41
+	{
42
+		$phpcsFile->recordMetric($stackPtr, 'Short array syntax used', 'yes');
43
+
44
+		$error = 'Short array syntax is not allowed';
45
+		$fix   = $phpcsFile->addFixableError($error, $stackPtr, 'Found');
46
+
47
+		if ($fix === true) {
48
+			$tokens = $phpcsFile->getTokens();
49
+			$opener = $tokens[$stackPtr]['bracket_opener'];
50
+			$closer = $tokens[$stackPtr]['bracket_closer'];
51
+
52
+			$phpcsFile->fixer->beginChangeset();
53
+			$phpcsFile->fixer->replaceToken($opener, 'array(');
54
+			$phpcsFile->fixer->replaceToken($closer, ')');
55
+			$phpcsFile->fixer->endChangeset();
56
+		}
57
+
58
+	}//end process()
59 59
 
60 60
 
61 61
 }//end class
Please login to merge, or discard this patch.
src/Standards/Generic/Sniffs/Formatting/NoSpaceAfterCastSniff.php 1 patch
Indentation   +36 added lines, -36 removed lines patch added patch discarded remove patch
@@ -17,42 +17,42 @@
 block discarded – undo
17 17
 {
18 18
 
19 19
 
20
-    /**
21
-     * Returns an array of tokens this test wants to listen for.
22
-     *
23
-     * @return array
24
-     */
25
-    public function register()
26
-    {
27
-        return Tokens::$castTokens;
28
-
29
-    }//end register()
30
-
31
-
32
-    /**
33
-     * Processes this test, when one of its tokens is encountered.
34
-     *
35
-     * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.
36
-     * @param int                         $stackPtr  The position of the current token in
37
-     *                                               the stack passed in $tokens.
38
-     *
39
-     * @return void
40
-     */
41
-    public function process(File $phpcsFile, $stackPtr)
42
-    {
43
-        $tokens = $phpcsFile->getTokens();
44
-
45
-        if ($tokens[($stackPtr + 1)]['code'] !== T_WHITESPACE) {
46
-            return;
47
-        }
48
-
49
-        $error = 'A cast statement must not be followed by a space';
50
-        $fix   = $phpcsFile->addFixableError($error, $stackPtr, 'SpaceFound');
51
-        if ($fix === true) {
52
-            $phpcsFile->fixer->replaceToken(($stackPtr + 1), '');
53
-        }
54
-
55
-    }//end process()
20
+	/**
21
+	 * Returns an array of tokens this test wants to listen for.
22
+	 *
23
+	 * @return array
24
+	 */
25
+	public function register()
26
+	{
27
+		return Tokens::$castTokens;
28
+
29
+	}//end register()
30
+
31
+
32
+	/**
33
+	 * Processes this test, when one of its tokens is encountered.
34
+	 *
35
+	 * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.
36
+	 * @param int                         $stackPtr  The position of the current token in
37
+	 *                                               the stack passed in $tokens.
38
+	 *
39
+	 * @return void
40
+	 */
41
+	public function process(File $phpcsFile, $stackPtr)
42
+	{
43
+		$tokens = $phpcsFile->getTokens();
44
+
45
+		if ($tokens[($stackPtr + 1)]['code'] !== T_WHITESPACE) {
46
+			return;
47
+		}
48
+
49
+		$error = 'A cast statement must not be followed by a space';
50
+		$fix   = $phpcsFile->addFixableError($error, $stackPtr, 'SpaceFound');
51
+		if ($fix === true) {
52
+			$phpcsFile->fixer->replaceToken(($stackPtr + 1), '');
53
+		}
54
+
55
+	}//end process()
56 56
 
57 57
 
58 58
 }//end class
Please login to merge, or discard this patch.
src/Standards/Generic/Sniffs/Strings/UnnecessaryStringConcatSniff.php 1 patch
Indentation   +104 added lines, -104 removed lines patch added patch discarded remove patch
@@ -16,110 +16,110 @@
 block discarded – undo
16 16
 class UnnecessaryStringConcatSniff 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
-     * If true, an error will be thrown; otherwise a warning.
31
-     *
32
-     * @var boolean
33
-     */
34
-    public $error = true;
35
-
36
-    /**
37
-     * If true, strings concatenated over multiple lines are allowed.
38
-     *
39
-     * Useful if you break strings over multiple lines to work
40
-     * within a max line length.
41
-     *
42
-     * @var boolean
43
-     */
44
-    public $allowMultiline = false;
45
-
46
-
47
-    /**
48
-     * Returns an array of tokens this test wants to listen for.
49
-     *
50
-     * @return array
51
-     */
52
-    public function register()
53
-    {
54
-        return [
55
-            T_STRING_CONCAT,
56
-            T_PLUS,
57
-        ];
58
-
59
-    }//end register()
60
-
61
-
62
-    /**
63
-     * Processes this sniff, when one of its tokens is encountered.
64
-     *
65
-     * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.
66
-     * @param int                         $stackPtr  The position of the current token
67
-     *                                               in the stack passed in $tokens.
68
-     *
69
-     * @return void
70
-     */
71
-    public function process(File $phpcsFile, $stackPtr)
72
-    {
73
-        // Work out which type of file this is for.
74
-        $tokens = $phpcsFile->getTokens();
75
-        if ($tokens[$stackPtr]['code'] === T_STRING_CONCAT) {
76
-            if ($phpcsFile->tokenizerType === 'JS') {
77
-                return;
78
-            }
79
-        } else {
80
-            if ($phpcsFile->tokenizerType === 'PHP') {
81
-                return;
82
-            }
83
-        }
84
-
85
-        $prev = $phpcsFile->findPrevious(T_WHITESPACE, ($stackPtr - 1), null, true);
86
-        $next = $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 1), null, true);
87
-        if ($prev === false || $next === false) {
88
-            return;
89
-        }
90
-
91
-        if (isset(Tokens::$stringTokens[$tokens[$prev]['code']]) === true
92
-            && isset(Tokens::$stringTokens[$tokens[$next]['code']]) === true
93
-        ) {
94
-            if ($tokens[$prev]['content'][0] === $tokens[$next]['content'][0]) {
95
-                // Before we throw an error for PHP, allow strings to be
96
-                // combined if they would have < and ? next to each other because
97
-                // this trick is sometimes required in PHP strings.
98
-                if ($phpcsFile->tokenizerType === 'PHP') {
99
-                    $prevChar = substr($tokens[$prev]['content'], -2, 1);
100
-                    $nextChar = $tokens[$next]['content'][1];
101
-                    $combined = $prevChar.$nextChar;
102
-                    if ($combined === '?'.'>' || $combined === '<'.'?') {
103
-                        return;
104
-                    }
105
-                }
106
-
107
-                if ($this->allowMultiline === true
108
-                    && $tokens[$prev]['line'] !== $tokens[$next]['line']
109
-                ) {
110
-                    return;
111
-                }
112
-
113
-                $error = 'String concat is not required here; use a single string instead';
114
-                if ($this->error === true) {
115
-                    $phpcsFile->addError($error, $stackPtr, 'Found');
116
-                } else {
117
-                    $phpcsFile->addWarning($error, $stackPtr, 'Found');
118
-                }
119
-            }//end if
120
-        }//end if
121
-
122
-    }//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
+	 * If true, an error will be thrown; otherwise a warning.
31
+	 *
32
+	 * @var boolean
33
+	 */
34
+	public $error = true;
35
+
36
+	/**
37
+	 * If true, strings concatenated over multiple lines are allowed.
38
+	 *
39
+	 * Useful if you break strings over multiple lines to work
40
+	 * within a max line length.
41
+	 *
42
+	 * @var boolean
43
+	 */
44
+	public $allowMultiline = false;
45
+
46
+
47
+	/**
48
+	 * Returns an array of tokens this test wants to listen for.
49
+	 *
50
+	 * @return array
51
+	 */
52
+	public function register()
53
+	{
54
+		return [
55
+			T_STRING_CONCAT,
56
+			T_PLUS,
57
+		];
58
+
59
+	}//end register()
60
+
61
+
62
+	/**
63
+	 * Processes this sniff, when one of its tokens is encountered.
64
+	 *
65
+	 * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.
66
+	 * @param int                         $stackPtr  The position of the current token
67
+	 *                                               in the stack passed in $tokens.
68
+	 *
69
+	 * @return void
70
+	 */
71
+	public function process(File $phpcsFile, $stackPtr)
72
+	{
73
+		// Work out which type of file this is for.
74
+		$tokens = $phpcsFile->getTokens();
75
+		if ($tokens[$stackPtr]['code'] === T_STRING_CONCAT) {
76
+			if ($phpcsFile->tokenizerType === 'JS') {
77
+				return;
78
+			}
79
+		} else {
80
+			if ($phpcsFile->tokenizerType === 'PHP') {
81
+				return;
82
+			}
83
+		}
84
+
85
+		$prev = $phpcsFile->findPrevious(T_WHITESPACE, ($stackPtr - 1), null, true);
86
+		$next = $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 1), null, true);
87
+		if ($prev === false || $next === false) {
88
+			return;
89
+		}
90
+
91
+		if (isset(Tokens::$stringTokens[$tokens[$prev]['code']]) === true
92
+			&& isset(Tokens::$stringTokens[$tokens[$next]['code']]) === true
93
+		) {
94
+			if ($tokens[$prev]['content'][0] === $tokens[$next]['content'][0]) {
95
+				// Before we throw an error for PHP, allow strings to be
96
+				// combined if they would have < and ? next to each other because
97
+				// this trick is sometimes required in PHP strings.
98
+				if ($phpcsFile->tokenizerType === 'PHP') {
99
+					$prevChar = substr($tokens[$prev]['content'], -2, 1);
100
+					$nextChar = $tokens[$next]['content'][1];
101
+					$combined = $prevChar.$nextChar;
102
+					if ($combined === '?'.'>' || $combined === '<'.'?') {
103
+						return;
104
+					}
105
+				}
106
+
107
+				if ($this->allowMultiline === true
108
+					&& $tokens[$prev]['line'] !== $tokens[$next]['line']
109
+				) {
110
+					return;
111
+				}
112
+
113
+				$error = 'String concat is not required here; use a single string instead';
114
+				if ($this->error === true) {
115
+					$phpcsFile->addError($error, $stackPtr, 'Found');
116
+				} else {
117
+					$phpcsFile->addWarning($error, $stackPtr, 'Found');
118
+				}
119
+			}//end if
120
+		}//end if
121
+
122
+	}//end process()
123 123
 
124 124
 
125 125
 }//end class
Please login to merge, or discard this patch.
src/Standards/Generic/Sniffs/Files/OneInterfacePerFileSniff.php 1 patch
Indentation   +30 added lines, -30 removed lines patch added patch discarded remove patch
@@ -16,36 +16,36 @@
 block discarded – undo
16 16
 {
17 17
 
18 18
 
19
-    /**
20
-     * Returns an array of tokens this test wants to listen for.
21
-     *
22
-     * @return array
23
-     */
24
-    public function register()
25
-    {
26
-        return [T_INTERFACE];
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
-        $nextInterface = $phpcsFile->findNext($this->register(), ($stackPtr + 1));
43
-        if ($nextInterface !== false) {
44
-            $error = 'Only one interface is allowed in a file';
45
-            $phpcsFile->addError($error, $nextInterface, 'MultipleFound');
46
-        }
47
-
48
-    }//end process()
19
+	/**
20
+	 * Returns an array of tokens this test wants to listen for.
21
+	 *
22
+	 * @return array
23
+	 */
24
+	public function register()
25
+	{
26
+		return [T_INTERFACE];
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
+		$nextInterface = $phpcsFile->findNext($this->register(), ($stackPtr + 1));
43
+		if ($nextInterface !== false) {
44
+			$error = 'Only one interface is allowed in a file';
45
+			$phpcsFile->addError($error, $nextInterface, 'MultipleFound');
46
+		}
47
+
48
+	}//end process()
49 49
 
50 50
 
51 51
 }//end class
Please login to merge, or discard this patch.
php_codesniffer/src/Standards/Generic/Sniffs/Files/ByteOrderMarkSniff.php 1 patch
Indentation   +50 added lines, -50 removed lines patch added patch discarded remove patch
@@ -16,65 +16,65 @@
 block discarded – undo
16 16
 class ByteOrderMarkSniff implements Sniff
17 17
 {
18 18
 
19
-    /**
20
-     * List of supported BOM definitions.
21
-     *
22
-     * Use encoding names as keys and hex BOM representations as values.
23
-     *
24
-     * @var array
25
-     */
26
-    protected $bomDefinitions = [
27
-        'UTF-8'       => 'efbbbf',
28
-        'UTF-16 (BE)' => 'feff',
29
-        'UTF-16 (LE)' => 'fffe',
30
-    ];
19
+	/**
20
+	 * List of supported BOM definitions.
21
+	 *
22
+	 * Use encoding names as keys and hex BOM representations as values.
23
+	 *
24
+	 * @var array
25
+	 */
26
+	protected $bomDefinitions = [
27
+		'UTF-8'       => 'efbbbf',
28
+		'UTF-16 (BE)' => 'feff',
29
+		'UTF-16 (LE)' => 'fffe',
30
+	];
31 31
 
32 32
 
33
-    /**
34
-     * Returns an array of tokens this test wants to listen for.
35
-     *
36
-     * @return array
37
-     */
38
-    public function register()
39
-    {
40
-        return [T_INLINE_HTML];
33
+	/**
34
+	 * Returns an array of tokens this test wants to listen for.
35
+	 *
36
+	 * @return array
37
+	 */
38
+	public function register()
39
+	{
40
+		return [T_INLINE_HTML];
41 41
 
42
-    }//end register()
42
+	}//end register()
43 43
 
44 44
 
45
-    /**
46
-     * Processes this sniff, 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
50
-     *                                               the stack passed in $tokens.
51
-     *
52
-     * @return void
53
-     */
54
-    public function process(File $phpcsFile, $stackPtr)
55
-    {
56
-        // The BOM will be the very first token in the file.
57
-        if ($stackPtr !== 0) {
58
-            return;
59
-        }
45
+	/**
46
+	 * Processes this sniff, 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
50
+	 *                                               the stack passed in $tokens.
51
+	 *
52
+	 * @return void
53
+	 */
54
+	public function process(File $phpcsFile, $stackPtr)
55
+	{
56
+		// The BOM will be the very first token in the file.
57
+		if ($stackPtr !== 0) {
58
+			return;
59
+		}
60 60
 
61
-        $tokens = $phpcsFile->getTokens();
61
+		$tokens = $phpcsFile->getTokens();
62 62
 
63
-        foreach ($this->bomDefinitions as $bomName => $expectedBomHex) {
64
-            $bomByteLength = (strlen($expectedBomHex) / 2);
65
-            $htmlBomHex    = bin2hex(substr($tokens[$stackPtr]['content'], 0, $bomByteLength));
66
-            if ($htmlBomHex === $expectedBomHex) {
67
-                $errorData = [$bomName];
68
-                $error     = 'File contains %s byte order mark, which may corrupt your application';
69
-                $phpcsFile->addError($error, $stackPtr, 'Found', $errorData);
70
-                $phpcsFile->recordMetric($stackPtr, 'Using byte order mark', 'yes');
71
-                return;
72
-            }
73
-        }
63
+		foreach ($this->bomDefinitions as $bomName => $expectedBomHex) {
64
+			$bomByteLength = (strlen($expectedBomHex) / 2);
65
+			$htmlBomHex    = bin2hex(substr($tokens[$stackPtr]['content'], 0, $bomByteLength));
66
+			if ($htmlBomHex === $expectedBomHex) {
67
+				$errorData = [$bomName];
68
+				$error     = 'File contains %s byte order mark, which may corrupt your application';
69
+				$phpcsFile->addError($error, $stackPtr, 'Found', $errorData);
70
+				$phpcsFile->recordMetric($stackPtr, 'Using byte order mark', 'yes');
71
+				return;
72
+			}
73
+		}
74 74
 
75
-        $phpcsFile->recordMetric($stackPtr, 'Using byte order mark', 'no');
75
+		$phpcsFile->recordMetric($stackPtr, 'Using byte order mark', 'no');
76 76
 
77
-    }//end process()
77
+	}//end process()
78 78
 
79 79
 
80 80
 }//end class
Please login to merge, or discard this patch.
php_codesniffer/src/Standards/Generic/Sniffs/Files/LineEndingsSniff.php 2 patches
Switch Indentation   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -95,18 +95,18 @@
 block discarded – undo
95 95
         if ($fix === true) {
96 96
             $tokens = $phpcsFile->getTokens();
97 97
             switch ($this->eolChar) {
98
-            case '\n':
99
-                $eolChar = "\n";
100
-                break;
101
-            case '\r':
102
-                $eolChar = "\r";
103
-                break;
104
-            case '\r\n':
105
-                $eolChar = "\r\n";
106
-                break;
107
-            default:
108
-                $eolChar = $this->eolChar;
109
-                break;
98
+            	case '\n':
99
+                	$eolChar = "\n";
100
+                	break;
101
+            	case '\r':
102
+                	$eolChar = "\r";
103
+                	break;
104
+            	case '\r\n':
105
+                	$eolChar = "\r\n";
106
+                	break;
107
+            	default:
108
+                	$eolChar = $this->eolChar;
109
+                	break;
110 110
             }
111 111
 
112 112
             for ($i = 0; $i < $phpcsFile->numTokens; $i++) {
Please login to merge, or discard this patch.
Indentation   +128 added lines, -128 removed lines patch added patch discarded remove patch
@@ -15,134 +15,134 @@
 block discarded – undo
15 15
 class LineEndingsSniff implements Sniff
16 16
 {
17 17
 
18
-    /**
19
-     * A list of tokenizers this sniff supports.
20
-     *
21
-     * @var array
22
-     */
23
-    public $supportedTokenizers = [
24
-        'PHP',
25
-        'JS',
26
-        'CSS',
27
-    ];
28
-
29
-    /**
30
-     * The valid EOL character.
31
-     *
32
-     * @var string
33
-     */
34
-    public $eolChar = '\n';
35
-
36
-
37
-    /**
38
-     * Returns an array of tokens this test wants to listen for.
39
-     *
40
-     * @return array
41
-     */
42
-    public function register()
43
-    {
44
-        return [
45
-            T_OPEN_TAG,
46
-            T_OPEN_TAG_WITH_ECHO,
47
-        ];
48
-
49
-    }//end register()
50
-
51
-
52
-    /**
53
-     * Processes this sniff, when one of its tokens is encountered.
54
-     *
55
-     * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.
56
-     * @param int                         $stackPtr  The position of the current token in
57
-     *                                               the stack passed in $tokens.
58
-     *
59
-     * @return int
60
-     */
61
-    public function process(File $phpcsFile, $stackPtr)
62
-    {
63
-        $found = $phpcsFile->eolChar;
64
-        $found = str_replace("\n", '\n', $found);
65
-        $found = str_replace("\r", '\r', $found);
66
-
67
-        $phpcsFile->recordMetric($stackPtr, 'EOL char', $found);
68
-
69
-        if ($found === $this->eolChar) {
70
-            // Ignore the rest of the file.
71
-            return ($phpcsFile->numTokens + 1);
72
-        }
73
-
74
-        // Check for single line files without an EOL. This is a very special
75
-        // case and the EOL char is set to \n when this happens.
76
-        if ($found === '\n') {
77
-            $tokens    = $phpcsFile->getTokens();
78
-            $lastToken = ($phpcsFile->numTokens - 1);
79
-            if ($tokens[$lastToken]['line'] === 1
80
-                && $tokens[$lastToken]['content'] !== "\n"
81
-            ) {
82
-                return;
83
-            }
84
-        }
85
-
86
-        $error    = 'End of line character is invalid; expected "%s" but found "%s"';
87
-        $expected = $this->eolChar;
88
-        $expected = str_replace("\n", '\n', $expected);
89
-        $expected = str_replace("\r", '\r', $expected);
90
-        $data     = [
91
-            $expected,
92
-            $found,
93
-        ];
94
-
95
-        // Errors are always reported on line 1, no matter where the first PHP tag is.
96
-        $fix = $phpcsFile->addFixableError($error, 0, 'InvalidEOLChar', $data);
97
-
98
-        if ($fix === true) {
99
-            $tokens = $phpcsFile->getTokens();
100
-            switch ($this->eolChar) {
101
-            case '\n':
102
-                $eolChar = "\n";
103
-                break;
104
-            case '\r':
105
-                $eolChar = "\r";
106
-                break;
107
-            case '\r\n':
108
-                $eolChar = "\r\n";
109
-                break;
110
-            default:
111
-                $eolChar = $this->eolChar;
112
-                break;
113
-            }
114
-
115
-            for ($i = 0; $i < $phpcsFile->numTokens; $i++) {
116
-                if (isset($tokens[($i + 1)]) === true
117
-                    && $tokens[($i + 1)]['line'] <= $tokens[$i]['line']
118
-                ) {
119
-                    continue;
120
-                }
121
-
122
-                // Token is the last on a line.
123
-                if (isset($tokens[$i]['orig_content']) === true) {
124
-                    $tokenContent = $tokens[$i]['orig_content'];
125
-                } else {
126
-                    $tokenContent = $tokens[$i]['content'];
127
-                }
128
-
129
-                if ($tokenContent === '') {
130
-                    // Special case for JS/CSS close tag.
131
-                    continue;
132
-                }
133
-
134
-                $newContent  = rtrim($tokenContent, "\r\n");
135
-                $newContent .= $eolChar;
136
-                if ($tokenContent !== $newContent) {
137
-                    $phpcsFile->fixer->replaceToken($i, $newContent);
138
-                }
139
-            }//end for
140
-        }//end if
141
-
142
-        // Ignore the rest of the file.
143
-        return ($phpcsFile->numTokens + 1);
144
-
145
-    }//end process()
18
+	/**
19
+	 * A list of tokenizers this sniff supports.
20
+	 *
21
+	 * @var array
22
+	 */
23
+	public $supportedTokenizers = [
24
+		'PHP',
25
+		'JS',
26
+		'CSS',
27
+	];
28
+
29
+	/**
30
+	 * The valid EOL character.
31
+	 *
32
+	 * @var string
33
+	 */
34
+	public $eolChar = '\n';
35
+
36
+
37
+	/**
38
+	 * Returns an array of tokens this test wants to listen for.
39
+	 *
40
+	 * @return array
41
+	 */
42
+	public function register()
43
+	{
44
+		return [
45
+			T_OPEN_TAG,
46
+			T_OPEN_TAG_WITH_ECHO,
47
+		];
48
+
49
+	}//end register()
50
+
51
+
52
+	/**
53
+	 * Processes this sniff, when one of its tokens is encountered.
54
+	 *
55
+	 * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.
56
+	 * @param int                         $stackPtr  The position of the current token in
57
+	 *                                               the stack passed in $tokens.
58
+	 *
59
+	 * @return int
60
+	 */
61
+	public function process(File $phpcsFile, $stackPtr)
62
+	{
63
+		$found = $phpcsFile->eolChar;
64
+		$found = str_replace("\n", '\n', $found);
65
+		$found = str_replace("\r", '\r', $found);
66
+
67
+		$phpcsFile->recordMetric($stackPtr, 'EOL char', $found);
68
+
69
+		if ($found === $this->eolChar) {
70
+			// Ignore the rest of the file.
71
+			return ($phpcsFile->numTokens + 1);
72
+		}
73
+
74
+		// Check for single line files without an EOL. This is a very special
75
+		// case and the EOL char is set to \n when this happens.
76
+		if ($found === '\n') {
77
+			$tokens    = $phpcsFile->getTokens();
78
+			$lastToken = ($phpcsFile->numTokens - 1);
79
+			if ($tokens[$lastToken]['line'] === 1
80
+				&& $tokens[$lastToken]['content'] !== "\n"
81
+			) {
82
+				return;
83
+			}
84
+		}
85
+
86
+		$error    = 'End of line character is invalid; expected "%s" but found "%s"';
87
+		$expected = $this->eolChar;
88
+		$expected = str_replace("\n", '\n', $expected);
89
+		$expected = str_replace("\r", '\r', $expected);
90
+		$data     = [
91
+			$expected,
92
+			$found,
93
+		];
94
+
95
+		// Errors are always reported on line 1, no matter where the first PHP tag is.
96
+		$fix = $phpcsFile->addFixableError($error, 0, 'InvalidEOLChar', $data);
97
+
98
+		if ($fix === true) {
99
+			$tokens = $phpcsFile->getTokens();
100
+			switch ($this->eolChar) {
101
+			case '\n':
102
+				$eolChar = "\n";
103
+				break;
104
+			case '\r':
105
+				$eolChar = "\r";
106
+				break;
107
+			case '\r\n':
108
+				$eolChar = "\r\n";
109
+				break;
110
+			default:
111
+				$eolChar = $this->eolChar;
112
+				break;
113
+			}
114
+
115
+			for ($i = 0; $i < $phpcsFile->numTokens; $i++) {
116
+				if (isset($tokens[($i + 1)]) === true
117
+					&& $tokens[($i + 1)]['line'] <= $tokens[$i]['line']
118
+				) {
119
+					continue;
120
+				}
121
+
122
+				// Token is the last on a line.
123
+				if (isset($tokens[$i]['orig_content']) === true) {
124
+					$tokenContent = $tokens[$i]['orig_content'];
125
+				} else {
126
+					$tokenContent = $tokens[$i]['content'];
127
+				}
128
+
129
+				if ($tokenContent === '') {
130
+					// Special case for JS/CSS close tag.
131
+					continue;
132
+				}
133
+
134
+				$newContent  = rtrim($tokenContent, "\r\n");
135
+				$newContent .= $eolChar;
136
+				if ($tokenContent !== $newContent) {
137
+					$phpcsFile->fixer->replaceToken($i, $newContent);
138
+				}
139
+			}//end for
140
+		}//end if
141
+
142
+		// Ignore the rest of the file.
143
+		return ($phpcsFile->numTokens + 1);
144
+
145
+	}//end process()
146 146
 
147 147
 
148 148
 }//end class
Please login to merge, or discard this patch.
src/Standards/Generic/Sniffs/Files/OneObjectStructurePerFileSniff.php 1 patch
Indentation   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -16,40 +16,40 @@
 block discarded – undo
16 16
 {
17 17
 
18 18
 
19
-    /**
20
-     * Returns an array of tokens this test wants to listen for.
21
-     *
22
-     * @return array
23
-     */
24
-    public function register()
25
-    {
26
-        return [
27
-            T_CLASS,
28
-            T_INTERFACE,
29
-            T_TRAIT,
30
-        ];
31
-
32
-    }//end register()
33
-
34
-
35
-    /**
36
-     * Processes this sniff, when one of its tokens is encountered.
37
-     *
38
-     * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.
39
-     * @param int                         $stackPtr  The position of the current token in
40
-     *                                               the stack passed in $tokens.
41
-     *
42
-     * @return void
43
-     */
44
-    public function process(File $phpcsFile, $stackPtr)
45
-    {
46
-        $nextClass = $phpcsFile->findNext($this->register(), ($stackPtr + 1));
47
-        if ($nextClass !== false) {
48
-            $error = 'Only one object structure is allowed in a file';
49
-            $phpcsFile->addError($error, $nextClass, 'MultipleFound');
50
-        }
51
-
52
-    }//end process()
19
+	/**
20
+	 * Returns an array of tokens this test wants to listen for.
21
+	 *
22
+	 * @return array
23
+	 */
24
+	public function register()
25
+	{
26
+		return [
27
+			T_CLASS,
28
+			T_INTERFACE,
29
+			T_TRAIT,
30
+		];
31
+
32
+	}//end register()
33
+
34
+
35
+	/**
36
+	 * Processes this sniff, when one of its tokens is encountered.
37
+	 *
38
+	 * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.
39
+	 * @param int                         $stackPtr  The position of the current token in
40
+	 *                                               the stack passed in $tokens.
41
+	 *
42
+	 * @return void
43
+	 */
44
+	public function process(File $phpcsFile, $stackPtr)
45
+	{
46
+		$nextClass = $phpcsFile->findNext($this->register(), ($stackPtr + 1));
47
+		if ($nextClass !== false) {
48
+			$error = 'Only one object structure is allowed in a file';
49
+			$phpcsFile->addError($error, $nextClass, 'MultipleFound');
50
+		}
51
+
52
+	}//end process()
53 53
 
54 54
 
55 55
 }//end class
Please login to merge, or discard this patch.
php_codesniffer/src/Standards/Generic/Sniffs/Files/OneTraitPerFileSniff.php 1 patch
Indentation   +30 added lines, -30 removed lines patch added patch discarded remove patch
@@ -16,36 +16,36 @@
 block discarded – undo
16 16
 {
17 17
 
18 18
 
19
-    /**
20
-     * Returns an array of tokens this test wants to listen for.
21
-     *
22
-     * @return array
23
-     */
24
-    public function register()
25
-    {
26
-        return [T_TRAIT];
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
-        $nextClass = $phpcsFile->findNext($this->register(), ($stackPtr + 1));
43
-        if ($nextClass !== false) {
44
-            $error = 'Only one trait is allowed in a file';
45
-            $phpcsFile->addError($error, $nextClass, 'MultipleFound');
46
-        }
47
-
48
-    }//end process()
19
+	/**
20
+	 * Returns an array of tokens this test wants to listen for.
21
+	 *
22
+	 * @return array
23
+	 */
24
+	public function register()
25
+	{
26
+		return [T_TRAIT];
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
+		$nextClass = $phpcsFile->findNext($this->register(), ($stackPtr + 1));
43
+		if ($nextClass !== false) {
44
+			$error = 'Only one trait is allowed in a file';
45
+			$phpcsFile->addError($error, $nextClass, 'MultipleFound');
46
+		}
47
+
48
+	}//end process()
49 49
 
50 50
 
51 51
 }//end class
Please login to merge, or discard this patch.
php_codesniffer/src/Standards/Generic/Sniffs/Files/OneClassPerFileSniff.php 1 patch
Indentation   +30 added lines, -30 removed lines patch added patch discarded remove patch
@@ -16,36 +16,36 @@
 block discarded – undo
16 16
 {
17 17
 
18 18
 
19
-    /**
20
-     * Returns an array of tokens this test wants to listen for.
21
-     *
22
-     * @return array
23
-     */
24
-    public function register()
25
-    {
26
-        return [T_CLASS];
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
-        $nextClass = $phpcsFile->findNext($this->register(), ($stackPtr + 1));
43
-        if ($nextClass !== false) {
44
-            $error = 'Only one class is allowed in a file';
45
-            $phpcsFile->addError($error, $nextClass, 'MultipleFound');
46
-        }
47
-
48
-    }//end process()
19
+	/**
20
+	 * Returns an array of tokens this test wants to listen for.
21
+	 *
22
+	 * @return array
23
+	 */
24
+	public function register()
25
+	{
26
+		return [T_CLASS];
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
+		$nextClass = $phpcsFile->findNext($this->register(), ($stackPtr + 1));
43
+		if ($nextClass !== false) {
44
+			$error = 'Only one class is allowed in a file';
45
+			$phpcsFile->addError($error, $nextClass, 'MultipleFound');
46
+		}
47
+
48
+	}//end process()
49 49
 
50 50
 
51 51
 }//end class
Please login to merge, or discard this patch.