Completed
Branch BUG/required-message-fields (8f9492)
by
unknown
10:53 queued 20s
created
src/Standards/MySource/Sniffs/PHP/ReturnFunctionValueSniff.php 1 patch
Indentation   +42 added lines, -42 removed lines patch added patch discarded remove patch
@@ -16,48 +16,48 @@
 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_RETURN];
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
-        $tokens = $phpcsFile->getTokens();
43
-
44
-        $functionName = $phpcsFile->findNext(T_STRING, ($stackPtr + 1), null, false, null, true);
45
-
46
-        while ($functionName !== false) {
47
-            // Check if this is really a function.
48
-            $bracket = $phpcsFile->findNext(T_WHITESPACE, ($functionName + 1), null, true);
49
-            if ($tokens[$bracket]['code'] !== T_OPEN_PARENTHESIS) {
50
-                // Not a function call.
51
-                $functionName = $phpcsFile->findNext(T_STRING, ($functionName + 1), null, false, null, true);
52
-                continue;
53
-            }
54
-
55
-            $error = 'The result of a function call should be assigned to a variable before being returned';
56
-            $phpcsFile->addWarning($error, $stackPtr, 'NotAssigned');
57
-            break;
58
-        }
59
-
60
-    }//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_RETURN];
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
+		$tokens = $phpcsFile->getTokens();
43
+
44
+		$functionName = $phpcsFile->findNext(T_STRING, ($stackPtr + 1), null, false, null, true);
45
+
46
+		while ($functionName !== false) {
47
+			// Check if this is really a function.
48
+			$bracket = $phpcsFile->findNext(T_WHITESPACE, ($functionName + 1), null, true);
49
+			if ($tokens[$bracket]['code'] !== T_OPEN_PARENTHESIS) {
50
+				// Not a function call.
51
+				$functionName = $phpcsFile->findNext(T_STRING, ($functionName + 1), null, false, null, true);
52
+				continue;
53
+			}
54
+
55
+			$error = 'The result of a function call should be assigned to a variable before being returned';
56
+			$phpcsFile->addWarning($error, $stackPtr, 'NotAssigned');
57
+			break;
58
+		}
59
+
60
+	}//end process()
61 61
 
62 62
 
63 63
 }//end class
