Completed
Pull Request — develop (#1492)
by Zack
15:57
created
PHPCompatibility/Sniffs/MethodUse/ForbiddenToStringParametersSniff.php 1 patch
Indentation   +57 added lines, -57 removed lines patch added patch discarded remove patch
@@ -28,43 +28,43 @@  discard block
 block discarded – undo
28 28
 class ForbiddenToStringParametersSniff extends Sniff
29 29
 {
30 30
 
31
-    /**
32
-     * Returns an array of tokens this test wants to listen for.
33
-     *
34
-     * @since 9.2.0
35
-     *
36
-     * @return array
37
-     */
38
-    public function register()
39
-    {
40
-        return array(
41
-            \T_DOUBLE_COLON,
42
-            \T_OBJECT_OPERATOR,
43
-        );
44
-    }
31
+	/**
32
+	 * Returns an array of tokens this test wants to listen for.
33
+	 *
34
+	 * @since 9.2.0
35
+	 *
36
+	 * @return array
37
+	 */
38
+	public function register()
39
+	{
40
+		return array(
41
+			\T_DOUBLE_COLON,
42
+			\T_OBJECT_OPERATOR,
43
+		);
44
+	}
45 45
 
46
-    /**
47
-     * Processes this test, when one of its tokens is encountered.
48
-     *
49
-     * @since 9.2.0
50
-     *
51
-     * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned.
52
-     * @param int                   $stackPtr  The position of the current token
53
-     *                                         in the stack passed in $tokens.
54
-     *
55
-     * @return void
56
-     */
57
-    public function process(File $phpcsFile, $stackPtr)
58
-    {
59
-        if ($this->supportsAbove('5.3') === false) {
60
-            return;
61
-        }
46
+	/**
47
+	 * Processes this test, when one of its tokens is encountered.
48
+	 *
49
+	 * @since 9.2.0
50
+	 *
51
+	 * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned.
52
+	 * @param int                   $stackPtr  The position of the current token
53
+	 *                                         in the stack passed in $tokens.
54
+	 *
55
+	 * @return void
56
+	 */
57
+	public function process(File $phpcsFile, $stackPtr)
58
+	{
59
+		if ($this->supportsAbove('5.3') === false) {
60
+			return;
61
+		}
62 62
 
63
-        $tokens = $phpcsFile->getTokens();
63
+		$tokens = $phpcsFile->getTokens();
64 64
 
65
-        $nextNonEmpty = $phpcsFile->findNext(Tokens::$emptyTokens, ($stackPtr + 1), null, true);
66
-        if ($nextNonEmpty === false || $tokens[$nextNonEmpty]['code'] !== \T_STRING) {
67
-            /*
65
+		$nextNonEmpty = $phpcsFile->findNext(Tokens::$emptyTokens, ($stackPtr + 1), null, true);
66
+		if ($nextNonEmpty === false || $tokens[$nextNonEmpty]['code'] !== \T_STRING) {
67
+			/*
68 68
              * Not a method call.
69 69
              *
70 70
              * Note: This disregards method calls with the method name in a variable, like:
@@ -72,31 +72,31 @@  discard block
 block discarded – undo
72 72
              *   $obj->$method();
73 73
              * However, that would be very hard to examine reliably anyway.
74 74
              */
75
-            return;
76
-        }
75
+			return;
76
+		}
77 77
 
78
-        if (strtolower($tokens[$nextNonEmpty]['content']) !== '__tostring') {
79
-            // Not a call to the __clone() method.
80
-            return;
81
-        }
78
+		if (strtolower($tokens[$nextNonEmpty]['content']) !== '__tostring') {
79
+			// Not a call to the __clone() method.
80
+			return;
81
+		}
82 82
 
83
-        $openParens = $phpcsFile->findNext(Tokens::$emptyTokens, ($nextNonEmpty + 1), null, true);
84
-        if ($openParens === false || $tokens[$openParens]['code'] !== \T_OPEN_PARENTHESIS) {
85
-            // Not a method call.
86
-            return;
87
-        }
83
+		$openParens = $phpcsFile->findNext(Tokens::$emptyTokens, ($nextNonEmpty + 1), null, true);
84
+		if ($openParens === false || $tokens[$openParens]['code'] !== \T_OPEN_PARENTHESIS) {
85
+			// Not a method call.
86
+			return;
87
+		}
88 88
 
89
-        $closeParens = $phpcsFile->findNext(Tokens::$emptyTokens, ($openParens + 1), null, true);
90
-        if ($closeParens === false || $tokens[$closeParens]['code'] === \T_CLOSE_PARENTHESIS) {
91
-            // Not a method call.
92
-            return;
93
-        }
89
+		$closeParens = $phpcsFile->findNext(Tokens::$emptyTokens, ($openParens + 1), null, true);
90
+		if ($closeParens === false || $tokens[$closeParens]['code'] === \T_CLOSE_PARENTHESIS) {
91
+			// Not a method call.
92
+			return;
93
+		}
94 94
 
95
-        // If we're still here, then this is a call to the __toString() magic method passing parameters.
96
-        $phpcsFile->addError(
97
-            'The __toString() magic method will no longer accept passed arguments since PHP 5.3',
98
-            $stackPtr,
99
-            'Passed'
100
-        );
101
-    }
95
+		// If we're still here, then this is a call to the __toString() magic method passing parameters.
96
+		$phpcsFile->addError(
97
+			'The __toString() magic method will no longer accept passed arguments since PHP 5.3',
98
+			$stackPtr,
99
+			'Passed'
100
+		);
101
+	}
102 102
 }
Please login to merge, or discard this patch.
PHPCompatibility/Sniffs/MethodUse/NewDirectCallsToCloneSniff.php 1 patch
Indentation   +51 added lines, -51 removed lines patch added patch discarded remove patch
@@ -30,43 +30,43 @@  discard block
 block discarded – undo
30 30
 class NewDirectCallsToCloneSniff extends Sniff
