-
Notifications
You must be signed in to change notification settings - Fork 53
Expand file tree
/
Copy pathWaitForTextSniff.php
More file actions
83 lines (69 loc) · 2.4 KB
/
WaitForTextSniff.php
File metadata and controls
83 lines (69 loc) · 2.4 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<?php
/**
* \DrupalPractice\Sniffs\FunctionCalls\WaitForText
*
* @category PHP
* @package PHP_CodeSniffer
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
namespace DrupalPractice\Sniffs\FunctionCalls;
use PHP_CodeSniffer\Files\File;
use Drupal\Sniffs\Semantics\FunctionCall;
/**
* Check that waitForText return values are always handled.
*
* @category PHP
* @package PHP_CodeSniffer
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class WaitForTextSniff extends FunctionCall
{
/**
* Whether method invocations with the same function name should be processed,
* too.
*
* @var boolean
*/
protected $includeMethodCalls = true;
/**
* Returns an array of function names this test wants to listen for.
*
* @return array<string>
*/
public function registerFunctionNames()
{
return ['waitForText'];
}//end registerFunctionNames()
/**
* Processes this function call.
*
* @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.
* @param int $stackPtr The position of the function call in
* the stack.
* @param int $openBracket The position of the opening
* parenthesis in the stack.
* @param int $closeBracket The position of the closing
* parenthesis in the stack.
*
* @return void|int
*/
public function processFunctionCall(
File $phpcsFile,
$stackPtr,
$openBracket,
$closeBracket
) {
$tokens = $phpcsFile->getTokens();
$start = $phpcsFile->findStartOfStatement($stackPtr);
$end = $phpcsFile->findEndOfStatement($start);
// We are assigning to a variable, all is well.
if ($tokens[$start]['code'] === T_VARIABLE && $phpcsFile->findNext(T_EQUAL, $start, $end) !== false) {
return;
}
$function = ($start - 2);
if ($tokens[$function]['content'] === 'assertTrue' || $tokens[$function]['content'] === 'assertFalse') {
return;
}
$phpcsFile->addWarning('waitForText functions do not self assert and must be asserted manually', $start, 'WaitForText');
}//end processFunctionCall()
}//end class