Please login to merge, or discard this patch.
php_codesniffer/src/Standards/MySource/Sniffs/PHP/GetRequestDataSniff.php 1 patch
Indentation   +85 added lines, -85 removed lines patch added patch discarded remove patch
@@ -16,91 +16,91 @@
 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_VARIABLE];
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
-        $tokens = $phpcsFile->getTokens();
43
-
44
-        $varName = $tokens[$stackPtr]['content'];
45
-        if ($varName !== '$_REQUEST'
46
-            && $varName !== '$_GET'
47
-            && $varName !== '$_POST'
48
-            && $varName !== '$_FILES'
49
-        ) {
50
-            return;
51
-        }
52
-
53
-        // The only place these super globals can be accessed directly is
54
-        // in the getRequestData() method of the Security class.
55
-        $inClass = false;
56
-        foreach ($tokens[$stackPtr]['conditions'] as $i => $type) {
57
-            if ($tokens[$i]['code'] === T_CLASS) {
58
-                $className = $phpcsFile->findNext(T_STRING, $i);
59
-                $className = $tokens[$className]['content'];
60
-                if (strtolower($className) === 'security') {
61
-                    $inClass = true;
62
-                } else {
63
-                    // We don't have nested classes.
64
-                    break;
65
-                }
66
-            } else if ($inClass === true && $tokens[$i]['code'] === T_FUNCTION) {
67
-                $funcName = $phpcsFile->findNext(T_STRING, $i);
68
-                $funcName = $tokens[$funcName]['content'];
69
-                if (strtolower($funcName) === 'getrequestdata') {
70
-                    // This is valid.
71
-                    return;
72
-                } else {
73
-                    // We don't have nested functions.
74
-                    break;
75
-                }
76
-            }//end if
77
-        }//end foreach
78
-
79
-        // If we get to here, the super global was used incorrectly.
80
-        // First find out how it is being used.
81
-        $globalName = strtolower(substr($varName, 2));
82
-        $usedVar    = '';
83
-
84
-        $openBracket = $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 1), null, true);
85
-        if ($tokens[$openBracket]['code'] === T_OPEN_SQUARE_BRACKET) {
86
-            $closeBracket = $tokens[$openBracket]['bracket_closer'];
87
-            $usedVar      = $phpcsFile->getTokensAsString(($openBracket + 1), ($closeBracket - $openBracket - 1));
88
-        }
89
-
90
-        $type  = 'SuperglobalAccessed';
91
-        $error = 'The %s super global must not be accessed directly; use Security::getRequestData(';
92
-        $data  = [$varName];
93
-        if ($usedVar !== '') {
94
-            $type  .= 'WithVar';
95
-            $error .= '%s, \'%s\'';
96
-            $data[] = $usedVar;
97
-            $data[] = $globalName;
98
-        }
99
-
100
-        $error .= ') instead';
101
-        $phpcsFile->addError($error, $stackPtr, $type, $data);
102
-
103
-    }//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_VARIABLE];
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
+		$tokens = $phpcsFile->getTokens();
43
+
44
+		$varName = $tokens[$stackPtr]['content'];
45
+		if ($varName !== '$_REQUEST'
46
+			&& $varName !== '$_GET'
47
+			&& $varName !== '$_POST'
48
+			&& $varName !== '$_FILES'
49
+		) {
50
+			return;
51
+		}
52
+
53
+		// The only place these super globals can be accessed directly is
54
+		// in the getRequestData() method of the Security class.
55
+		$inClass = false;
56
+		foreach ($tokens[$stackPtr]['conditions'] as $i => $type) {
57
+			if ($tokens[$i]['code'] === T_CLASS) {
58
+				$className = $phpcsFile->findNext(T_STRING, $i);
59
+				$className = $tokens[$className]['content'];
60
+				if (strtolower($className) === 'security') {
61
+					$inClass = true;
62
+				} else {
63
+					// We don't have nested classes.
64
+					break;
65
+				}
66
+			} else if ($inClass === true && $tokens[$i]['code'] === T_FUNCTION) {
67
+				$funcName = $phpcsFile->findNext(T_STRING, $i);
68
+				$funcName = $tokens[$funcName]['content'];
69
+				if (strtolower($funcName) === 'getrequestdata') {
70
+					// This is valid.
71
+					return;
72
+				} else {
73
+					// We don't have nested functions.
74
+					break;
75
+				}
76
+			}//end if
77
+		}//end foreach
78
+
79
+		// If we get to here, the super global was used incorrectly.
80
+		// First find out how it is being used.
81
+		$globalName = strtolower(substr($varName, 2));
82
+		$usedVar    = '';
83
+
84
+		$openBracket = $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 1), null, true);
85
+		if ($tokens[$openBracket]['code'] === T_OPEN_SQUARE_BRACKET) {
86
+			$closeBracket = $tokens[$openBracket]['bracket_closer'];
87
+			$usedVar      = $phpcsFile->getTokensAsString(($openBracket + 1), ($closeBracket - $openBracket - 1));
88
+		}
89
+
90
+		$type  = 'SuperglobalAccessed';
91
+		$error = 'The %s super global must not be accessed directly; use Security::getRequestData(';
92
+		$data  = [$varName];
93
+		if ($usedVar !== '') {
94
+			$type  .= 'WithVar';
95
+			$error .= '%s, \'%s\'';
96
+			$data[] = $usedVar;
97
+			$data[] = $globalName;
98
+		}
99
+
100
+		$error .= ') instead';
101
+		$phpcsFile->addError($error, $stackPtr, $type, $data);
102
+
103
+	}//end process()
104 104
 
105 105
 
106 106
 }//end class
Please login to merge, or discard this patch.
php_codesniffer/src/Standards/MySource/Sniffs/Strings/JoinStringsSniff.php 1 patch
Indentation   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -16,61 +16,61 @@
 block discarded – undo
16 16
 class JoinStringsSniff implements Sniff