31 31
 {
32 32
 
33
-    /**
34
-     * Returns an array of tokens this test wants to listen for.
35
-     *
36
-     * @since 9.1.0
37
-     *
38
-     * @return array
39
-     */
40
-    public function register()
41
-    {
42
-        return array(
43
-            \T_DOUBLE_COLON,
44
-            \T_OBJECT_OPERATOR,
45
-        );
46
-    }
33
+	/**
34
+	 * Returns an array of tokens this test wants to listen for.
35
+	 *
36
+	 * @since 9.1.0
37
+	 *
38
+	 * @return array
39
+	 */
40
+	public function register()
41
+	{
42
+		return array(
43
+			\T_DOUBLE_COLON,
44
+			\T_OBJECT_OPERATOR,
45
+		);
46
+	}
47 47
 
48
-    /**
49
-     * Processes this test, when one of its tokens is encountered.
50
-     *
51
-     * @since 9.1.0
52
-     *
53
-     * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned.
54
-     * @param int                   $stackPtr  The position of the current token in
55
-     *                                         the stack passed in $tokens.
56
-     *
57
-     * @return void
58
-     */
59
-    public function process(File $phpcsFile, $stackPtr)
60
-    {
61
-        if ($this->supportsBelow('5.6') === false) {
62
-            return;
63
-        }
48
+	/**
49
+	 * Processes this test, when one of its tokens is encountered.
50
+	 *
51
+	 * @since 9.1.0
52
+	 *
53
+	 * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned.
54
+	 * @param int                   $stackPtr  The position of the current token in
55
+	 *                                         the stack passed in $tokens.
56
+	 *
57
+	 * @return void
58
+	 */
59
+	public function process(File $phpcsFile, $stackPtr)
60
+	{
61
+		if ($this->supportsBelow('5.6') === false) {
62
+			return;
63
+		}
64 64
 
65
-        $tokens = $phpcsFile->getTokens();
65
+		$tokens = $phpcsFile->getTokens();
66 66
 
67
-        $nextNonEmpty = $phpcsFile->findNext(Tokens::$emptyTokens, ($stackPtr + 1), null, true);
68
-        if ($nextNonEmpty === false || $tokens[$nextNonEmpty]['code'] !== \T_STRING) {
69
-            /*
67
+		$nextNonEmpty = $phpcsFile->findNext(Tokens::$emptyTokens, ($stackPtr + 1), null, true);
68
+		if ($nextNonEmpty === false || $tokens[$nextNonEmpty]['code'] !== \T_STRING) {
69
+			/*
70 70
              * Not a method call.
71 71
              *
72 72
              * Note: This disregards method calls with the method name in a variable, like:
@@ -74,24 +74,24 @@  discard block
 block discarded – undo
74 74
              *   $obj->$method();
75 75
              * However, that would be very hard to examine reliably anyway.
76 76
              */
77
-            return;
78
-        }
77
+			return;
78
+		}
79 79
 
80
-        if (strtolower($tokens[$nextNonEmpty]['content']) !== '__clone') {
81
-            // Not a call to the __clone() method.
82
-            return;
83
-        }
80
+		if (strtolower($tokens[$nextNonEmpty]['content']) !== '__clone') {
81
+			// Not a call to the __clone() method.
82
+			return;
83
+		}
84 84
 
85
-        $nextNextNonEmpty = $phpcsFile->findNext(Tokens::$emptyTokens, ($nextNonEmpty + 1), null, true);
86
-        if ($nextNextNonEmpty === false || $tokens[$nextNextNonEmpty]['code'] !== \T_OPEN_PARENTHESIS) {
87
-            // Not a method call.
88
-            return;
89
-        }
85
+		$nextNextNonEmpty = $phpcsFile->findNext(Tokens::$emptyTokens, ($nextNonEmpty + 1), null, true);
86
+		if ($nextNextNonEmpty === false || $tokens[$nextNextNonEmpty]['code'] !== \T_OPEN_PARENTHESIS) {
87
+			// Not a method call.
88
+			return;
89
+		}
90 90
 
91
-        $phpcsFile->addError(
92
-            'Direct calls to the __clone() magic method are not allowed in PHP 5.6 or earlier.',
93
-            $nextNonEmpty,
94
-            'Found'
95
-        );
96
-    }
91
+		$phpcsFile->addError(
92
+			'Direct calls to the __clone() magic method are not allowed in PHP 5.6 or earlier.',
93
+			$nextNonEmpty,
94
+			'Found'
95
+		);
96
+	}
97 97
 }
Please login to merge, or discard this patch.
Sniffs/FunctionNameRestrictions/RemovedMagicAutoloadSniff.php 1 patch
Indentation   +47 added lines, -47 removed lines patch added patch discarded remove patch
@@ -23,58 +23,58 @@
 block discarded – undo
23 23
  */
24 24
 class RemovedMagicAutoloadSniff extends Sniff
25 25
 {
26
-    /**
27
-     * Scopes to look for when testing using validDirectScope
28
-     *
29
-     * @var array
30
-     */
31
-    private $checkForScopes = array(
32
-        'T_CLASS'      => true,
33
-        'T_ANON_CLASS' => true,
34
-        'T_INTERFACE'  => true,
35
-        'T_TRAIT'      => true,
36
-        'T_NAMESPACE'  => true,
37
-    );
26
+	/**
27
+	 * Scopes to look for when testing using validDirectScope
28
+	 *
29
+	 * @var array
30
+	 */
31
+	private $checkForScopes = array(
32
+		'T_CLASS'      => true,
33
+		'T_ANON_CLASS' => true,
34
+		'T_INTERFACE'  => true,
35
+		'T_TRAIT'      => true,
36
+		'T_NAMESPACE'  => true,
37
+	);
38 38
 
39
-    /**
40
-     * Returns an array of tokens this test wants to listen for.
41
-     *
42
-     * @return array
43
-     */
44
-    public function register()
45
-    {
46
-        return array(\T_FUNCTION);
47
-    }
39
+	/**
40
+	 * Returns an array of tokens this test wants to listen for.
41
+	 *
42
+	 * @return array
43
+	 */
44
+	public function register()
45
+	{
46
+		return array(\T_FUNCTION);
47
+	}
48 48
 
49
-    /**
50
-     * Processes this test, when one of its tokens is encountered.
51
-     *
52
-     * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned.
53
-     * @param int                   $stackPtr  The position of the current token in the
54
-     *                                         stack passed in $tokens.
55
-     *
56
-     * @return void
57
-     */
58
-    public function process(File $phpcsFile, $stackPtr)
59
-    {
60
-        if ($this->supportsAbove('7.2') === false) {
61
-            return;
62
-        }
49
+	/**
50
+	 * Processes this test, when one of its tokens is encountered.
51
+	 *
52
+	 * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned.
53
+	 * @param int                   $stackPtr  The position of the current token in the
54
+	 *                                         stack passed in $tokens.
55
+	 *
56
+	 * @return void
57
+	 */
58
+	public function process(File $phpcsFile, $stackPtr)
59
+	{
60
+		if ($this->supportsAbove('7.2') === false) {
61
+			return;
62
+		}
63 63
 
64
-        $funcName = $phpcsFile->getDeclarationName($stackPtr);
64
+		$funcName = $phpcsFile->getDeclarationName($stackPtr);
65 65
 
66
-        if (strtolower($funcName) !== '__autoload') {
67
-            return;
68
-        }
66
+		if (strtolower($funcName) !== '__autoload') {
67
+			return;
68
+		}
69 69
 
70
-        if ($this->validDirectScope($phpcsFile, $stackPtr, $this->checkForScopes) !== false) {
71
-            return;
72
-        }
70
+		if ($this->validDirectScope($phpcsFile, $stackPtr, $this->checkForScopes) !== false) {
71
+			return;
72
+		}
73 73
 
74
-        if ($this->determineNamespace($phpcsFile, $stackPtr) !== '') {
75
-            return;
76
-        }
74
+		if ($this->determineNamespace($phpcsFile, $stackPtr) !== '') {
75
+			return;
76
+		}
77 77
 
78
-        $phpcsFile->addWarning('Use of __autoload() function is deprecated since PHP 7.2', $stackPtr, 'Found');
79
-    }
78
+		$phpcsFile->addWarning('Use of __autoload() function is deprecated since PHP 7.2', $stackPtr, 'Found');
79
+	}
80 80
 }
Please login to merge, or discard this patch.
Sniffs/FunctionNameRestrictions/RemovedNamespacedAssertSniff.php 1 patch
Indentation   +51 added lines, -51 removed lines patch added patch discarded remove patch
@@ -30,63 +30,63 @@
 block discarded – undo
30 30
  */
31 31
 class RemovedNamespacedAssertSniff extends Sniff
