Skip to content

Commit 5dace4b

Browse files
committed
Merge branch 'master' into 4.x
2 parents a405d0a + df4784c commit 5dace4b

36 files changed

+908
-121
lines changed

src/Standards/Generic/Sniffs/CodeAnalysis/UnconditionalIfStatementSniff.php

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,6 @@ public function process(File $phpcsFile, $stackPtr)
7777

7878
if (isset(Tokens::EMPTY_TOKENS[$code]) === true) {
7979
continue;
80-
}
81-
82-
if ($code === T_NAME_FULLY_QUALIFIED) {
83-
$compareReadyKeyword = strtolower($tokens[$next]['content']);
84-
if ($compareReadyKeyword !== '\true' && $compareReadyKeyword !== '\false') {
85-
$goodCondition = true;
86-
}
8780
} else if ($code !== T_TRUE && $code !== T_FALSE) {
8881
$goodCondition = true;
8982
}

src/Standards/Generic/Sniffs/ControlStructures/DisallowYodaConditionsSniff.php

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -55,24 +55,12 @@ public function process(File $phpcsFile, $stackPtr)
5555
T_LNUMBER,
5656
T_DNUMBER,
5757
T_CONSTANT_ENCAPSED_STRING,
58-
T_NAME_FULLY_QUALIFIED,
5958
];
6059

6160
if (in_array($tokens[$previousIndex]['code'], $relevantTokens, true) === false) {
6261
return;
6362
}
6463

65-
// Special case: T_NAME_FULLY_QUALIFIED is only a "relevant" token when it is for a FQN true/false/null.
66-
if ($tokens[$previousIndex]['code'] === T_NAME_FULLY_QUALIFIED) {
67-
$compareReadyKeyword = strtolower($tokens[$previousIndex]['content']);
68-
if ($compareReadyKeyword !== '\true'
69-
&& $compareReadyKeyword !== '\false'
70-
&& $compareReadyKeyword !== '\null'
71-
) {
72-
return;
73-
}
74-
}
75-
7664
if ($tokens[$previousIndex]['code'] === T_CLOSE_SHORT_ARRAY) {
7765
$previousIndex = $tokens[$previousIndex]['bracket_opener'];
7866
if ($this->isArrayStatic($phpcsFile, $previousIndex) === false) {
@@ -185,21 +173,10 @@ public function isArrayStatic(File $phpcsFile, $arrayToken)
185173
continue;
186174
}
187175

188-
// Special case: T_NAME_FULLY_QUALIFIED is only a "static" token when it is for a FQN true/false/null.
189-
if ($tokens[$i]['code'] === T_NAME_FULLY_QUALIFIED) {
190-
$compareReadyKeyword = strtolower($tokens[$i]['content']);
191-
if ($compareReadyKeyword === '\true'
192-
|| $compareReadyKeyword === '\false'
193-
|| $compareReadyKeyword === '\null'
194-
) {
195-
continue;
196-
}
197-
}
198-
199176
if (isset($staticTokens[$tokens[$i]['code']]) === false) {
200177
return false;
201178
}
202-
}//end for
179+
}
203180

204181
return true;
205182

