-
Notifications
You must be signed in to change notification settings - Fork 81
Expand file tree
/
Copy pathTypeJuggleSniff.php
More file actions
38 lines (31 loc) · 1015 Bytes
/
TypeJuggleSniff.php
File metadata and controls
38 lines (31 loc) · 1015 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<?php
namespace PHPCS_SecurityAudit\Security\Sniffs\Misc;
use PHP_CodeSniffer\Sniffs\Sniff;
use PHP_CodeSniffer\Files\File;
class TypeJuggleSniff implements Sniff {
/**
* Returns the token types that this sniff is interested in.
*
* @return array(int)
*/
public function register() {
return array(T_IS_EQUAL, T_IS_NOT_EQUAL);
}
/**
* Processes the tokens that this sniff is interested in.
*
* @param File $phpcsFile The file where the token was found.
* @param int $stackPtr The position in the stack where
* the token was found.
*
* @return void
*/
public function process(File $phpcsFile, $stackPtr) {
if (\PHP_CodeSniffer\Config::getConfigData('ParanoiaMode')) {
$tokens = $phpcsFile->getTokens();
$warning = 'You are using the comparison operator "%s" that converts type and may cause unintended results.';
$phpcsFile->addWarning($warning, $stackPtr, 'TypeJuggle', array($tokens[$stackPtr]['content']));
}
}
}
?>