Completed
Push — try/jetpack-stories-block-mobi... ( 5d409e...2fea66 )
by
unknown
116:16 queued 106:28
created

MasterUserConstantSniff   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 1
dl 0
loc 31
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A register() 0 3 1
A process() 0 13 2
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
8
/**
9
 * Sniffer that looks for JETPACK_MASTER_USER constant usage
10
 */
11
class MasterUserConstantSniff implements Sniff {
12
	/**
13
	 * Returns the token types that this sniff is interested in.
14
	 *
15
	 * @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...
16
	 */
17
	public function register() {
18
		return array( T_STRING );
19
	}
20
21
	/**
22
	 * Processes the tokens that this sniff is interested in.
23
	 *
24
	 * @param File $phpcs_file The file where the token was found.
25
	 * @param int  $stack_ptr The position in the stack where the token was found.
26
	 */
27
	public function process( File $phpcs_file, $stack_ptr ) {
28
29
		$tokens = $phpcs_file->getTokens();
30
31
		if ( 'JETPACK_MASTER_USER' === $tokens[ $stack_ptr ]['content'] ) {
32
			$phpcs_file->addWarning(
33
				'JETPACK_MASTER_USER constant should not be used. Use the blog token to make requests instead, or use the current user token when needed.',
34
				$stack_ptr,
35
				'ShouldNotBeUsed'
36
			);
37
		}
38
39
	}
40
41
}
42