32 32
 {
33
-    /**
34
-     * Scopes in which an `assert` function can be declared without issue.
35
-     *
36
-     * @var array
37
-     */
38
-    private $scopes = array(
39
-        \T_CLASS,
40
-        \T_INTERFACE,
41
-        \T_TRAIT,
42
-        \T_CLOSURE,
43
-    );
33
+	/**
34
+	 * Scopes in which an `assert` function can be declared without issue.
35
+	 *
36
+	 * @var array
37
+	 */
38
+	private $scopes = array(
39
+		\T_CLASS,
40
+		\T_INTERFACE,
41
+		\T_TRAIT,
42
+		\T_CLOSURE,
43
+	);
44 44
 
45
-    /**
46
-     * Returns an array of tokens this test wants to listen for.
47
-     *
48
-     * @return array
49
-     */
50
-    public function register()
51
-    {
52
-        // Enrich the scopes list.
53
-        if (\defined('T_ANON_CLASS')) {
54
-            $this->scopes[] = \T_ANON_CLASS;
55
-        }
45
+	/**
46
+	 * Returns an array of tokens this test wants to listen for.
47
+	 *
48
+	 * @return array
49
+	 */
50
+	public function register()
51
+	{
52
+		// Enrich the scopes list.
53
+		if (\defined('T_ANON_CLASS')) {
54
+			$this->scopes[] = \T_ANON_CLASS;
55
+		}
56 56
 
57
-        return array(\T_FUNCTION);
58
-    }
57
+		return array(\T_FUNCTION);
58
+	}
59 59
 
60
-    /**
61
-     * Processes this test, when one of its tokens is encountered.
62
-     *
63
-     * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned.
64
-     * @param int                   $stackPtr  The position of the current token in the
65
-     *                                         stack passed in $tokens.
66
-     *
67
-     * @return void
68
-     */
69
-    public function process(File $phpcsFile, $stackPtr)
70
-    {
71
-        if ($this->supportsAbove('7.3') === false) {
72
-            return;
73
-        }
60
+	/**
61
+	 * Processes this test, when one of its tokens is encountered.
62
+	 *
63
+	 * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned.
64
+	 * @param int                   $stackPtr  The position of the current token in the
65
+	 *                                         stack passed in $tokens.
66
+	 *
67
+	 * @return void
68
+	 */
69
+	public function process(File $phpcsFile, $stackPtr)
70
+	{
71
+		if ($this->supportsAbove('7.3') === false) {
72
+			return;
73
+		}
74 74
 
75
-        $funcName = $phpcsFile->getDeclarationName($stackPtr);
75
+		$funcName = $phpcsFile->getDeclarationName($stackPtr);
76 76
 
77
-        if (strtolower($funcName) !== 'assert') {
78
-            return;
79
-        }
77
+		if (strtolower($funcName) !== 'assert') {
78
+			return;
79
+		}
80 80
 
81
-        if ($phpcsFile->hasCondition($stackPtr, $this->scopes) === true) {
82
-            return;
83
-        }
81
+		if ($phpcsFile->hasCondition($stackPtr, $this->scopes) === true) {
82
+			return;
83
+		}
84 84
 
85
-        if ($this->determineNamespace($phpcsFile, $stackPtr) === '') {
86
-            // Not a namespaced function declaration. Parse error, but not our concern.
87
-            return;
88
-        }
85
+		if ($this->determineNamespace($phpcsFile, $stackPtr) === '') {
86
+			// Not a namespaced function declaration. Parse error, but not our concern.
87
+			return;
88
+		}
89 89
 
90
-        $phpcsFile->addWarning('Declaring a free-standing function called assert() is deprecated since PHP 7.3.', $stackPtr, 'Found');
91
-    }
90
+		$phpcsFile->addWarning('Declaring a free-standing function called assert() is deprecated since PHP 7.3.', $stackPtr, 'Found');
91
+	}
92 92
 }
Please login to merge, or discard this patch.
PHPCompatibility/Sniffs/FunctionNameRestrictions/NewMagicMethodsSniff.php 1 patch
Indentation   +167 added lines, -167 removed lines patch added patch discarded remove patch
@@ -24,171 +24,171 @@
 block discarded – undo
24 24
 class NewMagicMethodsSniff extends AbstractNewFeatureSniff
