Skip to content

Commit 635cd00

Browse files
committed
Merge remote-tracking branch 'upstream/master' into whitespace-incompatibility
2 parents 8b9b9ea + d415500 commit 635cd00

17 files changed

+416
-18
lines changed

.github/ISSUE_TEMPLATE/bug_report.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,13 @@ A clear and concise description of what you expected to happen.
4848

4949
## Versions (please complete the following information)
5050

51-
| | |
52-
|-------------------------|------------------------------------------------------------------------------|
53-
| Operating System | [e.g., Windows 10, MacOS 10.15] |
54-
| PHP version | [e.g., 7.2, 7.4] |
55-
| PHP_CodeSniffer version | [e.g., 3.5.5, master] |
56-
| Standard | [e.g., PSR2, PSR12, Squiz, custom] |
57-
| Install type | [e.g. Composer (global/local), PHAR, PEAR, git clone, other (please expand)] |
51+
| | |
52+
|-|-|
53+
| Operating System | [e.g., Windows 10, MacOS 10.15]
54+
| PHP version | [e.g., 7.2, 7.4]
55+
| PHP_CodeSniffer version | [e.g., 3.5.5, master]
56+
| Standard | [e.g., PSR2, PSR12, Squiz, custom]
57+
| Install type | [e.g. Composer (global/local), PHAR, PEAR, git clone, other (please expand)]
5858

5959
## Additional context
6060
Add any other context about the problem here.

package.xml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,13 @@ http://pear.php.net/dtd/package-2.0.xsd">
7171
- PSR-PER has been used to confirm the order of this keyword so it can be applied to PSR2 and PSR12 correctly
7272
-- Thanks to Juliette Reinders Folmer (@jrfnl) for the patch
7373
- Squiz.Formatting.OperatorBracket no longer reports false positives in match() structures
74+
- Documentation has been added for the following sniffs:
75+
-- PSR2.Files.ClosingTag
76+
-- PSR2.Methods.FunctionCallSignature
77+
-- PSR2.Methods.FunctionClosingBrace
78+
-- Thanks to Atsushi Okui (@blue32a) for the patch
79+
- Fixed bug #3557 : Squiz.Arrays.ArrayDeclaration will now ignore PHP 7.4 array unpacking when determining whether an array is associative
80+
-- Thanks to Volker Dusch (@edorian) for the patch
7481
- Fixed bug #3616 : Squiz.PHP.DisallowComparisonAssignment false positive for PHP 8 match expression
7582
-- Thanks to Juliette Reinders Folmer (@jrfnl) for the patch
7683
- Fixed bug #3618 : Generic.WhiteSpace.ArbitraryParenthesesSpacing false positive for return new parent()
@@ -96,10 +103,14 @@ http://pear.php.net/dtd/package-2.0.xsd">
96103
-- Thanks to Juliette Reinders Folmer (@jrfnl) for the patch
97104
- Fixed bug #3728 : PHP 8.2 | PSR1/SideEffects: allow for readonly classes
98105
-- Thanks to Juliette Reinders Folmer (@jrfnl) for the patch
106+
- Fixed bug #3776 : Generic/JSHint: error when JSHint is not available
107+
-- Thanks to Dan Wallis (@fredden) for the patch
99108
- Fixed bug #3777 : Squiz/NonExecutableCode: slew of bug fixes, mostly related to modern PHP
100109
-- Thanks to Juliette Reinders Folmer (@jrfnl) for the patch
101110
- Fixed bug #3779 : Squiz/LowercasePHPFunctions + Generic/ForbiddenFunctions: bug fix for class names in attributes
102111
-- Thanks to Juliette Reinders Folmer (@jrfnl) for the patch
112+
- Fixed bug #3785 : Squiz/FunctionComment: potential "Uninitialized string offset 0" when a type contains a duplicate pipe symbol
113+
-- Thanks to Dan Wallis (@fredden) for the patch
103114
- Fixed bug #3787 : PEAR/Squiz/[MultiLine]FunctionDeclaration: allow for PHP 8.1 new in initializers
104115
-- Thanks to Juliette Reinders Folmer (@jrfnl) for the patch
105116
- Fixed bug #3789 : Incorrect tokenization for ternary operator with match inside of it
@@ -1374,9 +1385,12 @@ http://pear.php.net/dtd/package-2.0.xsd">
13741385
<file baseinstalldir="PHP/CodeSniffer" name="SwitchDeclarationStandard.xml" role="php" />
13751386
</dir>
13761387
<dir name="Files">
1388+
<file baseinstalldir="PHP/CodeSniffer" name="ClosingTagStandard.xml" role="php" />
13771389
<file baseinstalldir="PHP/CodeSniffer" name="EndFileNewlineStandard.xml" role="php" />
13781390
</dir>
13791391
<dir name="Methods">
1392+
<file baseinstalldir="PHP/CodeSniffer" name="FunctionCallSignatureStandard.xml" role="php" />
1393+
<file baseinstalldir="PHP/CodeSniffer" name="FunctionClosingBraceStandard.xml" role="php" />
13801394
<file baseinstalldir="PHP/CodeSniffer" name="MethodDeclarationStandard.xml" role="php" />
13811395
</dir>
13821396
<dir name="Namespaces">