17 17
 {
18 18
 
19
-    /**
20
-     * A list of tokenizers this sniff supports.
21
-     *
22
-     * @var array
23
-     */
24
-    public $supportedTokenizers = ['JS'];
19
+	/**
20
+	 * A list of tokenizers this sniff supports.
21
+	 *
22
+	 * @var array
23
+	 */
24
+	public $supportedTokenizers = ['JS'];
25 25
 
26 26
 
27
-    /**
28
-     * Returns an array of tokens this test wants to listen for.
29
-     *
30
-     * @return array
31
-     */
32
-    public function register()
33
-    {
34
-        return [T_STRING];
27
+	/**
28
+	 * Returns an array of tokens this test wants to listen for.
29
+	 *
30
+	 * @return array
31
+	 */
32
+	public function register()
33
+	{
34
+		return [T_STRING];
35 35
 
36
-    }//end register()
36
+	}//end register()
37 37
 
38 38
 
39
-    /**
40
-     * Processes this test, when one of its tokens is encountered.
41
-     *
42
-     * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.
43
-     * @param integer                     $stackPtr  The position of the current token
44
-     *                                               in the stack passed in $tokens.
45
-     *
46
-     * @return void
47
-     */
48
-    public function process(File $phpcsFile, $stackPtr)
49
-    {
50
-        $tokens = $phpcsFile->getTokens();
39
+	/**
40
+	 * Processes this test, when one of its tokens is encountered.
41
+	 *
42
+	 * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.
43
+	 * @param integer                     $stackPtr  The position of the current token
44
+	 *                                               in the stack passed in $tokens.
45
+	 *
46
+	 * @return void
47
+	 */
48
+	public function process(File $phpcsFile, $stackPtr)
49
+	{
50
+		$tokens = $phpcsFile->getTokens();
51 51
 
52
-        if ($tokens[$stackPtr]['content'] !== 'join') {
53
-            return;
54
-        }
52
+		if ($tokens[$stackPtr]['content'] !== 'join') {
53
+			return;
54
+		}
55 55
 
56
-        $prev = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($stackPtr - 1), null, true);
57
-        if ($tokens[$prev]['code'] !== T_OBJECT_OPERATOR) {
58
-            return;
59
-        }
56
+		$prev = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($stackPtr - 1), null, true);
57
+		if ($tokens[$prev]['code'] !== T_OBJECT_OPERATOR) {
58
+			return;
59
+		}
60 60
 
61
-        $prev = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($prev - 1), null, true);
62
-        if ($tokens[$prev]['code'] === T_CLOSE_SQUARE_BRACKET) {
63
-            $opener = $tokens[$prev]['bracket_opener'];
64
-            if ($tokens[($opener - 1)]['code'] !== T_STRING) {
65
-                // This means the array is declared inline, like x = [a,b,c].join()
66
-                // and not elsewhere, like x = y[a].join()
67
-                // The first is not allowed while the second is.
68
-                $error = 'Joining strings using inline arrays is not allowed; use the + operator instead';
69
-                $phpcsFile->addError($error, $stackPtr, 'ArrayNotAllowed');
70
-            }
71
-        }
61
+		$prev = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($prev - 1), null, true);
62
+		if ($tokens[$prev]['code'] === T_CLOSE_SQUARE_BRACKET) {
63
+			$opener = $tokens[$prev]['bracket_opener'];
64
+			if ($tokens[($opener - 1)]['code'] !== T_STRING) {
65
+				// This means the array is declared inline, like x = [a,b,c].join()
66
+				// and not elsewhere, like x = y[a].join()
67
+				// The first is not allowed while the second is.
68
+				$error = 'Joining strings using inline arrays is not allowed; use the + operator instead';
69
+				$phpcsFile->addError($error, $stackPtr, 'ArrayNotAllowed');
70
+			}
71
+		}
72 72
 
73
-    }//end process()
73
+	}//end process()
74 74
 
75 75
 
76 76
 }//end class
