Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into whitespace-incomp…
Browse files Browse the repository at this point in the history
…atibility
  • Loading branch information
fredden committed Jul 11, 2023
2 parents 8b9b9ea + d415500 commit 635cd00
Show file tree
Hide file tree
Showing 17 changed files with 416 additions and 18 deletions.
14 changes: 7 additions & 7 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ A clear and concise description of what you expected to happen.

## Versions (please complete the following information)

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

## Additional context
Add any other context about the problem here.
Expand Down
14 changes: 14 additions & 0 deletions package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,13 @@ http://pear.php.net/dtd/package-2.0.xsd">
- PSR-PER has been used to confirm the order of this keyword so it can be applied to PSR2 and PSR12 correctly
-- Thanks to Juliette Reinders Folmer (@jrfnl) for the patch
- Squiz.Formatting.OperatorBracket no longer reports false positives in match() structures
- Documentation has been added for the following sniffs:
-- PSR2.Files.ClosingTag
-- PSR2.Methods.FunctionCallSignature
-- PSR2.Methods.FunctionClosingBrace
-- Thanks to Atsushi Okui (@blue32a) for the patch
- Fixed bug #3557 : Squiz.Arrays.ArrayDeclaration will now ignore PHP 7.4 array unpacking when determining whether an array is associative
-- Thanks to Volker Dusch (@edorian) for the patch
- Fixed bug #3616 : Squiz.PHP.DisallowComparisonAssignment false positive for PHP 8 match expression
-- Thanks to Juliette Reinders Folmer (@jrfnl) for the patch
- Fixed bug #3618 : Generic.WhiteSpace.ArbitraryParenthesesSpacing false positive for return new parent()
Expand All @@ -96,10 +103,14 @@ http://pear.php.net/dtd/package-2.0.xsd">
-- Thanks to Juliette Reinders Folmer (@jrfnl) for the patch
- Fixed bug #3728 : PHP 8.2 | PSR1/SideEffects: allow for readonly classes
-- Thanks to Juliette Reinders Folmer (@jrfnl) for the patch
- Fixed bug #3776 : Generic/JSHint: error when JSHint is not available
-- Thanks to Dan Wallis (@fredden) for the patch
- Fixed bug #3777 : Squiz/NonExecutableCode: slew of bug fixes, mostly related to modern PHP
-- Thanks to Juliette Reinders Folmer (@jrfnl) for the patch
- Fixed bug #3779 : Squiz/LowercasePHPFunctions + Generic/ForbiddenFunctions: bug fix for class names in attributes
-- Thanks to Juliette Reinders Folmer (@jrfnl) for the patch
- Fixed bug #3785 : Squiz/FunctionComment: potential "Uninitialized string offset 0" when a type contains a duplicate pipe symbol
-- Thanks to Dan Wallis (@fredden) for the patch
- Fixed bug #3787 : PEAR/Squiz/[MultiLine]FunctionDeclaration: allow for PHP 8.1 new in initializers
-- Thanks to Juliette Reinders Folmer (@jrfnl) for the patch
- Fixed bug #3789 : Incorrect tokenization for ternary operator with match inside of it
Expand Down Expand Up @@ -1374,9 +1385,12 @@ http://pear.php.net/dtd/package-2.0.xsd">
<file baseinstalldir="PHP/CodeSniffer" name="SwitchDeclarationStandard.xml" role="php" />
</dir>
<dir name="Files">
<file baseinstalldir="PHP/CodeSniffer" name="ClosingTagStandard.xml" role="php" />
<file baseinstalldir="PHP/CodeSniffer" name="EndFileNewlineStandard.xml" role="php" />
</dir>
<dir name="Methods">
<file baseinstalldir="PHP/CodeSniffer" name="FunctionCallSignatureStandard.xml" role="php" />
<file baseinstalldir="PHP/CodeSniffer" name="FunctionClosingBraceStandard.xml" role="php" />
<file baseinstalldir="PHP/CodeSniffer" name="MethodDeclarationStandard.xml" role="php" />
</dir>
<dir name="Namespaces">
Expand Down
2 changes: 1 addition & 1 deletion src/Standards/Generic/Sniffs/Debug/JSHintSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function process(File $phpcsFile, $stackPtr)
{
$rhinoPath = Config::getExecutablePath('rhino');
$jshintPath = Config::getExecutablePath('jshint');
if ($rhinoPath === null && $jshintPath === null) {
if ($jshintPath === null) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Standards/Generic/Tests/Debug/JSHintUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ protected function shouldSkipTest()
{
$rhinoPath = Config::getExecutablePath('rhino');
$jshintPath = Config::getExecutablePath('jshint');
if ($rhinoPath === null && $jshintPath === null) {
if ($jshintPath === null) {
return true;
}

Expand Down
23 changes: 23 additions & 0 deletions src/Standards/PSR2/Docs/Files/ClosingTagStandard.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<documentation title="Closing Tag">
<standard>
<![CDATA[
Checks that the file does not end with a closing tag.
]]>
</standard>
<code_comparison>
<code title="Valid: Closing tag not used.">
<![CDATA[
<?php
echo 'Foo';
<em></em>
]]>
</code>
<code title="Invalid: Closing tag used.">
<![CDATA[
<?php
echo 'Foo';
<em>?></em>
]]>
</code>
</code_comparison>
</documentation>
107 changes: 107 additions & 0 deletions src/Standards/PSR2/Docs/Methods/FunctionCallSignatureStandard.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
<documentation title="Function Call Signature">
<standard>
<![CDATA[
Checks that the function call format is correct.
]]>
</standard>
<code_comparison>
<code title="Valid: Correct spacing is used around parentheses.">
<![CDATA[
foo<em></em>(<em></em>$bar, $baz<em></em>);
]]>
</code>
<code title="Invalid: Incorrect spacing used, too much space around the parentheses.">
<![CDATA[
foo<em> </em>(<em> </em>$bar, $baz<em> </em>);
]]>
</code>
</code_comparison>
<code_comparison>
<code title="Valid: Correct number of spaces used for indent in a multi-line function call.">
<![CDATA[
foo(
<em> </em>$bar,
<em> </em>$baz
);
]]>
</code>
<code title="Invalid: Incorrect number of spaces used for indent in a multi-line function call.">
<![CDATA[
foo(
<em> </em>$bar,
<em> </em>$baz
);
]]>
</code>
</code_comparison>
<code_comparison>
<code title="Valid: Closing parenthesis for a multi-line function call is on a new line after the last parameter.">
<![CDATA[
foo(
$bar,
$baz
<em>)</em>;
]]>
</code>
<code title="Invalid: Closing parenthesis for a multi-line function call is not on a new line after the last parameter.">
<![CDATA[
foo(
$bar,
$baz<em>)</em>;
]]>
</code>
</code_comparison>
<code_comparison>
<code title="Valid: The first argument of a multi-line function call is on a new line.">
<![CDATA[
foo(
<em>$bar</em>,
$baz
);
]]>
</code>
<code title="Invalid: The first argument of a multi-line function call is not on a new line.">
<![CDATA[
foo(<em>$bar</em>,
$baz
);
]]>
</code>
</code_comparison>
<code_comparison>
<code title="Valid: Only one argument per line in a multi-line function call.">
<![CDATA[
foo(
$bar,
<em>$baz</em>
);
]]>
</code>
<code title="Invalid: Two or more arguments per line in a multi-line function call.">
<![CDATA[
foo(
$bar, <em>$baz</em>
);
]]>
</code>
</code_comparison>
<code_comparison>
<code title="Valid: No blank lines in a multi-line function call.">
<![CDATA[
foo(
$bar,
$baz
);
]]>
</code>
<code title="Invalid: Blank line in multi-line function call.">
<![CDATA[
foo(
$bar,
<em></em>
$baz
);
]]>
</code>
</code_comparison>
</documentation>
26 changes: 26 additions & 0 deletions src/Standards/PSR2/Docs/Methods/FunctionClosingBraceStandard.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<documentation title="Function Closing Brace">
<standard>
<![CDATA[
Checks that the closing brace of a function goes directly after the body.
]]>
</standard>
<code_comparison>
<code title="Valid: Closing brace directly follows the function body.">
<![CDATA[
function foo()
{
echo 'foo';
<em>}</em>
]]>
</code>
<code title="Invalid: Blank line between the function body and the closing brace.">
<![CDATA[
function foo()
{
echo 'foo';
<em></em>
<em>}</em>
]]>
</code>
</code_comparison>
</documentation>
23 changes: 18 additions & 5 deletions src/Standards/Squiz/Sniffs/Arrays/ArrayDeclarationSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -430,9 +430,13 @@ public function processMultiLineArray($phpcsFile, $stackPtr, $arrayStart, $array
}

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

if ($keyUsed === false) {
Expand Down Expand Up @@ -470,8 +474,17 @@ public function processMultiLineArray($phpcsFile, $stackPtr, $arrayStart, $array
true
);

$indices[] = ['value' => $valueContent];
$singleUsed = true;
$indices[] = ['value' => $valueContent];
$usesArrayUnpacking = $phpcsFile->findPrevious(
Tokens::$emptyTokens,
($nextToken - 2),
null,
true
);
if ($tokens[$usesArrayUnpacking]['code'] !== T_ELLIPSIS) {
// Don't decide if an array is key => value indexed or not when PHP 7.4+ array unpacking is used.
$singleUsed = true;
}
}//end if

$lastToken = $nextToken;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,10 @@ protected function processParams(File $phpcsFile, $stackPtr, $commentStart)
$suggestedTypeNames = [];

foreach ($typeNames as $typeName) {
if ($typeName === '') {
continue;
}

// Strip nullable operator.
if ($typeName[0] === '?') {
$typeName = substr($typeName, 1);
Expand Down
47 changes: 45 additions & 2 deletions src/Standards/Squiz/Tests/Arrays/ArrayDeclarationUnitTest.1.inc
Original file line number Diff line number Diff line change
Expand Up @@ -475,14 +475,57 @@ yield array(
static fn () : string => '',
);

$foo = [
$foo = array(
'foo' => match ($anything) {
'foo' => 'bar',
default => null,
},
];
);

// Intentional syntax error.
$a = array(
'a' =>
);

// Safeguard correct errors for key/no key when PHP 7.4+ array unpacking is encountered.
$x = array(
...$a,
'foo' => 'bar',
);

$x = array(
'foo' => 'bar',
...$a,
);

$x = array(
'foo' => 'bar',
...$a,
'baz' => 'bar',
);

$x = array(
...$a,
'foo' => 'bar', // OK.
'bar', // NoKeySpecified Error (based on second entry).
);

$x = array(
...$a,
'bar', // OK.
'foo' => 'bar', // KeySpecified Error (based on second entry).
);

$x = array(
'foo' => 'bar',
...$a,
'baz' => 'bar',
'bar', // NoKeySpecified Error (based on first entry).
);

$x = array(
'bar',
...$a,
'bar',
'baz' => 'bar', // KeySpecified (based on first entry).
);
Loading

0 comments on commit 635cd00

Please sign in to comment.