src/Standards/Generic/Sniffs/PHP/LowerCaseConstantSniff.php

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,6 @@ public function register()
6060
{
6161
$targets = $this->targets;
6262

63-
// Allow for "fully qualified" true/false/null.
64-
$targets[] = T_NAME_FULLY_QUALIFIED;
65-
6663
// Register scope modifiers to filter out property type declarations.
6764
$targets += Tokens::SCOPE_MODIFIERS;
6865
$targets[] = T_VAR;
@@ -99,13 +96,6 @@ public function process(File $phpcsFile, $stackPtr)
9996
{
10097
$tokens = $phpcsFile->getTokens();
10198

102-
// If this is a fully qualified name, check if it is FQN true/false/null.
103-
if ($tokens[$stackPtr]['code'] === T_NAME_FULLY_QUALIFIED
104-
&& $this->isFQNTrueFalseNull($phpcsFile, $stackPtr) === false
105-
) {
106-
return;
107-
}
108-
10999
// Skip over potential type declarations for constants.
110100
if ($tokens[$stackPtr]['code'] === T_CONST) {
111101
// Constant must always have a value assigned to it, so we can just look for the assignment
@@ -190,10 +180,7 @@ public function process(File $phpcsFile, $stackPtr)
190180
}
191181

192182
for ($i = $param['default_token']; $i < $paramEnd; $i++) {
193-
if (isset($this->targets[$tokens[$i]['code']]) === true
194-
|| ($tokens[$i]['code'] === T_NAME_FULLY_QUALIFIED
195-
&& $this->isFQNTrueFalseNull($phpcsFile, $i) === true)
196-
) {
183+
if (isset($this->targets[$tokens[$i]['code']]) === true) {
197184
$this->processConstant($phpcsFile, $i);
198185
}
199186
}
@@ -209,28 +196,6 @@ public function process(File $phpcsFile, $stackPtr)
209196
}//end process()
210197

211198

212-
/**
213-
* Check if a fully qualified name is a fully qualified true/false/null.
214-
*
215-
* @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.
216-
* @param int $stackPtr The position of the T_NAME_FULLY_QUALIFIED token in the
217-
* stack passed in $tokens.
218-
*
219-
* @return bool
220-
*/
221-
protected function isFQNTrueFalseNull(File $phpcsFile, $stackPtr)
222-
{
223-
$tokens = $phpcsFile->getTokens();
224-
225-
// Check for fully qualified true/false/null only.
226-
$compareReadyKeyword = strtolower($tokens[$stackPtr]['content']);
227-
return ($compareReadyKeyword === '\true'
228-
|| $compareReadyKeyword === '\false'
229-
|| $compareReadyKeyword === '\null');
230-
231-
}//end isFQNTrueFalseNull()
232-
233-
234199
/**
235200
* Processes a non-type declaration constant.
236201
*

src/Standards/PEAR/Sniffs/Functions/ValidDefaultValueSniff.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,14 @@ public function process(File $phpcsFile, $stackPtr)
5454
}
5555

5656
if (array_key_exists('default', $param) === true) {
57-
$defaultFound = true;
57+
$defaultFound = true;
58+
$defaultValueLc = strtolower($param['default']);
5859
// Check if the arg is type hinted and using NULL for the default.
5960
// This does not make the argument optional - it just allows NULL
6061
// to be passed in.
61-
if ($param['type_hint'] !== '' && strtolower($param['default']) === 'null') {
62+
if ($param['type_hint'] !== ''
63+
&& ($defaultValueLc === 'null' || $defaultValueLc === '\null')
64+
) {
6265
$defaultFound = false;
6366
}
6467

src/Standards/PEAR/Tests/Functions/ValidDefaultValueUnitTest.1.inc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,3 +114,7 @@ class ConstructorPropertyPromotionMixedWithNormalParams {
114114
mixed $requiredParam,
115115
) {}
116116
}
117+
118+
// Safeguard correct handling of FQN null as default value.
119+
function foo(Foo $foo = \null, $bar) {}
120+
function foo(Foo $foo = \null, Foz $foz = \NULL, $bar = true, $baz) {}

src/Standards/PEAR/Tests/Functions/ValidDefaultValueUnitTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ public function getErrorList($testFile='')
4646
101 => 1,
4747
106 => 1,
4848
114 => 1,
49+
120 => 1,
4950
];
5051

5152
default:

src/Standards/PSR2/Tests/ControlStructures/SwitchDeclarationUnitTest.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ switch ($sContext)
252252
case 'SOMETHING':
253253
case 'CONSTANT':
254254
do_something();
255-
break;
255+
\exit();
256256
case 'GLOBAL':
257257
case 'GLOBAL1':
258258
do_something();

src/Standards/PSR2/Tests/ControlStructures/SwitchDeclarationUnitTest.inc.fixed

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ switch ($sContext)
255255
case 'SOMETHING':
256256
case 'CONSTANT':
257257
do_something();
258-
break;
258+
\exit();
259259
case 'GLOBAL':
260260
case 'GLOBAL1':
261261
do_something();

src/Standards/Squiz/Sniffs/Operators/ComparisonOperatorUsageSniff.php

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -174,13 +174,6 @@ public function process(File $phpcsFile, $stackPtr)
174174
$foundBooleans++;
175175
}
176176

177-
if ($tokens[$i]['code'] === T_NAME_FULLY_QUALIFIED) {
178-
$compareReadyKeyword = strtolower($tokens[$i]['content']);
179-
if ($compareReadyKeyword === '\true' || $compareReadyKeyword === '\false') {
180-
$foundBooleans++;
181-
}
182-
}
183-
184177
if ($tokens[$i]['code'] === T_BOOLEAN_AND
185178
|| $tokens[$i]['code'] === T_BOOLEAN_OR
186179
) {

src/Standards/Squiz/Tests/ControlStructures/SwitchDeclarationUnitTest.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ case '3':
5858
break;
5959
case '4':
6060
$case = '4';
61-
break;
61+
\exit;
6262
default:
6363
$case = null;
6464
break;

0 commit comments

Comments
 (0)