This repository has been archived by the owner on Mar 31, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDeprecatedNewReferenceSniff.php
68 lines (58 loc) · 1.72 KB
/
DeprecatedNewReferenceSniff.php
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
<?php
/**
* PHP53Compatibility_Sniffs_PHP_DeprecatedNewReferenceSniff.
*
* PHP version 5.3
*
* @category PHP
* @package PHP53Compatibility
* @author Wim Godden <wim.godden@cu.be>
* @copyright 2010 Cu.be Solutions bvba
*/
/**
* PHP53Compatibility_Sniffs_PHP_DeprecatedNewReferenceSniff.
*
* Discourages the use of assigning the return value of new by reference
*
* PHP version 5.3
*
* @category PHP
* @package PHP53Compatibility
* @author Wim Godden <wim.godden@cu.be>
* @copyright 2010 Cu.be Solutions bvba
*/
class PHP53Compatibility_Sniffs_PHP_DeprecatedNewReferenceSniff implements PHP_CodeSniffer_Sniff
{
/**
* If true, an error will be thrown; otherwise a warning.
*
* @var bool
*/
protected $error = true;
/**
* Returns an array of tokens this test wants to listen for.
*
* @return array
*/
public function register()
{
return array(T_NEW);
}//end register()
/**
* Processes this test, when one of its tokens is encountered.
*
* @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
* @param int $stackPtr The position of the current token in the
* stack passed in $tokens.
*
* @return void
*/
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
{
$tokens = $phpcsFile->getTokens();
if ($tokens[$stackPtr - 1]['type'] == 'T_BITWISE_AND' || $tokens[$stackPtr - 2]['type'] == 'T_BITWISE_AND') {
$error = '[PHP 5.3] Assigning the return value of new by reference is deprecated in PHP 5.3';
$phpcsFile->addError($error, $stackPtr);
}
}//end process()
}//end class