src/Standards/Generic/Sniffs/Debug/JSHintSniff.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public function process(File $phpcsFile, $stackPtr)
5252
{
5353
$rhinoPath = Config::getExecutablePath('rhino');
5454
$jshintPath = Config::getExecutablePath('jshint');
55-
if ($rhinoPath === null && $jshintPath === null) {
55+
if ($jshintPath === null) {
5656
return;
5757
}
5858

src/Standards/Generic/Tests/Debug/JSHintUnitTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ protected function shouldSkipTest()
2525
{
2626
$rhinoPath = Config::getExecutablePath('rhino');
2727
$jshintPath = Config::getExecutablePath('jshint');
28-
if ($rhinoPath === null && $jshintPath === null) {
28+
if ($jshintPath === null) {
2929
return true;
3030
}
3131

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<documentation title="Closing Tag">
2+
<standard>
3+
<![CDATA[
4+
Checks that the file does not end with a closing tag.
5+
]]>
6+
</standard>
7+
<code_comparison>
8+
<code title="Valid: Closing tag not used.">
9+
<![CDATA[
10+
<?php
11+
echo 'Foo';
12+
<em></em>
13+
]]>
14+
</code>
15+
<code title="Invalid: Closing tag used.">
16+
<![CDATA[
17+
<?php
18+
echo 'Foo';
19+
<em>?></em>
20+
]]>
21+
</code>
22+
</code_comparison>
23+
</documentation>
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
<documentation title="Function Call Signature">
2+
<standard>
3+
<![CDATA[
4+
Checks that the function call format is correct.
5+
]]>
6+
</standard>
7+
<code_comparison>
8+
<code title="Valid: Correct spacing is used around parentheses.">
9+
<![CDATA[
10+
foo<em></em>(<em></em>$bar, $baz<em></em>);
11+
]]>
12+
</code>
13+
<code title="Invalid: Incorrect spacing used, too much space around the parentheses.">
14+
<![CDATA[
15+
foo<em> </em>(<em> </em>$bar, $baz<em> </em>);
16+
]]>
17+
</code>
18+
</code_comparison>
19+
<code_comparison>
20+
<code title="Valid: Correct number of spaces used for indent in a multi-line function call.">
21+
<![CDATA[
22+
foo(
23+
<em> </em>$bar,
24+
<em> </em>$baz
25+
);
26+
]]>
27+
</code>
28+
<code title="Invalid: Incorrect number of spaces used for indent in a multi-line function call.">
29+
<![CDATA[
30+
foo(
31+
<em> </em>$bar,
32+
<em> </em>$baz
33+
);
34+
]]>
35+
</code>
36+
</code_comparison>
37+
<code_comparison>
38+
<code title="Valid: Closing parenthesis for a multi-line function call is on a new line after the last parameter.">
39+
<![CDATA[
40+
foo(
41+
$bar,
42+
$baz
43+
<em>)</em>;
44+
]]>
45+
</code>
46+
<code title="Invalid: Closing parenthesis for a multi-line function call is not on a new line after the last parameter.">
47+
<![CDATA[
48+
foo(
49+
$bar,
50+
$baz<em>)</em>;
51+
]]>
52+
</code>
53+
</code_comparison>
54+
<code_comparison>
55+
<code title="Valid: The first argument of a multi-line function call is on a new line.">
56+
<![CDATA[
57+
foo(
58+
<em>$bar</em>,
59+
$baz
60+
);
61+
]]>
62+
</code>
63+
<code title="Invalid: The first argument of a multi-line function call is not on a new line.">
64+
<![CDATA[
65+
foo(<em>$bar</em>,
66+
$baz
67+
);
68+
]]>
69+
</code>
70+
</code_comparison>
71+
<code_comparison>
72+
<code title="Valid: Only one argument per line in a multi-line function call.">
73+
<![CDATA[
74+
foo(
75+
$bar,
76+
<em>$baz</em>
77+
);
78+
]]>
79+
</code>
80+
<code title="Invalid: Two or more arguments per line in a multi-line function call.">
81+
<![CDATA[
82+
foo(
83+
$bar, <em>$baz</em>
84+
);
85+
]]>
86+
</code>
87+
</code_comparison>
88+
<code_comparison>
89+
<code title="Valid: No blank lines in a multi-line function call.">
90+
<![CDATA[
91+
foo(
92+
$bar,
93+
$baz
94+
);
95+
]]>
96+
</code>
97+
<code title="Invalid: Blank line in multi-line function call.">
98+
<![CDATA[
99+
foo(
100+
$bar,
101+
<em></em>
102+
$baz
103+
);
104+
]]>
105+
</code>
106+
</code_comparison>
107+
</documentation>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<documentation title="Function Closing Brace">
2+
<standard>
3+
<![CDATA[
4+
Checks that the closing brace of a function goes directly after the body.
5+
]]>
6+
</standard>
7+
<code_comparison>
8+
<code title="Valid: Closing brace directly follows the function body.">
9+
<![CDATA[
10+
function foo()
11+
{
12+
echo 'foo';
13+
<em>}</em>
14+
]]>
15+
</code>
16+
<code title="Invalid: Blank line between the function body and the closing brace.">
17+
<![CDATA[
18+
function foo()
19+
{
20+
echo 'foo';
21+
<em></em>
22+
<em>}</em>
23+
]]>
24+
</code>
25+
</code_comparison>
26+
</documentation>

src/Standards/Squiz/Sniffs/Arrays/ArrayDeclarationSniff.php

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -430,9 +430,13 @@ public function processMultiLineArray($phpcsFile, $stackPtr, $arrayStart, $array
430430
}
431431

432432
if ($keyUsed === true && $tokens[$lastToken]['code'] === T_COMMA) {
433-
$error = 'No key specified for array entry; first entry specifies key';
434-
$phpcsFile->addError($error, $nextToken, 'NoKeySpecified');
435-
return;
433+
$nextToken = $phpcsFile->findNext(Tokens::$emptyTokens, ($lastToken + 1), null, true);
434+
// Allow for PHP 7.4+ array unpacking within an array declaration.
435+
if ($tokens[$nextToken]['code'] !== T_ELLIPSIS) {
436+
$error = 'No key specified for array entry; first entry specifies key';
437+
$phpcsFile->addError($error, $nextToken, 'NoKeySpecified');
438+
return;
439+
}
436440
}
437441

438442
if ($keyUsed === false) {
@@ -470,8 +474,17 @@ public function processMultiLineArray($phpcsFile, $stackPtr, $arrayStart, $array
470474
true
471475
);
472476

473-
$indices[] = ['value' => $valueContent];
474-
$singleUsed = true;
477+
$indices[] = ['value' => $valueContent];
478+
$usesArrayUnpacking = $phpcsFile->findPrevious(
479+
Tokens::$emptyTokens,
480+
($nextToken - 2),
481+
null,
482+
true
483+
);
484+
if ($tokens[$usesArrayUnpacking]['code'] !== T_ELLIPSIS) {
485+
// Don't decide if an array is key => value indexed or not when PHP 7.4+ array unpacking is used.
486+
$singleUsed = true;
487+
}
475488
}//end if
476489

477490
$lastToken = $nextToken;

src/Standards/Squiz/Sniffs/Commenting/FunctionCommentSniff.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,10 @@ protected function processParams(File $phpcsFile, $stackPtr, $commentStart)
405405
$suggestedTypeNames = [];
406406

407407
foreach ($typeNames as $typeName) {
408+
if ($typeName === '') {
409+
continue;
410+
}
411+
408412
// Strip nullable operator.
409413
if ($typeName[0] === '?') {
410414
$typeName = substr($typeName, 1);

src/Standards/Squiz/Tests/Arrays/ArrayDeclarationUnitTest.1.inc

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -475,14 +475,57 @@ yield array(
475475
static fn () : string => '',
476476
);
477477

478-
$foo = [
478+
$foo = array(
479479
'foo' => match ($anything) {
480480
'foo' => 'bar',
481481
default => null,
482482
},
483-
];
483+
);
484484

485485
// Intentional syntax error.
486486
$a = array(
487487
'a' =>
488488
);
489+
490+
// Safeguard correct errors for key/no key when PHP 7.4+ array unpacking is encountered.
491+
$x = array(
492+
...$a,
493+
'foo' => 'bar',
494+
);
495+
496+
$x = array(
497+
'foo' => 'bar',
498+
...$a,
499+
);
500+
501+
$x = array(
502+
'foo' => 'bar',
503+
...$a,
504+
'baz' => 'bar',
505+
);
506+
507+
$x = array(
508+
...$a,
509+
'foo' => 'bar', // OK.
510+
'bar', // NoKeySpecified Error (based on second entry).
511+
);
512+
513+
$x = array(
514+
...$a,
515+
'bar', // OK.
516+
'foo' => 'bar', // KeySpecified Error (based on second entry).
517+
);
518+
519+
$x = array(
520+
'foo' => 'bar',
521+
...$a,
522+
'baz' => 'bar',
523+
'bar', // NoKeySpecified Error (based on first entry).
524+
);
525+
526+
$x = array(
527+
'bar',
528+
...$a,
529+
'bar',
530+
'baz' => 'bar', // KeySpecified (based on first entry).
531+
);

0 commit comments

Comments
 (0)