Please login to merge, or discard this patch.
php_codesniffer/src/Standards/MySource/Sniffs/Debug/DebugCodeSniff.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 [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
-        $tokens = $phpcsFile->getTokens();
43
-
44
-        $className = $phpcsFile->findPrevious(T_WHITESPACE, ($stackPtr - 1), null, true);
45
-        if (strtolower($tokens[$className]['content']) === 'debug') {
46
-            $method = $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 1), null, true);
47
-            $error  = 'Call to debug function Debug::%s() must be removed';
48
-            $data   = [$tokens[$method]['content']];
49
-            $phpcsFile->addError($error, $stackPtr, 'Found', $data);
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 [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
+		$tokens = $phpcsFile->getTokens();
43
+
44
+		$className = $phpcsFile->findPrevious(T_WHITESPACE, ($stackPtr - 1), null, true);
45
+		if (strtolower($tokens[$className]['content']) === 'debug') {
46
+			$method = $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 1), null, true);
47
+			$error  = 'Call to debug function Debug::%s() must be removed';
48
+			$data   = [$tokens[$method]['content']];
49
+			$phpcsFile->addError($error, $stackPtr, 'Found', $data);
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/MySource/Sniffs/Debug/FirebugConsoleSniff.php 1 patch
Indentation   +37 added lines, -37 removed lines patch added patch discarded remove patch
@@ -15,50 +15,50 @@
 block discarded – undo
15 15
 class FirebugConsoleSniff implements Sniff
16 16
 {
17 17
 
18
-    /**
19
-     * A list of tokenizers this sniff supports.
20
-     *
21
-     * @var array
22
-     */
23
-    public $supportedTokenizers = ['JS'];
18
+	/**
19
+	 * A list of tokenizers this sniff supports.
20
+	 *
21
+	 * @var array
22
+	 */
23
+	public $supportedTokenizers = ['JS'];
24 24
 
25 25
 
26
-    /**
27
-     * Returns an array of tokens this test wants to listen for.
28
-     *
29
-     * @return array
30
-     */
31
-    public function register()
32
-    {
33
-        return [
34
-            T_STRING,
35
-            T_PROPERTY,
36
-            T_LABEL,
37
-            T_OBJECT,
38
-        ];
26
+	/**
27
+	 * Returns an array of tokens this test wants to listen for.
28
+	 *
29
+	 * @return array
30
+	 */
31
+	public function register()
32
+	{
33
+		return [
34
+			T_STRING,
35
+			T_PROPERTY,
36
+			T_LABEL,
37
+			T_OBJECT,
38
+		];
39 39
 
40
-    }//end register()
40
+	}//end register()
41 41
 
42 42
 
43
-    /**
44
-     * Processes this test, when one of its tokens is encountered.
45
-     *
46
-     * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.
47
-     * @param int                         $stackPtr  The position of the current token
48
-     *                                               in the stack passed in $tokens.
49
-     *
50
-     * @return void
51
-     */
52
-    public function process(File $phpcsFile, $stackPtr)
53
-    {
54
-        $tokens = $phpcsFile->getTokens();
43
+	/**
44
+	 * Processes this test, when one of its tokens is encountered.
45
+	 *
46
+	 * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.
47
+	 * @param int                         $stackPtr  The position of the current token
48
+	 *                                               in the stack passed in $tokens.
49
+	 *
50
+	 * @return void
51
+	 */
52
+	public function process(File $phpcsFile, $stackPtr)
53
+	{
54
+		$tokens = $phpcsFile->getTokens();
55 55
 
56
-        if (strtolower($tokens[$stackPtr]['content']) === 'console') {
57
-            $error = 'Variables, functions and labels must not be named "console"; name may conflict with Firebug internal variable';
58
-            $phpcsFile->addError($error, $stackPtr, 'ConflictFound');
59
-        }
56
+		if (strtolower($tokens[$stackPtr]['content']) === 'console') {
57
+			$error = 'Variables, functions and labels must not be named "console"; name may conflict with Firebug internal variable';
58
+			$phpcsFile->addError($error, $stackPtr, 'ConflictFound');
59
+		}
60 60
 
61
-    }//end process()
61
+	}//end process()
62 62
 
63 63
 
64 64
 }//end class
Please login to merge, or discard this patch.
src/Standards/MySource/Sniffs/Channels/UnusedSystemSniff.php 2 patches
Indentation   +120 added lines, -120 removed lines patch added patch discarded remove patch
@@ -16,126 +16,126 @@
 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