25 25
 {
26 26
 
27
-    /**
28
-     * A list of new magic methods, not considered magic in older versions.
29
-     *
30
-     * Method names in the array should be all *lowercase*.
31
-     * The array lists : version number with false (not magic) or true (magic).
32
-     * If's sufficient to list the first version where the method became magic.
33
-     *
34
-     * @var array(string => array(string => int|string|null))
35
-     */
36
-    protected $newMagicMethods = array(
37
-        '__get' => array(
38
-            '4.4' => false,
39
-            '5.0' => true,
40
-        ),
41
-
42
-        '__isset' => array(
43
-            '5.0' => false,
44
-            '5.1' => true,
45
-        ),
46
-        '__unset' => array(
47
-            '5.0' => false,
48
-            '5.1' => true,
49
-        ),
50
-        '__set_state' => array(
51
-            '5.0' => false,
52
-            '5.1' => true,
53
-        ),
54
-
55
-        '__callstatic' => array(
56
-            '5.2' => false,
57
-            '5.3' => true,
58
-        ),
59
-        '__invoke' => array(
60
-            '5.2' => false,
61
-            '5.3' => true,
62
-        ),
63
-
64
-        '__debuginfo' => array(
65
-            '5.5' => false,
66
-            '5.6' => true,
67
-        ),
68
-
69
-        // Special case - only became properly magical in 5.2.0,
70
-        // before that it was only called for echo and print.
71
-        '__tostring' => array(
72
-            '5.1'     => false,
73
-            '5.2'     => true,
74
-            'message' => 'The method %s() was not truly magical in PHP version %s and earlier. The associated magic functionality will only be called when directly combined with echo or print.',
75
-        ),
76
-    );
77
-
78
-
79
-    /**
80
-     * Returns an array of tokens this test wants to listen for.
81
-     *
82
-     * @return array
83
-     */
84
-    public function register()
85
-    {
86
-        return array(\T_FUNCTION);
87
-    }
88
-
89
-
90
-    /**
91
-     * Processes this test, when one of its tokens is encountered.
92
-     *
93
-     * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned.
94
-     * @param int                   $stackPtr  The position of the current token in the
95
-     *                                         stack passed in $tokens.
96
-     *
97
-     * @return void
98
-     */
99
-    public function process(File $phpcsFile, $stackPtr)
100
-    {
101
-        $functionName   = $phpcsFile->getDeclarationName($stackPtr);
102
-        $functionNameLc = strtolower($functionName);
103
-
104
-        if (isset($this->newMagicMethods[$functionNameLc]) === false) {
105
-            return;
106
-        }
107
-
108
-        if ($this->inClassScope($phpcsFile, $stackPtr, false) === false) {
109
-            return;
110
-        }
111
-
112
-        $itemInfo = array(
113
-            'name'   => $functionName,
114
-            'nameLc' => $functionNameLc,
115
-        );
116
-        $this->handleFeature($phpcsFile, $stackPtr, $itemInfo);
117
-    }
118
-
119
-
120
-    /**
121
-     * Get the relevant sub-array for a specific item from a multi-dimensional array.
122
-     *
123
-     * @param array $itemInfo Base information about the item.
124
-     *
125
-     * @return array Version and other information about the item.
126
-     */
127
-    public function getItemArray(array $itemInfo)
128
-    {
129
-        return $this->newMagicMethods[$itemInfo['nameLc']];
130
-    }
131
-
132
-
133
-    /**
134
-     * Get an array of the non-PHP-version array keys used in a sub-array.
135
-     *
136
-     * @return array
137
-     */
138
-    protected function getNonVersionArrayKeys()
139
-    {
140
-        return array('message');
141
-    }
142
-
143
-
144
-    /**
145
-     * Retrieve the relevant detail (version) information for use in an error message.
146
-     *
147
-     * @param array $itemArray Version and other information about the item.
148
-     * @param array $itemInfo  Base information about the item.
149
-     *
150
-     * @return array
151
-     */
152
-    public function getErrorInfo(array $itemArray, array $itemInfo)
153
-    {
154
-        $errorInfo            = parent::getErrorInfo($itemArray, $itemInfo);
155
-        $errorInfo['error']   = false; // Warning, not error.
156
-        $errorInfo['message'] = '';
157
-
158
-        if (empty($itemArray['message']) === false) {
159
-            $errorInfo['message'] = $itemArray['message'];
160
-        }
161
-
162
-        return $errorInfo;
163
-    }
164
-
165
-
166
-    /**
167
-     * Get the error message template for this sniff.
168
-     *
169
-     * @return string
170
-     */
171
-    protected function getErrorMsgTemplate()
172
-    {
173
-        return 'The method %s() was not magical in PHP version %s and earlier. The associated magic functionality will not be invoked.';
174
-    }
175
-
176
-
177
-    /**
178
-     * Allow for concrete child classes to filter the error message before it's passed to PHPCS.
179
-     *
180
-     * @param string $error     The error message which was created.
181
-     * @param array  $itemInfo  Base information about the item this error message applies to.
182
-     * @param array  $errorInfo Detail information about an item this error message applies to.
183
-     *
184
-     * @return string
185
-     */
186
-    protected function filterErrorMsg($error, array $itemInfo, array $errorInfo)
187
-    {
188
-        if ($errorInfo['message'] !== '') {
189
-            $error = $errorInfo['message'];
190
-        }
191
-
192
-        return $error;
193
-    }
27
+	/**
28
+	 * A list of new magic methods, not considered magic in older versions.
29
+	 *
30
+	 * Method names in the array should be all *lowercase*.
31
+	 * The array lists : version number with false (not magic) or true (magic).
32
+	 * If's sufficient to list the first version where the method became magic.
33
+	 *
34
+	 * @var array(string => array(string => int|string|null))
35
+	 */
36
+	protected $newMagicMethods = array(
37
+		'__get' => array(
38
+			'4.4' => false,
39
+			'5.0' => true,
40
+		),
41
+
42
+		'__isset' => array(
43
+			'5.0' => false,
44
+			'5.1' => true,
45
+		),
46
+		'__unset' => array(
47
+			'5.0' => false,
48
+			'5.1' => true,
49
+		),
50
+		'__set_state' => array(
51
+			'5.0' => false,
52
+			'5.1' => true,
53
+		),
54
+
55
+		'__callstatic' => array(
56
+			'5.2' => false,
57
+			'5.3' => true,
58
+		),
59
+		'__invoke' => array(
60
+			'5.2' => false,
61
+			'5.3' => true,
62
+		),
63
+
64
+		'__debuginfo' => array(
65
+			'5.5' => false,
66
+			'5.6' => true,
67
+		),
68
+
69
+		// Special case - only became properly magical in 5.2.0,
70
+		// before that it was only called for echo and print.
71
+		'__tostring' => array(
72
+			'5.1'     => false,
73
+			'5.2'     => true,
74
+			'message' => 'The method %s() was not truly magical in PHP version %s and earlier. The associated magic functionality will only be called when directly combined with echo or print.',
75
+		),
76
+	);
77
+
78
+
79
+	/**
80
+	 * Returns an array of tokens this test wants to listen for.
81
+	 *
82
+	 * @return array
83
+	 */
84
+	public function register()
85
+	{
86
+		return array(\T_FUNCTION);
87
+	}
88
+
89
+
90
+	/**
91
+	 * Processes this test, when one of its tokens is encountered.
92
+	 *
93
+	 * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned.
94
+	 * @param int                   $stackPtr  The position of the current token in the
95
+	 *                                         stack passed in $tokens.
96
+	 *
97
+	 * @return void
98
+	 */
99
+	public function process(File $phpcsFile, $stackPtr)
100
+	{
101
+		$functionName   = $phpcsFile->getDeclarationName($stackPtr);
102
+		$functionNameLc = strtolower($functionName);
103
+
104
+		if (isset($this->newMagicMethods[$functionNameLc]) === false) {
105
+			return;
106
+		}
107
+
108
+		if ($this->inClassScope($phpcsFile, $stackPtr, false) === false) {
109
+			return;
110
+		}
111
+
112
+		$itemInfo = array(
113
+			'name'   => $functionName,
114
+			'nameLc' => $functionNameLc,
115
+		);
116
+		$this->handleFeature($phpcsFile, $stackPtr, $itemInfo);
117
+	}
118
+
119
+
120
+	/**
121
+	 * Get the relevant sub-array for a specific item from a multi-dimensional array.
122
+	 *
123
+	 * @param array $itemInfo Base information about the item.
124
+	 *
125
+	 * @return array Version and other information about the item.
126
+	 */
127
+	public function getItemArray(array $itemInfo)
128
+	{
129
+		return $this->newMagicMethods[$itemInfo['nameLc']];
130
+	}
131
+
132
+
133
+	/**
134
+	 * Get an array of the non-PHP-version array keys used in a sub-array.
135
+	 *
136
+	 * @return array
137
+	 */
138
+	protected function getNonVersionArrayKeys()
139
+	{
140
+		return array('message');
141
+	}
142
+
143
+
144
+	/**
145
+	 * Retrieve the relevant detail (version) information for use in an error message.
146
+	 *
147
+	 * @param array $itemArray Version and other information about the item.
148
+	 * @param array $itemInfo  Base information about the item.
149
+	 *
150
+	 * @return array
151
+	 */
152
+	public function getErrorInfo(array $itemArray, array $itemInfo)
153
+	{
154
+		$errorInfo            = parent::getErrorInfo($itemArray, $itemInfo);
155
+		$errorInfo['error']   = false; // Warning, not error.
156
+		$errorInfo['message'] = '';
157
+
158
+		if (empty($itemArray['message']) === false) {
159
+			$errorInfo['message'] = $itemArray['message'];
160
+		}
161
+
162
+		return $errorInfo;
163
+	}
164
+
165
+
166
+	/**
167
+	 * Get the error message template for this sniff.
168
+	 *
169
+	 * @return string
170
+	 */
171
+	protected function getErrorMsgTemplate()
172
+	{
173
+		return 'The method %s() was not magical in PHP version %s and earlier. The associated magic functionality will not be invoked.';
174
+	}
175
+
176
+
177
+	/**
178
+	 * Allow for concrete child classes to filter the error message before it's passed to PHPCS.
179
+	 *
180
+	 * @param string $error     The error message which was created.
181
+	 * @param array  $itemInfo  Base information about the item this error message applies to.
182
+	 * @param array  $errorInfo Detail information about an item this error message applies to.
183
+	 *
184
+	 * @return string
185
+	 */
186
+	protected function filterErrorMsg($error, array $itemInfo, array $errorInfo)
187
+	{
188
+		if ($errorInfo['message'] !== '') {
189
+			$error = $errorInfo['message'];
190
+		}
191
+
192
+		return $error;
193
+	}
194 194
 }
