Completed
Push — renovate/css-loader-5.x ( b1ade2...04695b )
by
unknown
23:16 queued 14:14
created

MasterUserConstantSniff::process()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 2
dl 0
loc 13
rs 9.8333
c 0
b 0
f 0
1
<?php // phpcs:ignore WordPress.Files.FileName.NotHyphenatedLowercase
2
3
namespace Automattic\Jetpack\Sniffs\Constants;
4
5
use PHP_CodeSniffer\Files\File;
6
use PHP_CodeSniffer\Sniffs\Sniff;
7
use PHP_CodeSniffer\Util\Tokens;
8
9
/**
10
 * Sniffer that looks for JETPACK_MASTER_USER constant usage
11
 */
12
class MasterUserConstantSniff implements Sniff {
13
	/**
14
	 * Returns the token types that this sniff is interested in.
15
	 *
16
	 * @return array(int)
0 ignored issues
show
Documentation introduced by
The doc-type array(int) could not be parsed: Expected "|" or "end of type", but got "(" at position 5. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
17
	 */
18
	public function register() {
19
		return array( T_STRING );
20
	}
21
22
23
	/**
24
	 * Processes the tokens that this sniff is interested in.
25
	 *
26
	 * @param File $phpcs_file The file where the token was found.
27
	 * @param int  $stack_ptr The position in the stack where the token was found.
28
	 */
29
	public function process( File $phpcs_file, $stack_ptr ) {
30
31
		$tokens = $phpcs_file->getTokens();
32
33
		if ( 'JETPACK_MASTER_USER' === $tokens[ $stack_ptr ]['content'] ) {
34
			$phpcs_file->addWarning(
35
				'JETPACK_MASTER_USER constant should not be used. Use the blog token to make requests instead, or use the current user token when needed.',
36
				$stack_ptr,
37
				'ShouldNotBeUsed'
38
			);
39
		}
40
41
	}
42
43
}
44