-        $tokens = $phpcsFile->getTokens();
43
-
44
-        // Check if this is a call to includeSystem, includeAsset or includeWidget.
45
-        $methodName = strtolower($tokens[($stackPtr + 1)]['content']);
46
-        if ($methodName === 'includesystem'
47
-            || $methodName === 'includeasset'
48
-            || $methodName === 'includewidget'
49
-        ) {
50
-            $systemName = $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 3), null, true);
51
-            if ($systemName === false || $tokens[$systemName]['code'] !== T_CONSTANT_ENCAPSED_STRING) {
52
-                // Must be using a variable instead of a specific system name.
53
-                // We can't accurately check that.
54
-                return;
55
-            }
56
-
57
-            $systemName = trim($tokens[$systemName]['content'], " '");
58
-        } else {
59
-            return;
60
-        }
61
-
62
-        if ($methodName === 'includeasset') {
63
-            $systemName .= 'assettype';
64
-        } else if ($methodName === 'includewidget') {
65
-            $systemName .= 'widgettype';
66
-        }
67
-
68
-        $systemName = strtolower($systemName);
69
-
70
-        // Now check if this system is used anywhere in this scope.
71
-        $level = $tokens[$stackPtr]['level'];
72
-        for ($i = ($stackPtr + 1); $i < $phpcsFile->numTokens; $i++) {
73
-            if ($tokens[$i]['level'] < $level) {
74
-                // We have gone out of scope.
75
-                // If the original include was inside an IF statement that
76
-                // is checking if the system exists, check the outer scope
77
-                // as well.
78
-                if ($tokens[$stackPtr]['level'] === $level) {
79
-                    // We are still in the base level, so this is the first
80
-                    // time we have got here.
81
-                    $conditions = array_keys($tokens[$stackPtr]['conditions']);
82
-                    if (empty($conditions) === false) {
83
-                        $cond = array_pop($conditions);
84
-                        if ($tokens[$cond]['code'] === T_IF) {
85
-                            $i = $tokens[$cond]['scope_closer'];
86
-                            $level--;
87
-                            continue;
88
-                        }
89
-                    }
90
-                }
91
-
92
-                break;
93
-            }//end if
94
-
95
-            if ($tokens[$i]['code'] !== T_DOUBLE_COLON
96
-                && $tokens[$i]['code'] !== T_EXTENDS
97
-                && $tokens[$i]['code'] !== T_IMPLEMENTS
98
-            ) {
99
-                continue;
100
-            }
101
-
102
-            switch ($tokens[$i]['code']) {
103
-            case T_DOUBLE_COLON:
104
-                $usedName = strtolower($tokens[($i - 1)]['content']);
105
-                if ($usedName === $systemName) {
106
-                    // The included system was used, so it is fine.
107
-                    return;
108
-                }
109
-                break;
110
-            case T_EXTENDS:
111
-                $classNameToken = $phpcsFile->findNext(T_STRING, ($i + 1));
112
-                $className      = strtolower($tokens[$classNameToken]['content']);
113
-                if ($className === $systemName) {
114
-                    // The included system was used, so it is fine.
115
-                    return;
116
-                }
117
-                break;
118
-            case T_IMPLEMENTS:
119
-                $endImplements = $phpcsFile->findNext([T_EXTENDS, T_OPEN_CURLY_BRACKET], ($i + 1));
120
-                for ($x = ($i + 1); $x < $endImplements; $x++) {
121
-                    if ($tokens[$x]['code'] === T_STRING) {
122
-                        $className = strtolower($tokens[$x]['content']);
123
-                        if ($className === $systemName) {
124
-                            // The included system was used, so it is fine.
125
-                            return;
126
-                        }
127
-                    }
128
-                }
129
-                break;
130
-            }//end switch
131
-        }//end for
132
-
133
-        // If we get to here, the system was not use.
134
-        $error = 'Included system "%s" is never used';
135
-        $data  = [$systemName];
136
-        $phpcsFile->addError($error, $stackPtr, 'Found', $data);
137
-
138
-    }//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_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
+		$tokens = $phpcsFile->getTokens();
43
+
44
+		// Check if this is a call to includeSystem, includeAsset or includeWidget.
45
+		$methodName = strtolower($tokens[($stackPtr + 1)]['content']);
46
+		if ($methodName === 'includesystem'
47
+			|| $methodName === 'includeasset'
48
+			|| $methodName === 'includewidget'
49
+		) {
50
+			$systemName = $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 3), null, true);
51
+			if ($systemName === false || $tokens[$systemName]['code'] !== T_CONSTANT_ENCAPSED_STRING) {
52
+				// Must be using a variable instead of a specific system name.
53
+				// We can't accurately check that.
54
+				return;
55
+			}
56
+
57
+			$systemName = trim($tokens[$systemName]['content'], " '");
58
+		} else {
59
+			return;
60
+		}
61
+
62
+		if ($methodName === 'includeasset') {
63
+			$systemName .= 'assettype';
64
+		} else if ($methodName === 'includewidget') {
65
+			$systemName .= 'widgettype';
66
+		}
67
+
68
+		$systemName = strtolower($systemName);
69
+
70
+		// Now check if this system is used anywhere in this scope.
71
+		$level = $tokens[$stackPtr]['level'];
72
+		for ($i = ($stackPtr + 1); $i < $phpcsFile->numTokens; $i++) {
73
+			if ($tokens[$i]['level'] < $level) {
74
+				// We have gone out of scope.
75
+				// If the original include was inside an IF statement that
76
+				// is checking if the system exists, check the outer scope
77
+				// as well.
78
+				if ($tokens[$stackPtr]['level'] === $level) {
79
+					// We are still in the base level, so this is the first
80
+					// time we have got here.
81
+					$conditions = array_keys($tokens[$stackPtr]['conditions']);
82
+					if (empty($conditions) === false) {
83
+						$cond = array_pop($conditions);
84
+						if ($tokens[$cond]['code'] === T_IF) {
85
+							$i = $tokens[$cond]['scope_closer'];
86
+							$level--;
87
+							continue;
88
+						}
89
+					}
90
+				}
91
+
92
+				break;
93
+			}//end if
94
+
95
+			if ($tokens[$i]['code'] !== T_DOUBLE_COLON
96
+				&& $tokens[$i]['code'] !== T_EXTENDS
97
+				&& $tokens[$i]['code'] !== T_IMPLEMENTS
98
+			) {
99
+				continue;
100
+			}
101
+
102
+			switch ($tokens[$i]['code']) {
103
+			case T_DOUBLE_COLON:
104
+				$usedName = strtolower($tokens[($i - 1)]['content']);
105
+				if ($usedName === $systemName) {
106
+					// The included system was used, so it is fine.
107
+					return;
108
+				}
109
+				break;
110
+			case T_EXTENDS:
111
+				$classNameToken = $phpcsFile->findNext(T_STRING, ($i + 1));
112
+				$className      = strtolower($tokens[$classNameToken]['content']);
113
+				if ($className === $systemName) {
114
+					// The included system was used, so it is fine.
115
+					return;
116
+				}
117
+				break;
118
+			case T_IMPLEMENTS:
119
+				$endImplements = $phpcsFile->findNext([T_EXTENDS, T_OPEN_CURLY_BRACKET], ($i + 1));
120
+				for ($x = ($i + 1); $x < $endImplements; $x++) {
121
+					if ($tokens[$x]['code'] === T_STRING) {
122
+						$className = strtolower($tokens[$x]['content']);
123
+						if ($className === $systemName) {
124
+							// The included system was used, so it is fine.
125
+							return;
126
+						}
127
+					}
128
+				}
129
+				break;
130
+			}//end switch
131
+		}//end for
132
+
133
+		// If we get to here, the system was not use.
134
+		$error = 'Included system "%s" is never used';
135
+		$data  = [$systemName];
136
+		$phpcsFile->addError($error, $stackPtr, 'Found', $data);
137
+
138
+	}//end process()
139 139
 