Please login to merge, or discard this patch.
Sniffs/FunctionNameRestrictions/RemovedPHP4StyleConstructorsSniff.php 1 patch
Indentation   +99 added lines, -99 removed lines patch added patch discarded remove patch
@@ -27,109 +27,109 @@
 block discarded – undo
27 27
 class RemovedPHP4StyleConstructorsSniff extends Sniff
28 28
 {
29 29
 
30
-    /**
31
-     * Returns an array of tokens this test wants to listen for.
32
-     *
33
-     * @return array
34
-     */
35
-    public function register()
36
-    {
37
-        return array(
38
-            \T_CLASS,
39
-            \T_INTERFACE,
40
-        );
41
-    }
42
-
43
-    /**
44
-     * Processes this test, when one of its tokens is encountered.
45
-     *
46
-     * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned.
47
-     * @param int                   $stackPtr  The position of the current token in the
48
-     *                                         stack passed in $tokens.
49
-     *
50
-     * @return void
51
-     */
52
-    public function process(File $phpcsFile, $stackPtr)
53
-    {
54
-        if ($this->supportsAbove('7.0') === false) {
55
-            return;
56
-        }
57
-
58
-        if ($this->determineNamespace($phpcsFile, $stackPtr) !== '') {
59
-            /*
30
+	/**
31
+	 * Returns an array of tokens this test wants to listen for.
32
+	 *
33
+	 * @return array
34
+	 */
35
+	public function register()
36
+	{
37
+		return array(
38
+			\T_CLASS,
39
+			\T_INTERFACE,
40
+		);
41
+	}
42
+
43
+	/**
44
+	 * Processes this test, when one of its tokens is encountered.
45
+	 *
46
+	 * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned.
47
+	 * @param int                   $stackPtr  The position of the current token in the
48
+	 *                                         stack passed in $tokens.
49
+	 *
50
+	 * @return void
51
+	 */
52
+	public function process(File $phpcsFile, $stackPtr)
53
+	{
54
+		if ($this->supportsAbove('7.0') === false) {
55
+			return;
56
+		}
57
+
58
+		if ($this->determineNamespace($phpcsFile, $stackPtr) !== '') {
59
+			/*
60 60
              * Namespaced methods with the same name as the class are treated as
61 61
              * regular methods, so we can bow out if we're in a namespace.
62 62
              *
63 63
              * Note: the exception to this is PHP 5.3.0-5.3.2. This is currently
64 64
              * not dealt with.
65 65
              */
66
-            return;
67
-        }
68
-
69
-        $tokens = $phpcsFile->getTokens();
70
-
71
-        $class = $tokens[$stackPtr];
72
-
73
-        if (isset($class['scope_closer']) === false) {
74
-            return;
75
-        }
76
-
77
-        $nextNonEmpty = $phpcsFile->findNext(Tokens::$emptyTokens, ($stackPtr + 1), null, true);
78
-        if ($nextNonEmpty === false || $tokens[$nextNonEmpty]['code'] !== \T_STRING) {
79
-            // Anonymous class in combination with PHPCS 2.3.x.
80
-            return;
81
-        }
82
-
83
-        $scopeCloser = $class['scope_closer'];
84
-        $className   = $tokens[$nextNonEmpty]['content'];
85
-
86
-        if (empty($className) || \is_string($className) === false) {
87
-            return;
88
-        }
89
-
90
-        $nextFunc            = $stackPtr;
91
-        $classNameLc         = strtolower($className);
92
-        $newConstructorFound = false;
93
-        $oldConstructorFound = false;
94
-        $oldConstructorPos   = -1;
95
-        while (($nextFunc = $phpcsFile->findNext(\T_FUNCTION, ($nextFunc + 1), $scopeCloser)) !== false) {
96
-            $functionScopeCloser = $nextFunc;
97
-            if (isset($tokens[$nextFunc]['scope_closer'])) {
98
-                // Normal (non-interface, non-abstract) method.
99
-                $functionScopeCloser = $tokens[$nextFunc]['scope_closer'];
100
-            }
101
-
102
-            $funcName = $phpcsFile->getDeclarationName($nextFunc);
103
-            if (empty($funcName) || \is_string($funcName) === false) {
104
-                $nextFunc = $functionScopeCloser;
105
-                continue;
106
-            }
107
-
108
-            $funcNameLc = strtolower($funcName);
109
-
110
-            if ($funcNameLc === '__construct') {
111
-                $newConstructorFound = true;
112
-            }
113
-
114
-            if ($funcNameLc === $classNameLc) {
115
-                $oldConstructorFound = true;
116
-                $oldConstructorPos   = $nextFunc;
117
-            }
118
-
119
-            // If both have been found, no need to continue looping through the functions.
120
-            if ($newConstructorFound === true && $oldConstructorFound === true) {
121
-                break;
122
-            }
123
-
124
-            $nextFunc = $functionScopeCloser;
125
-        }
126
-
127
-        if ($newConstructorFound === false && $oldConstructorFound === true) {
128
-            $phpcsFile->addWarning(
129
-                'Use of deprecated PHP4 style class constructor is not supported since PHP 7.',
130
-                $oldConstructorPos,
131
-                'Found'
132
-            );
133
-        }
134
-    }
66
+			return;
67
+		}
68
+
69
+		$tokens = $phpcsFile->getTokens();
70
+
71
+		$class = $tokens[$stackPtr];
72
+
73
+		if (isset($class['scope_closer']) === false) {
74
+			return;
75
+		}
76
+
77
+		$nextNonEmpty = $phpcsFile->findNext(Tokens::$emptyTokens, ($stackPtr + 1), null, true);
78
+		if ($nextNonEmpty === false || $tokens[$nextNonEmpty]['code'] !== \T_STRING) {
79
+			// Anonymous class in combination with PHPCS 2.3.x.
80
+			return;
81
+		}
82
+
83
+		$scopeCloser = $class['scope_closer'];
84
+		$className   = $tokens[$nextNonEmpty]['content'];
85
+
86
+		if (empty($className) || \is_string($className) === false) {
87
+			return;
88
+		}
89
+
90
+		$nextFunc            = $stackPtr;
91
+		$classNameLc         = strtolower($className);
92
+		$newConstructorFound = false;
93
+		$oldConstructorFound = false;
94
+		$oldConstructorPos   = -1;
95
+		while (($nextFunc = $phpcsFile->findNext(\T_FUNCTION, ($nextFunc + 1), $scopeCloser)) !== false) {
96
+			$functionScopeCloser = $nextFunc;
97
+			if (isset($tokens[$nextFunc]['scope_closer'])) {
98
+				// Normal (non-interface, non-abstract) method.
99
+				$functionScopeCloser = $tokens[$nextFunc]['scope_closer'];
100
+			}
101
+
102
+			$funcName = $phpcsFile->getDeclarationName($nextFunc);
103
+			if (empty($funcName) || \is_string($funcName) === false) {
104
+				$nextFunc = $functionScopeCloser;
105
+				continue;
106
+			}
107
+
108
+			$funcNameLc = strtolower($funcName);
109
+
110
+			if ($funcNameLc === '__construct') {
111
+				$newConstructorFound = true;
112
+			}
113
+
114
+			if ($funcNameLc === $classNameLc) {
115
+				$oldConstructorFound = true;
116
+				$oldConstructorPos   = $nextFunc;
117
+			}
118
+
119
+			// If both have been found, no need to continue looping through the functions.
120
+			if ($newConstructorFound === true && $oldConstructorFound === true) {
121
+				break;
122
+			}
123
+
124
+			$nextFunc = $functionScopeCloser;
125
+		}
126
+
127
+		if ($newConstructorFound === false && $oldConstructorFound === true) {
128
+			$phpcsFile->addWarning(
129
+				'Use of deprecated PHP4 style class constructor is not supported since PHP 7.',
130
+				$oldConstructorPos,
131
+				'Found'
132
+			);
133
+		}
134
+	}
135 135
 }
