Conditions | 5 |
Paths | 5 |
Total Lines | 27 |
Code Lines | 15 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
26 | public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) { |
||
27 | $tokens = $phpcsFile->getTokens(); |
||
28 | |||
29 | $class = $tokens[$stackPtr]; |
||
30 | |||
31 | if(!IsSet($class['scope_closer'])) { |
||
32 | return; |
||
33 | } |
||
34 | |||
35 | $scopeCloser = $class['scope_closer']; |
||
36 | |||
37 | //get the name of the class |
||
38 | $classNamePos = $phpcsFile->findNext(T_STRING, $stackPtr); |
||
39 | $className = $tokens[$classNamePos]['content']; |
||
40 | |||
41 | $nextFunc = $stackPtr; |
||
42 | while (($nextFunc = $phpcsFile->findNext(T_FUNCTION, ($nextFunc + 1), $scopeCloser)) !== false) { |
||
43 | $fundNamePos = $phpcsFile->findNext(T_STRING, $nextFunc); |
||
44 | |||
45 | if ($this->supportsAbove('7.0')) { |
||
46 | if ($tokens[$fundNamePos]['content'] === $className) { |
||
47 | $phpcsFile->addError('Deprecated PHP4 style constructor are not supported since PHP7', |
||
48 | $fundNamePos); |
||
|
|||
49 | } |
||
50 | } |
||
51 | } |
||
52 | } |
||
53 | } |
||
54 |
This check looks for type mismatches where the missing type is
false
. This is usually indicative of an error condtion.Consider the follow example
This function either returns a new
DateTime
object or false, if there was an error. This is a typical pattern in PHP programming to show that an error has occurred without raising an exception. The calling code should check for this returnedfalse
before passing on the value to another function or method that may not be able to handle afalse
.