140 140
 
141 141
 }//end class
Please login to merge, or discard this patch.
Switch Indentation   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -100,33 +100,33 @@
 block discarded – undo
100 100
             }
101 101
 
102 102
             switch ($tokens[$i]['code']) {
103
-            case T_DOUBLE_COLON:
104
-                $usedName = strtolower($tokens[($i - 1)]['content']);
105
-                if ($usedName === $systemName) {
106
-                    // The included system was used, so it is fine.
107
-                    return;
108
-                }
109
-                break;
110
-            case T_EXTENDS:
111
-                $classNameToken = $phpcsFile->findNext(T_STRING, ($i + 1));
112
-                $className      = strtolower($tokens[$classNameToken]['content']);
113
-                if ($className === $systemName) {
114
-                    // The included system was used, so it is fine.
115
-                    return;
116
-                }
117
-                break;
118
-            case T_IMPLEMENTS:
119
-                $endImplements = $phpcsFile->findNext([T_EXTENDS, T_OPEN_CURLY_BRACKET], ($i + 1));
120
-                for ($x = ($i + 1); $x < $endImplements; $x++) {
121
-                    if ($tokens[$x]['code'] === T_STRING) {
122
-                        $className = strtolower($tokens[$x]['content']);
123
-                        if ($className === $systemName) {
124
-                            // The included system was used, so it is fine.
125
-                            return;
126
-                        }
127
-                    }
128
-                }
129
-                break;
103
+            	case T_DOUBLE_COLON:
104
+                	$usedName = strtolower($tokens[($i - 1)]['content']);
105
+                	if ($usedName === $systemName) {
106
+                    	// The included system was used, so it is fine.
107
+                    	return;
108
+                	}
109
+                	break;
110
+            	case T_EXTENDS:
111
+                	$classNameToken = $phpcsFile->findNext(T_STRING, ($i + 1));
112
+                	$className      = strtolower($tokens[$classNameToken]['content']);
113
+                	if ($className === $systemName) {
114
+                    	// The included system was used, so it is fine.
115
+                    	return;
116
+                	}
117
+                	break;
118
+            	case T_IMPLEMENTS:
119
+                	$endImplements = $phpcsFile->findNext([T_EXTENDS, T_OPEN_CURLY_BRACKET], ($i + 1));
120
+                	for ($x = ($i + 1); $x < $endImplements; $x++) {
121
+                    	if ($tokens[$x]['code'] === T_STRING) {
122
+                        	$className = strtolower($tokens[$x]['content']);
123
+                        	if ($className === $systemName) {
124
+                            	// The included system was used, so it is fine.
125
+                            	return;
126
+                        	}
127
+                    	}
128
+                	}
129
+                	break;
130 130
             }//end switch