Please login to merge, or discard this patch.
Sniffs/FunctionNameRestrictions/ReservedFunctionNamesSniff.php 1 patch
Indentation   +88 added lines, -88 removed lines patch added patch discarded remove patch
@@ -37,108 +37,108 @@
 block discarded – undo
37 37
 class ReservedFunctionNamesSniff extends PHPCS_CamelCapsFunctionNameSniff
38 38
 {
39 39
 
40
-    /**
41
-     * Overload the constructor to work round various PHPCS cross-version compatibility issues.
42
-     */
43
-    public function __construct()
44
-    {
45
-        $scopeTokens = array(\T_CLASS, \T_INTERFACE, \T_TRAIT);
46
-        if (\defined('T_ANON_CLASS')) {
47
-            $scopeTokens[] = \T_ANON_CLASS;
48
-        }
40
+	/**
41
+	 * Overload the constructor to work round various PHPCS cross-version compatibility issues.
42
+	 */
43
+	public function __construct()
44
+	{
45
+		$scopeTokens = array(\T_CLASS, \T_INTERFACE, \T_TRAIT);
46
+		if (\defined('T_ANON_CLASS')) {
47
+			$scopeTokens[] = \T_ANON_CLASS;
48
+		}
49 49
 
50
-        // Call the grand-parent constructor directly.
51
-        PHPCS_AbstractScopeSniff::__construct($scopeTokens, array(\T_FUNCTION), true);
50
+		// Call the grand-parent constructor directly.
51
+		PHPCS_AbstractScopeSniff::__construct($scopeTokens, array(\T_FUNCTION), true);
52 52
 
53
-        // Make sure debuginfo is included in the array. Upstream only includes it since 2.5.1.
54
-        $this->magicMethods['debuginfo'] = true;
55
-    }
53
+		// Make sure debuginfo is included in the array. Upstream only includes it since 2.5.1.
54
+		$this->magicMethods['debuginfo'] = true;
55
+	}
56 56
 
57 57
 
58
-    /**
59
-     * Processes the tokens within the scope.
60
-     *
61
-     * @param \PHP_CodeSniffer_File $phpcsFile The file being processed.
62
-     * @param int                   $stackPtr  The position where this token was
63
-     *                                         found.
64
-     * @param int                   $currScope The position of the current scope.
65
-     *
66
-     * @return void
67
-     */
68
-    protected function processTokenWithinScope(File $phpcsFile, $stackPtr, $currScope)
69
-    {
70
-        $tokens = $phpcsFile->getTokens();
58
+	/**
59
+	 * Processes the tokens within the scope.
60
+	 *
61
+	 * @param \PHP_CodeSniffer_File $phpcsFile The file being processed.
62
+	 * @param int                   $stackPtr  The position where this token was
63
+	 *                                         found.
64
+	 * @param int                   $currScope The position of the current scope.
65
+	 *
66
+	 * @return void
67
+	 */
68
+	protected function processTokenWithinScope(File $phpcsFile, $stackPtr, $currScope)
69
+	{
70
+		$tokens = $phpcsFile->getTokens();
71 71
 
72
-        /*
72
+		/*
73 73
          * Determine if this is a function which needs to be examined.
74 74
          * The `processTokenWithinScope()` is called for each valid scope a method is in,
75 75
          * so for nested classes, we need to make sure we only examine the token for
76 76
          * the lowest level valid scope.
77 77
          */
78
-        $conditions = $tokens[$stackPtr]['conditions'];
79
-        end($conditions);
80
-        $deepestScope = key($conditions);
81
-        if ($deepestScope !== $currScope) {
82
-            return;
83
-        }
78
+		$conditions = $tokens[$stackPtr]['conditions'];
79
+		end($conditions);
80
+		$deepestScope = key($conditions);
81
+		if ($deepestScope !== $currScope) {
82
+			return;
83
+		}
84 84
 
85
-        $methodName = $phpcsFile->getDeclarationName($stackPtr);
86
-        if ($methodName === null) {
87
-            // Ignore closures.
88
-            return;
89
-        }
85
+		$methodName = $phpcsFile->getDeclarationName($stackPtr);
86
+		if ($methodName === null) {
87
+			// Ignore closures.
88
+			return;
89
+		}
90 90
 
91
-        // Is this a magic method. i.e., is prefixed with "__" ?
92
-        if (preg_match('|^__[^_]|', $methodName) > 0) {
93
-            $magicPart = strtolower(substr($methodName, 2));
94
-            if (isset($this->magicMethods[$magicPart]) === false
95
-                && isset($this->methodsDoubleUnderscore[$magicPart]) === false
96
-            ) {
97
-                $className         = '[anonymous class]';
98
-                $scopeNextNonEmpty = $phpcsFile->findNext(Tokens::$emptyTokens, ($currScope + 1), null, true);
99
-                if ($scopeNextNonEmpty !== false && $tokens[$scopeNextNonEmpty]['code'] === \T_STRING) {
100
-                    $className = $tokens[$scopeNextNonEmpty]['content'];
101
-                }
91
+		// Is this a magic method. i.e., is prefixed with "__" ?
92
+		if (preg_match('|^__[^_]|', $methodName) > 0) {
93
+			$magicPart = strtolower(substr($methodName, 2));
94
+			if (isset($this->magicMethods[$magicPart]) === false
95
+				&& isset($this->methodsDoubleUnderscore[$magicPart]) === false
96
+			) {
97
+				$className         = '[anonymous class]';
98
+				$scopeNextNonEmpty = $phpcsFile->findNext(Tokens::$emptyTokens, ($currScope + 1), null, true);
99
+				if ($scopeNextNonEmpty !== false && $tokens[$scopeNextNonEmpty]['code'] === \T_STRING) {
100
+					$className = $tokens[$scopeNextNonEmpty]['content'];
101
+				}
102 102
 
103
-                $phpcsFile->addWarning(
104
-                    'Method name "%s" is discouraged; PHP has reserved all method names with a double underscore prefix for future use.',
105
-                    $stackPtr,
106
-                    'MethodDoubleUnderscore',
107
-                    array($className . '::' . $methodName)
108
-                );
109
-            }
110
-        }
111
-    }
103
+				$phpcsFile->addWarning(
104
+					'Method name "%s" is discouraged; PHP has reserved all method names with a double underscore prefix for future use.',
105
+					$stackPtr,
106
+					'MethodDoubleUnderscore',
107
+					array($className . '::' . $methodName)
108
+				);
109
+			}
110
+		}
111
+	}
112 112
 
113 113
 
114
-    /**
115
-     * Processes the tokens outside the scope.
116
-     *
117
-     * @param \PHP_CodeSniffer_File $phpcsFile The file being processed.
118
-     * @param int                   $stackPtr  The position where this token was
119
-     *                                         found.
120
-     *
121
-     * @return void
122
-     */
123
-    protected function processTokenOutsideScope(File $phpcsFile, $stackPtr)
124
-    {
125
-        $functionName = $phpcsFile->getDeclarationName($stackPtr);
126
-        if ($functionName === null) {
127
-            // Ignore closures.
128
-            return;
129
-        }
114
+	/**
115
+	 * Processes the tokens outside the scope.
116
+	 *
117
+	 * @param \PHP_CodeSniffer_File $phpcsFile The file being processed.
118
+	 * @param int                   $stackPtr  The position where this token was
119
+	 *                                         found.
120
+	 *
121
+	 * @return void
122
+	 */
123
+	protected function processTokenOutsideScope(File $phpcsFile, $stackPtr)
124
+	{
125
+		$functionName = $phpcsFile->getDeclarationName($stackPtr);
126
+		if ($functionName === null) {
127
+			// Ignore closures.
128
+			return;
129
+		}
130 130
 
131
-        // Is this a magic function. i.e., it is prefixed with "__".
132
-        if (preg_match('|^__[^_]|', $functionName) > 0) {
133
-            $magicPart = strtolower(substr($functionName, 2));
134
-            if (isset($this->magicFunctions[$magicPart]) === false) {
135
-                $phpcsFile->addWarning(
136
-                    'Function name "%s" is discouraged; PHP has reserved all method names with a double underscore prefix for future use.',
137
-                    $stackPtr,
138
-                    'FunctionDoubleUnderscore',
139
-                    array($functionName)
140
-                );
141
-            }
142
-        }
143
-    }
131
+		// Is this a magic function. i.e., it is prefixed with "__".
132
+		if (preg_match('|^__[^_]|', $functionName) > 0) {
133
+			$magicPart = strtolower(substr($functionName, 2));
134
+			if (isset($this->magicFunctions[$magicPart]) === false) {
135
+				$phpcsFile->addWarning(
136
+					'Function name "%s" is discouraged; PHP has reserved all method names with a double underscore prefix for future use.',
137
+					$stackPtr,
138
+					'FunctionDoubleUnderscore',
139
+					array($functionName)
140
+				);
141
+			}
142
+		}
143
+	}
144 144
 }
