|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* PHPCompatibility_Sniffs_PHP_DeprecatedNewReferenceSniff. |
|
4
|
|
|
* |
|
5
|
|
|
* PHP version 5.4 |
|
6
|
|
|
* |
|
7
|
|
|
* @category PHP |
|
8
|
|
|
* @package PHPCompatibility |
|
9
|
|
|
* @author Wim Godden <[email protected]> |
|
10
|
|
|
* @copyright 2012 Cu.be Solutions bvba |
|
11
|
|
|
*/ |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* PHPCompatibility_Sniffs_PHP_DeprecatedNewReferenceSniff. |
|
15
|
|
|
* |
|
16
|
|
|
* Discourages the use of assigning the return value of new by reference |
|
17
|
|
|
* |
|
18
|
|
|
* PHP version 5.4 |
|
19
|
|
|
* |
|
20
|
|
|
* @category PHP |
|
21
|
|
|
* @package PHPCompatibility |
|
22
|
|
|
* @author Wim Godden <[email protected]> |
|
23
|
|
|
* @copyright 2012 Cu.be Solutions bvba |
|
24
|
|
|
*/ |
|
25
|
|
|
class PHPCompatibility_Sniffs_PHP_DeprecatedNewReferenceSniff extends PHPCompatibility_Sniff |
|
26
|
|
|
{ |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* If true, an error will be thrown; otherwise a warning. |
|
30
|
|
|
* |
|
31
|
|
|
* @var bool |
|
32
|
|
|
*/ |
|
33
|
|
|
protected $error = false; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* Returns an array of tokens this test wants to listen for. |
|
37
|
|
|
* |
|
38
|
|
|
* @return array |
|
39
|
|
|
*/ |
|
40
|
|
|
public function register() |
|
41
|
|
|
{ |
|
42
|
|
|
return array(T_NEW); |
|
43
|
|
|
|
|
44
|
|
|
}//end register() |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* Processes this test, when one of its tokens is encountered. |
|
48
|
|
|
* |
|
49
|
|
|
* @param PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
50
|
|
|
* @param int $stackPtr The position of the current token in the |
|
51
|
|
|
* stack passed in $tokens. |
|
52
|
|
|
* |
|
53
|
|
|
* @return void |
|
54
|
|
|
*/ |
|
55
|
|
|
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) |
|
56
|
|
|
{ |
|
57
|
|
|
if ($this->supportsAbove('5.3')) { |
|
58
|
|
|
$tokens = $phpcsFile->getTokens(); |
|
59
|
|
|
if ($tokens[$stackPtr - 1]['type'] == 'T_BITWISE_AND' || $tokens[$stackPtr - 2]['type'] == 'T_BITWISE_AND') { |
|
60
|
|
|
if ($this->supportsAbove('7.0')) { |
|
61
|
|
|
$error = 'Assigning the return value of new by reference is deprecated in PHP 5.3 and forbidden in PHP 7.0'; |
|
62
|
|
|
$phpcsFile->addError($error, $stackPtr); |
|
63
|
|
|
} else { |
|
64
|
|
|
$error = 'Assigning the return value of new by reference is deprecated in PHP 5.3'; |
|
65
|
|
|
$phpcsFile->addWarning($error, $stackPtr); |
|
66
|
|
|
} |
|
67
|
|
|
} |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
}//end process() |
|
71
|
|
|
|
|
72
|
|
|
}//end class |
|
73
|
|
|
|