131 131
         }//end for
132 132
 
Please login to merge, or discard this patch.
src/Standards/MySource/Sniffs/Channels/IncludeOwnSystemSniff.php 2 patches
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.
php_codesniffer/src/Standards/MySource/Sniffs/Objects/AssignThisSniff.php 1 patch
Indentation   +61 added lines, -61 removed lines patch added patch discarded remove patch
@@ -15,67 +15,67 @@
 block discarded – undo
15 15
 class AssignThisSniff implements Sniff
16 16
 {
17 17
 
18
-    /**
19
-     * A list of tokenizers this sniff supports.
20
-     *
21
-     * @var array
22
-     */
23
-    public $supportedTokenizers = ['JS'];
24
-
25
-
26
-    /**
27
-     * Returns an array of tokens this test wants to listen for.
28
-     *
29
-     * @return array
30
-     */
31
-    public function register()
32
-    {
33
-        return [T_THIS];
34
-
35
-    }//end register()
36
-
37
-
38
-    /**
39
-     * Processes this test, when one of its tokens is encountered.
40
-     *
41
-     * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.
42
-     * @param int                         $stackPtr  The position of the current token
43
-     *                                               in the stack passed in $tokens.
44
-     *
45
-     * @return void
46
-     */
47
-    public function process(File $phpcsFile, $stackPtr)
48
-    {
49
-        $tokens = $phpcsFile->getTokens();
50
-
51
-        // Ignore this.something and other uses of "this" that are not
52
-        // direct assignments.
53
-        $next = $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 1), null, true);
54
-        if ($tokens[$next]['code'] !== T_SEMICOLON) {
55
-            if ($tokens[$next]['line'] === $tokens[$stackPtr]['line']) {
56
-                return;
57
-            }
58
-        }
59
-
60
-        // Something must be assigned to "this".
61
-        $prev = $phpcsFile->findPrevious(T_WHITESPACE, ($stackPtr - 1), null, true);
62
-        if ($tokens[$prev]['code'] !== T_EQUAL) {
63
-            return;
64
-        }
65
-
66
-        // A variable needs to be assigned to "this".
67
-        $prev = $phpcsFile->findPrevious(T_WHITESPACE, ($prev - 1), null, true);
68
-        if ($tokens[$prev]['code'] !== T_STRING) {
69
-            return;
70
-        }
71
-
72
-        // We can only assign "this" to a var called "self".
73
-        if ($tokens[$prev]['content'] !== 'self' && $tokens[$prev]['content'] !== '_self') {
74
-            $error = 'Keyword "this" can only be assigned to a variable called "self" or "_self"';
75
-            $phpcsFile->addError($error, $prev, 'NotSelf');
76
-        }
77
-
78
-    }//end process()
18
+	/**
19
+	 * A list of tokenizers this sniff supports.
20
+	 *
21
+	 * @var array
22
+	 */
23
+	public $supportedTokenizers = ['JS'];
24
+
25
+
26
+	/**
27
+	 * Returns an array of tokens this test wants to listen for.
28
+	 *
29
+	 * @return array
30
+	 */
31
+	public function register()
32
+	{
33
+		return [T_THIS];
34
+
35
+	}//end register()
36
+
37
+
38
+	/**
39
+	 * Processes this test, when one of its tokens is encountered.
40
+	 *
41
+	 * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.
42
+	 * @param int                         $stackPtr  The position of the current token
43
+	 *                                               in the stack passed in $tokens.
44
+	 *
45
+	 * @return void
46
+	 */
47
+	public function process(File $phpcsFile, $stackPtr)
48
+	{
49
+		$tokens = $phpcsFile->getTokens();
50
+
51
+		// Ignore this.something and other uses of "this" that are not
52
+		// direct assignments.
53
+		$next = $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 1), null, true);
54
+		if ($tokens[$next]['code'] !== T_SEMICOLON) {
55
+			if ($tokens[$next]['line'] === $tokens[$stackPtr]['line']) {
56
+				return;
57
+			}
58
+		}
59
+
60
+		// Something must be assigned to "this".
61
+		$prev = $phpcsFile->findPrevious(T_WHITESPACE, ($stackPtr - 1), null, true);
62
+		if ($tokens[$prev]['code'] !== T_EQUAL) {
63
+			return;
64
+		}
65
+
66
+		// A variable needs to be assigned to "this".
67
+		$prev = $phpcsFile->findPrevious(T_WHITESPACE, ($prev - 1), null, true);
68
+		if ($tokens[$prev]['code'] !== T_STRING) {
69
+			return;
70
+		}
71
+
72
+		// We can only assign "this" to a var called "self".
73
+		if ($tokens[$prev]['content'] !== 'self' && $tokens[$prev]['content'] !== '_self') {
74
+			$error = 'Keyword "this" can only be assigned to a variable called "self" or "_self"';
75
+			$phpcsFile->addError($error, $prev, 'NotSelf');
76
+		}
77
+
78
+	}//end process()
79 79
 