Please login to merge, or discard this patch.
PHPCompatibility/Sniffs/ParameterValues/NewNegativeStringOffsetSniff.php 1 patch
Indentation   +88 added lines, -88 removed lines patch added patch discarded remove patch
@@ -29,98 +29,98 @@
 block discarded – undo
29 29
 class NewNegativeStringOffsetSniff extends AbstractFunctionCallParameterSniff
30 30
 {
31 31
 
32
-    /**
33
-     * Functions to check for.
34
-     *
35
-     * @var array Function name => 1-based parameter offset of the affected parameters => parameter name.
36
-     */
37
-    protected $targetFunctions = array(
38
-        'file_get_contents'     => array(
39
-            4 => 'offset',
40
-        ),
41
-        'grapheme_extract'      => array(
42
-            4 => 'start',
43
-        ),
44
-        'grapheme_stripos'      => array(
45
-            3 => 'offset',
46
-        ),
47
-        'grapheme_strpos'       => array(
48
-            3 => 'offset',
49
-        ),
50
-        'iconv_strpos'          => array(
51
-            3 => 'offset',
52
-        ),
53
-        'mb_ereg_search_setpos' => array(
54
-            1 => 'position',
55
-        ),
56
-        'mb_strimwidth'         => array(
57
-            2 => 'start',
58
-            3 => 'width',
59
-        ),
60
-        'mb_stripos'            => array(
61
-            3 => 'offset',
62
-        ),
63
-        'mb_strpos'             => array(
64
-            3 => 'offset',
65
-        ),
66
-        'stripos'               => array(
67
-            3 => 'offset',
68
-        ),
69
-        'strpos'                => array(
70
-            3 => 'offset',
71
-        ),
72
-        'substr_count'          => array(
73
-            3 => 'offset',
74
-            4 => 'length',
75
-        ),
76
-    );
32
+	/**
33
+	 * Functions to check for.
34
+	 *
35
+	 * @var array Function name => 1-based parameter offset of the affected parameters => parameter name.
36
+	 */
37
+	protected $targetFunctions = array(
38
+		'file_get_contents'     => array(
39
+			4 => 'offset',
40
+		),
41
+		'grapheme_extract'      => array(
42
+			4 => 'start',
43
+		),
44
+		'grapheme_stripos'      => array(
45
+			3 => 'offset',
46
+		),
47
+		'grapheme_strpos'       => array(
48
+			3 => 'offset',
49
+		),
50
+		'iconv_strpos'          => array(
51
+			3 => 'offset',
52
+		),
53
+		'mb_ereg_search_setpos' => array(
54
+			1 => 'position',
55
+		),
56
+		'mb_strimwidth'         => array(
57
+			2 => 'start',
58
+			3 => 'width',
59
+		),
60
+		'mb_stripos'            => array(
61
+			3 => 'offset',
62
+		),
63
+		'mb_strpos'             => array(
64
+			3 => 'offset',
65
+		),
66
+		'stripos'               => array(
67
+			3 => 'offset',
68
+		),
69
+		'strpos'                => array(
70
+			3 => 'offset',
71
+		),
72
+		'substr_count'          => array(
73
+			3 => 'offset',
74
+			4 => 'length',
75
+		),
76
+	);
77 77
 
78 78
 
79
-    /**
80
-     * Do a version check to determine if this sniff needs to run at all.
81
-     *
82
-     * @return bool
83
-     */
84
-    protected function bowOutEarly()
85
-    {
86
-        return ($this->supportsBelow('7.0') === false);
87
-    }
79
+	/**
80
+	 * Do a version check to determine if this sniff needs to run at all.
81
+	 *
82
+	 * @return bool
83
+	 */
84
+	protected function bowOutEarly()
85
+	{
86
+		return ($this->supportsBelow('7.0') === false);
87
+	}
88 88
 
89
-    /**
90
-     * Process the parameters of a matched function.
91
-     *
92
-     * @param \PHP_CodeSniffer_File $phpcsFile    The file being scanned.
93
-     * @param int                   $stackPtr     The position of the current token in the stack.
94
-     * @param string                $functionName The token content (function name) which was matched.
95
-     * @param array                 $parameters   Array with information about the parameters.
96
-     *
97
-     * @return int|void Integer stack pointer to skip forward or void to continue
98
-     *                  normal file processing.
99
-     */
100
-    public function processParameters(File $phpcsFile, $stackPtr, $functionName, $parameters)
101
-    {
102
-        $functionLC = strtolower($functionName);
103
-        foreach ($this->targetFunctions[$functionLC] as $pos => $name) {
104
-            if (isset($parameters[$pos]) === false) {
105
-                continue;
106
-            }
89
+	/**
90
+	 * Process the parameters of a matched function.
91
+	 *
92
+	 * @param \PHP_CodeSniffer_File $phpcsFile    The file being scanned.
93
+	 * @param int                   $stackPtr     The position of the current token in the stack.
94
+	 * @param string                $functionName The token content (function name) which was matched.
95
+	 * @param array                 $parameters   Array with information about the parameters.
96
+	 *
97
+	 * @return int|void Integer stack pointer to skip forward or void to continue
98
+	 *                  normal file processing.
99
+	 */
100
+	public function processParameters(File $phpcsFile, $stackPtr, $functionName, $parameters)
101
+	{
102
+		$functionLC = strtolower($functionName);
103
+		foreach ($this->targetFunctions[$functionLC] as $pos => $name) {
104
+			if (isset($parameters[$pos]) === false) {
105
+				continue;
106
+			}
107 107
 
108
-            $targetParam = $parameters[$pos];
108
+			$targetParam = $parameters[$pos];
109 109
 
110
-            if ($this->isNegativeNumber($phpcsFile, $targetParam['start'], $targetParam['end']) === false) {
111
-                continue;
112
-            }
110
+			if ($this->isNegativeNumber($phpcsFile, $targetParam['start'], $targetParam['end']) === false) {
111
+				continue;
112
+			}
113 113
 
114
-            $phpcsFile->addError(
115
-                'Negative string offsets were not supported for the $%s parameter in %s() in PHP 7.0 or lower. Found %s',
116
-                $targetParam['start'],
117
-                'Found',
118
-                array(
119
-                    $name,
120
-                    $functionName,
121
-                    $targetParam['raw'],
122
-                )
123
-            );
124
-        }
125
-    }
114
+			$phpcsFile->addError(
115
+				'Negative string offsets were not supported for the $%s parameter in %s() in PHP 7.0 or lower. Found %s',
116
+				$targetParam['start'],
117
+				'Found',
118
+				array(
119
+					$name,
120
+					$functionName,
121
+					$targetParam['raw'],
122
+				)
123
+			);
124
+		}
125
+	}
126 126
 }
Please login to merge, or discard this patch.
PHPCompatibility/Sniffs/ParameterValues/NewPCREModifiersSniff.php 1 patch
Indentation   +78 added lines, -78 removed lines patch added patch discarded remove patch
@@ -24,92 +24,92 @@
 block discarded – undo
24 24
 class NewPCREModifiersSniff extends RemovedPCREModifiersSniff
25 25
 {
26 26
 
27
-    /**
28
-     * Functions to check for.
29
-     *
30
-     * @var array
31
-     */
32
-    protected $targetFunctions = array(
33
-        'preg_replace'                => true,
34
-        'preg_filter'                 => true,
35
-        'preg_grep'                   => true,
36
-        'preg_match_all'              => true,
37
-        'preg_match'                  => true,
38
-        'preg_replace_callback_array' => true,
39
-        'preg_replace_callback'       => true,
40
-        'preg_replace'                => true,
41
-        'preg_split'                  => true,
42
-    );
27
+	/**
28
+	 * Functions to check for.
29
+	 *
30
+	 * @var array
31
+	 */
32
+	protected $targetFunctions = array(
33
+		'preg_replace'                => true,
34
+		'preg_filter'                 => true,
35
+		'preg_grep'                   => true,
36
+		'preg_match_all'              => true,
37
+		'preg_match'                  => true,
38
+		'preg_replace_callback_array' => true,
39
+		'preg_replace_callback'       => true,
40
+		'preg_replace'                => true,
41
+		'preg_split'                  => true,
42
+	);
43 43
 
44
-    /**
45
-     * Array listing newly introduced regex modifiers.
46
-     *
47
-     * The key should be the modifier (case-sensitive!).
48
-     * The value should be the PHP version in which the modifier was introduced.
49
-     *
50
-     * @var array
51
-     */
52
-    protected $newModifiers = array(
53
-        'J' => array(
54
-            '7.1' => false,
55
-            '7.2' => true,
56
-        ),
57
-    );
44
+	/**
45
+	 * Array listing newly introduced regex modifiers.
46
+	 *
47
+	 * The key should be the modifier (case-sensitive!).
48
+	 * The value should be the PHP version in which the modifier was introduced.
49
+	 *
50
+	 * @var array
51
+	 */
52
+	protected $newModifiers = array(
53
+		'J' => array(
54
+			'7.1' => false,
55
+			'7.2' => true,
56
+		),
57
+	);
58 58
 
59 59
 
60
-    /**
61
-     * Do a version check to determine if this sniff needs to run at all.
62
-     *
63
-     * @return bool
64
-     */
65
-    protected function bowOutEarly()
66
-    {
67
-        // Version used here should be the highest version from the `$newModifiers` array,
68
-        // i.e. the last PHP version in which a new modifier was introduced.
69
-        return ($this->supportsBelow('7.2') === false);
70
-    }
60
+	/**
61
+	 * Do a version check to determine if this sniff needs to run at all.
62
+	 *
63
+	 * @return bool
64
+	 */
65
+	protected function bowOutEarly()
66
+	{
67
+		// Version used here should be the highest version from the `$newModifiers` array,
68
+		// i.e. the last PHP version in which a new modifier was introduced.
69
+		return ($this->supportsBelow('7.2') === false);
70
+	}
71 71
 
72 72
 
73
-    /**
74
-     * Examine the regex modifier string.
75
-     *
76
-     * @param \PHP_CodeSniffer_File $phpcsFile    The file being scanned.
77
-     * @param int                   $stackPtr     The position of the current token in the
78
-     *                                            stack passed in $tokens.
79
-     * @param string                $functionName The function which contained the pattern.
80
-     * @param string                $modifiers    The regex modifiers found.
81
-     *
82
-     * @return void
83
-     */
84
-    protected function examineModifiers(File $phpcsFile, $stackPtr, $functionName, $modifiers)
85
-    {
86
-        $error = 'The PCRE regex modifier "%s" is not present in PHP version %s or earlier';
73
+	/**
74
+	 * Examine the regex modifier string.
75
+	 *
76
+	 * @param \PHP_CodeSniffer_File $phpcsFile    The file being scanned.
77
+	 * @param int                   $stackPtr     The position of the current token in the
78
+	 *                                            stack passed in $tokens.
79
+	 * @param string                $functionName The function which contained the pattern.
80
+	 * @param string                $modifiers    The regex modifiers found.
81
+	 *
82
+	 * @return void
83
+	 */
84
+	protected function examineModifiers(File $phpcsFile, $stackPtr, $functionName, $modifiers)
85
+	{
86
+		$error = 'The PCRE regex modifier "%s" is not present in PHP version %s or earlier';
87 87
 
88
-        foreach ($this->newModifiers as $modifier => $versionArray) {
89
-            if (strpos($modifiers, $modifier) === false) {
90
-                continue;
91
-            }
88
+		foreach ($this->newModifiers as $modifier => $versionArray) {
89
+			if (strpos($modifiers, $modifier) === false) {
90
+				continue;
91
+			}
92 92
 
93
-            $notInVersion = '';
94
-            foreach ($versionArray as $version => $present) {
95
-                if ($notInVersion === '' && $present === false
96
-                    && $this->supportsBelow($version) === true
97
-                ) {
98
-                    $notInVersion = $version;
99
-                }
100
-            }
93
+			$notInVersion = '';
94
+			foreach ($versionArray as $version => $present) {
95
+				if ($notInVersion === '' && $present === false
96
+					&& $this->supportsBelow($version) === true
97
+				) {
98
+					$notInVersion = $version;
99
+				}
100
+			}
101 101
 
102
-            if ($notInVersion === '') {
103
-                continue;
104
-            }
102
+			if ($notInVersion === '') {
103
+				continue;
104
+			}
105 105
 
106
-            $errorCode = $modifier . 'ModifierFound';
107
-            $data      = array(
108
-                $modifier,
109
-                $notInVersion,
110
-            );
106
+			$errorCode = $modifier . 'ModifierFound';
107
+			$data      = array(
108
+				$modifier,
109
+				$notInVersion,
110
+			);
111 111
 
112
-            $phpcsFile->addError($error, $stackPtr, $errorCode, $data);
113
-        }
114
-    }
112
+			$phpcsFile->addError($error, $stackPtr, $errorCode, $data);
113
+		}
114
+	}
115 115
 }
Please login to merge, or discard this patch.