80 80
 
81 81
 }//end class
Please login to merge, or discard this patch.
src/Standards/MySource/Sniffs/Objects/DisallowNewWidgetSniff.php 1 patch
Indentation   +38 added lines, -38 removed lines patch added patch discarded remove patch
@@ -16,44 +16,44 @@
 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_NEW];
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
-        $tokens = $phpcsFile->getTokens();
43
-
44
-        $className = $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 1), null, true);
45
-        if ($tokens[$className]['code'] !== T_STRING) {
46
-            return;
47
-        }
48
-
49
-        if (substr(strtolower($tokens[$className]['content']), -10) === 'widgettype') {
50
-            $widgetType = substr($tokens[$className]['content'], 0, -10);
51
-            $error      = 'Manual creation of widget objects is banned; use Widget::getWidget(\'%s\'); instead';
52
-            $data       = [$widgetType];
53
-            $phpcsFile->addError($error, $stackPtr, 'Found', $data);
54
-        }
55
-
56
-    }//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_NEW];
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
+		$tokens = $phpcsFile->getTokens();
43
+
44
+		$className = $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 1), null, true);
45
+		if ($tokens[$className]['code'] !== T_STRING) {
46
+			return;
47
+		}
48
+
49
+		if (substr(strtolower($tokens[$className]['content']), -10) === 'widgettype') {
50
+			$widgetType = substr($tokens[$className]['content'], 0, -10);
51
+			$error      = 'Manual creation of widget objects is banned; use Widget::getWidget(\'%s\'); instead';
52
+			$data       = [$widgetType];
53
+			$phpcsFile->addError($error, $stackPtr, 'Found', $data);
54
+		}
55
+
56
+	}//end process()
57 57
 
58 58
 
59 59
 }//end class
Please login to merge, or discard this patch.