Skip to content

Commit 18e188e

Browse files
committed
Merge remote-tracking branch 'upstream/master' into whitespace-incompatibility
2 parents 6d1b209 + ed8e00d commit 18e188e

File tree

75 files changed

+1125
-192
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+1125
-192
lines changed

.github/workflows/test.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,11 @@ jobs:
9797
# Set the "short_open_tag" ini to make sure specific conditions are tested.
9898
# Also turn on error_reporting to ensure all notices are shown.
9999
if [[ ${{ matrix.custom_ini }} == true && "${{ matrix.php }}" == '5.5' ]]; then
100-
echo '::set-output name=PHP_INI::error_reporting=-1, display_errors=On, date.timezone=Australia/Sydney, short_open_tag=On, asp_tags=On'
100+
echo 'PHP_INI=error_reporting=-1, display_errors=On, date.timezone=Australia/Sydney, short_open_tag=On, asp_tags=On' >> $GITHUB_OUTPUT
101101
elif [[ ${{ matrix.custom_ini }} == true && "${{ matrix.php }}" == '7.0' ]]; then
102-
echo '::set-output name=PHP_INI::error_reporting=-1, display_errors=On, date.timezone=Australia/Sydney, short_open_tag=On'
102+
echo 'PHP_INI=error_reporting=-1, display_errors=On, date.timezone=Australia/Sydney, short_open_tag=On' >> $GITHUB_OUTPUT
103103
else
104-
echo '::set-output name=PHP_INI::error_reporting=-1, display_errors=On'
104+
echo 'PHP_INI=error_reporting=-1, display_errors=On' >> $GITHUB_OUTPUT
105105
fi
106106
107107
- name: Install PHP

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
"type": "library",
55
"keywords": [
66
"phpcs",
7-
"standards"
7+
"standards",
8+
"static analysis"
89
],
910
"homepage": "https://github.com/squizlabs/PHP_CodeSniffer",
1011
"license": "BSD-3-Clause",

package.xml

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,35 @@ http://pear.php.net/dtd/package-2.0.xsd">
2626
</stability>
2727
<license uri="https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt">BSD 3-Clause License</license>
2828
<notes>
29+
- Newer versions of Composer will now suggest installing PHPCS using require-dev instead of require
30+
-- Thanks to Gary Jones (@GaryJones) for the patch
31+
- A custom Out Of Memory error will now be shown if PHPCS or PHPCBF run out of memory during a run
32+
-- Error message provides actionable information about how to fix the problem and ensures the error is not silent
33+
-- Thanks to Juliette Reinders Folmer (@jrfnl) and Alain Schlesser (@schlessera) for the patch
34+
- Generic.PHP.LowerCaseType sniff now correctly examines types inside arrow functions
35+
-- Thanks to Juliette Reinders Folmer (@jrfnl) for the patch
36+
- Squiz.Formatting.OperatorBracket no longer reports false positives in match() structures
2937
- Fixed bug #3616 : Squiz.PHP.DisallowComparisonAssignment false positive for PHP 8 match expression
3038
-- Thanks to Juliette Reinders Folmer (@jrfnl) for the patch
3139
- Fixed bug #3618 : Generic.WhiteSpace.ArbitraryParenthesesSpacing false positive for return new parent()
3240
-- Thanks to Juliette Reinders Folmer (@jrfnl) for the patch
41+
- Fixed bug #3632 : Short list not tokenized correctly in control structures without braces
42+
-- Thanks to Juliette Reinders Folmer (@jrfnl) for the patch
43+
- Fixed bug #3639 : Tokenizer not applying tab replacement to heredoc/nowdoc closers
44+
-- Thanks to Juliette Reinders Folmer (@jrfnl) for the patch
45+
- Fixed bug #3640 : Generic.WhiteSpace.DisallowTabIndent not reporting errors for PHP 7.3 flexible heredoc/nowdoc syntax
46+
-- Thanks to Juliette Reinders Folmer (@jrfnl) for the patch
47+
- Fixed bug #3645 : PHPCS can show 0 exit code when running in parallel even if child process has fatal error
48+
-- Thanks to Alex Panshin (@enl) for the patch
49+
- Fixed bug #3653 : False positives for match() in OperatorSpacingSniff
50+
-- Thanks to Jaroslav Hanslík (@kukulich) for the patch
51+
- Fixed bug #3666 : PEAR.Functions.FunctionCallSignature incorrect indent fix when checking mixed HTML/PHP files
52+
- Fixed bug #3668 : PSR12.Classes.ClassInstantiation.MissingParentheses false positive when instantiating parent classes
53+
-- Similar issues also fixed in Generic.Functions.FunctionCallArgumentSpacing and Squiz.Formatting.OperatorBracket
54+
-- Thanks to Juliette Reinders Folmer (@jrfnl) for the patch
55+
- Fixed bug #3672 : Incorrect ScopeIndent.IncorrectExact report for match inside array literal
56+
- Fixed bug #3694 : Generic.WhiteSpace.SpreadOperatorSpacingAfter does not ignore spread operator in PHP 8.1 first class callables
57+
-- Thanks to Juliette Reinders Folmer (@jrfnl) for the patch
3358
</notes>
3459
<contents>
3560
<dir name="/">
@@ -143,6 +168,10 @@ http://pear.php.net/dtd/package-2.0.xsd">
143168
<file baseinstalldir="" name="FinallyTest.php" role="test" />
144169
<file baseinstalldir="" name="GotoLabelTest.inc" role="test" />
145170
<file baseinstalldir="" name="GotoLabelTest.php" role="test" />
171+
<file baseinstalldir="" name="HeredocNowdocCloserTest.inc" role="test" />
172+
<file baseinstalldir="" name="HeredocNowdocCloserTest.php" role="test" />
173+
<file baseinstalldir="" name="HeredocStringTest.inc" role="test" />
174+
<file baseinstalldir="" name="HeredocStringTest.php" role="test" />
146175
<file baseinstalldir="" name="NamedFunctionCallArgumentsTest.inc" role="test" />
147176
<file baseinstalldir="" name="NamedFunctionCallArgumentsTest.php" role="test" />
148177
<file baseinstalldir="" name="NullsafeObjectOperatorTest.inc" role="test" />
@@ -785,6 +814,8 @@ http://pear.php.net/dtd/package-2.0.xsd">
785814
<file baseinstalldir="PHP/CodeSniffer" name="DisallowTabIndentUnitTest.1.inc.fixed" role="test" />
786815
<file baseinstalldir="PHP/CodeSniffer" name="DisallowTabIndentUnitTest.2.inc" role="test" />
787816
<file baseinstalldir="PHP/CodeSniffer" name="DisallowTabIndentUnitTest.2.inc.fixed" role="test" />
817+
<file baseinstalldir="PHP/CodeSniffer" name="DisallowTabIndentUnitTest.3.inc" role="test" />
818+
<file baseinstalldir="PHP/CodeSniffer" name="DisallowTabIndentUnitTest.3.inc.fixed" role="test" />
788819
<file baseinstalldir="PHP/CodeSniffer" name="DisallowTabIndentUnitTest.js" role="test" />
789820
<file baseinstalldir="PHP/CodeSniffer" name="DisallowTabIndentUnitTest.js.fixed" role="test" />
790821
<file baseinstalldir="PHP/CodeSniffer" name="DisallowTabIndentUnitTest.php" role="test" />
@@ -2116,6 +2147,10 @@ http://pear.php.net/dtd/package-2.0.xsd">
21162147
<install as="CodeSniffer/Core/Tokenizer/FinallyTest.inc" name="tests/Core/Tokenizer/FinallyTest.inc" />
21172148
<install as="CodeSniffer/Core/Tokenizer/GotoLabelTest.php" name="tests/Core/Tokenizer/GotoLabelTest.php" />
21182149
<install as="CodeSniffer/Core/Tokenizer/GotoLabelTest.inc" name="tests/Core/Tokenizer/GotoLabelTest.inc" />
2150+
<install as="CodeSniffer/Core/Tokenizer/HeredocNowdocCloserTest.php" name="tests/Core/Tokenizer/HeredocNowdocCloserTest.php" />
2151+
<install as="CodeSniffer/Core/Tokenizer/HeredocNowdocCloserTest.inc" name="tests/Core/Tokenizer/HeredocNowdocCloserTest.inc" />
2152+
<install as="CodeSniffer/Core/Tokenizer/HeredocStringTest.php" name="tests/Core/Tokenizer/HeredocStringTest.php" />
2153+
<install as="CodeSniffer/Core/Tokenizer/HeredocStringTest.inc" name="tests/Core/Tokenizer/HeredocStringTest.inc" />
21192154
<install as="CodeSniffer/Core/Tokenizer/NamedFunctionCallArgumentsTest.php" name="tests/Core/Tokenizer/NamedFunctionCallArgumentsTest.php" />
21202155
<install as="CodeSniffer/Core/Tokenizer/NamedFunctionCallArgumentsTest.inc" name="tests/Core/Tokenizer/NamedFunctionCallArgumentsTest.inc" />
21212156
<install as="CodeSniffer/Core/Tokenizer/NullsafeObjectOperatorTest.php" name="tests/Core/Tokenizer/NullsafeObjectOperatorTest.php" />
@@ -2220,6 +2255,10 @@ http://pear.php.net/dtd/package-2.0.xsd">
22202255
<install as="CodeSniffer/Core/Tokenizer/FinallyTest.inc" name="tests/Core/Tokenizer/FinallyTest.inc" />
22212256
<install as="CodeSniffer/Core/Tokenizer/GotoLabelTest.php" name="tests/Core/Tokenizer/GotoLabelTest.php" />
22222257
<install as="CodeSniffer/Core/Tokenizer/GotoLabelTest.inc" name="tests/Core/Tokenizer/GotoLabelTest.inc" />
2258+
<install as="CodeSniffer/Core/Tokenizer/HeredocNowdocCloserTest.php" name="tests/Core/Tokenizer/HeredocNowdocCloserTest.php" />
2259+
<install as="CodeSniffer/Core/Tokenizer/HeredocNowdocCloserTest.inc" name="tests/Core/Tokenizer/HeredocNowdocCloserTest.inc" />
2260+
<install as="CodeSniffer/Core/Tokenizer/HeredocStringTest.php" name="tests/Core/Tokenizer/HeredocStringTest.php" />
2261+
<install as="CodeSniffer/Core/Tokenizer/HeredocStringTest.inc" name="tests/Core/Tokenizer/HeredocStringTest.inc" />
22232262
<install as="CodeSniffer/Core/Tokenizer/NamedFunctionCallArgumentsTest.php" name="tests/Core/Tokenizer/NamedFunctionCallArgumentsTest.php" />
22242263
<install as="CodeSniffer/Core/Tokenizer/NamedFunctionCallArgumentsTest.inc" name="tests/Core/Tokenizer/NamedFunctionCallArgumentsTest.inc" />
22252264
<install as="CodeSniffer/Core/Tokenizer/NullsafeObjectOperatorTest.php" name="tests/Core/Tokenizer/NullsafeObjectOperatorTest.php" />
@@ -2245,6 +2284,49 @@ http://pear.php.net/dtd/package-2.0.xsd">
22452284
</filelist>
22462285
</phprelease>
22472286
<changelog>
2287+
<release>
2288+
<version>
2289+
<release>3.7.2</release>
2290+
<api>3.7.2</api>
2291+
</version>
2292+
<stability>
2293+
<release>stable</release>
2294+
<api>stable</api>
2295+
</stability>
2296+
<date>2023-02-23</date>
2297+
<license uri="https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt">BSD License</license>
2298+
<notes>
2299+
- Newer versions of Composer will now suggest installing PHPCS using require-dev instead of require
2300+
-- Thanks to Gary Jones (@GaryJones) for the patch
2301+
- A custom Out Of Memory error will now be shown if PHPCS or PHPCBF run out of memory during a run
2302+
-- Error message provides actionable information about how to fix the problem and ensures the error is not silent
2303+
-- Thanks to Juliette Reinders Folmer (@jrfnl) and Alain Schlesser (@schlessera) for the patch
2304+
- Generic.PHP.LowerCaseType sniff now correctly examines types inside arrow functions
2305+
-- Thanks to Juliette Reinders Folmer (@jrfnl) for the patch
2306+
- Squiz.Formatting.OperatorBracket no longer reports false positives in match() structures
2307+
- Fixed bug #3616 : Squiz.PHP.DisallowComparisonAssignment false positive for PHP 8 match expression
2308+
-- Thanks to Juliette Reinders Folmer (@jrfnl) for the patch
2309+
- Fixed bug #3618 : Generic.WhiteSpace.ArbitraryParenthesesSpacing false positive for return new parent()
2310+
-- Thanks to Juliette Reinders Folmer (@jrfnl) for the patch
2311+
- Fixed bug #3632 : Short list not tokenized correctly in control structures without braces
2312+
-- Thanks to Juliette Reinders Folmer (@jrfnl) for the patch
2313+
- Fixed bug #3639 : Tokenizer not applying tab replacement to heredoc/nowdoc closers
2314+
-- Thanks to Juliette Reinders Folmer (@jrfnl) for the patch
2315+
- Fixed bug #3640 : Generic.WhiteSpace.DisallowTabIndent not reporting errors for PHP 7.3 flexible heredoc/nowdoc syntax
2316+
-- Thanks to Juliette Reinders Folmer (@jrfnl) for the patch
2317+
- Fixed bug #3645 : PHPCS can show 0 exit code when running in parallel even if child process has fatal error
2318+
-- Thanks to Alex Panshin (@enl) for the patch
2319+
- Fixed bug #3653 : False positives for match() in OperatorSpacingSniff
2320+
-- Thanks to Jaroslav Hanslík (@kukulich) for the patch
2321+
- Fixed bug #3666 : PEAR.Functions.FunctionCallSignature incorrect indent fix when checking mixed HTML/PHP files
2322+
- Fixed bug #3668 : PSR12.Classes.ClassInstantiation.MissingParentheses false positive when instantiating parent classes
2323+
-- Similar issues also fixed in Generic.Functions.FunctionCallArgumentSpacing and Squiz.Formatting.OperatorBracket
2324+
-- Thanks to Juliette Reinders Folmer (@jrfnl) for the patch
2325+
- Fixed bug #3672 : Incorrect ScopeIndent.IncorrectExact report for match inside array literal
2326+
- Fixed bug #3694 : Generic.WhiteSpace.SpreadOperatorSpacingAfter does not ignore spread operator in PHP 8.1 first class callables
2327+
-- Thanks to Juliette Reinders Folmer (@jrfnl) for the patch
2328+
</notes>
2329+
</release>
22482330
<release>
22492331
<version>
22502332
<release>3.7.1</release>

src/Files/File.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1798,7 +1798,7 @@ public function getMemberProperties($stackPtr)
17981798
|| $this->tokens[$ptr]['code'] === T_ENUM)
17991799
) {
18001800
// T_VARIABLEs in interfaces/enums can actually be method arguments
1801-
// but they wont be seen as being inside the method because there
1801+
// but they won't be seen as being inside the method because there
18021802
// are no scope openers and closers for abstract methods. If it is in
18031803
// parentheses, we can be pretty sure it is a method argument.
18041804
if (isset($this->tokens[$stackPtr]['nested_parenthesis']) === false

src/Ruleset.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,12 @@ public function explain()
249249
// one last time and clear the output buffer.
250250
$sniffs[] = '';
251251

252-
echo PHP_EOL."The $this->name standard contains $sniffCount sniffs".PHP_EOL;
252+
$summaryLine = PHP_EOL."The $this->name standard contains 1 sniff".PHP_EOL;
253+
if ($sniffCount !== 1) {
254+
$summaryLine = str_replace('1 sniff', "$sniffCount sniffs", $summaryLine);
255+
}
256+
257+
echo $summaryLine;
253258

254259
ob_start();
255260

src/Runner.php

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ class Runner
5353
*/
5454
public function runPHPCS()
5555
{
56+
$this->registerOutOfMemoryShutdownMessage('phpcs');
57+
5658
try {
5759
Util\Timing::startTiming();
5860
Runner::checkRequirements();
@@ -153,6 +155,8 @@ public function runPHPCS()
153155
*/
154156
public function runPHPCBF()
155157
{
158+
$this->registerOutOfMemoryShutdownMessage('phpcbf');
159+
156160
if (defined('PHP_CODESNIFFER_CBF') === false) {
157161
define('PHP_CODESNIFFER_CBF', true);
158162
}
@@ -721,6 +725,11 @@ private function processChildProcs($childProcs)
721725
continue;
722726
}
723727

728+
$childProcessStatus = pcntl_wexitstatus($status);
729+
if ($childProcessStatus !== 0) {
730+
$success = false;
731+
}
732+
724733
$out = $childProcs[$pid];
725734
unset($childProcs[$pid]);
726735
if (file_exists($out) === false) {
@@ -886,4 +895,42 @@ public function printProgress(File $file, $numFiles, $numProcessed)
886895
}//end printProgress()
887896

888897

898+
/**
899+
* Registers a PHP shutdown function to provide a more informative out of memory error.
900+
*
901+
* @param string $command The command which was used to initiate the PHPCS run.
902+
*
903+
* @return void
904+
*/
905+
private function registerOutOfMemoryShutdownMessage($command)
906+
{
907+
// Allocate all needed memory beforehand as much as possible.
908+
$errorMsg = PHP_EOL.'The PHP_CodeSniffer "%1$s" command ran out of memory.'.PHP_EOL;
909+
$errorMsg .= 'Either raise the "memory_limit" of PHP in the php.ini file or raise the memory limit at runtime'.PHP_EOL;
910+
$errorMsg .= 'using `%1$s -d memory_limit=512M` (replace 512M with the desired memory limit).'.PHP_EOL;
911+
$errorMsg = sprintf($errorMsg, $command);
912+
$memoryError = 'Allowed memory size of';
913+
$errorArray = [
914+
'type' => 42,
915+
'message' => 'Some random dummy string to take up memory and take up some more memory and some more',
916+
'file' => 'Another random string, which would be a filename this time. Should be relatively long to allow for deeply nested files',
917+
'line' => 31427,
918+
];
919+
920+
register_shutdown_function(
921+
static function () use (
922+
$errorMsg,
923+
$memoryError,
924+
$errorArray
925+
) {
926+
$errorArray = error_get_last();
927+
if (is_array($errorArray) === true && strpos($errorArray['message'], $memoryError) !== false) {
928+
echo $errorMsg;
929+
}
930+
}
931+
);
932+
933+
}//end registerOutOfMemoryShutdownMessage()
934+
935+
889936
}//end class

src/Sniffs/AbstractArraySniff.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,9 @@ public function process(File $phpcsFile, $stackPtr)
104104
/**
105105
* Find next separator in array - either: comma or double arrow.
106106
*
107-
* @param File $phpcsFile The current file being checked.
108-
* @param int $ptr The position of current token.
109-
* @param int $arrayEnd The token that ends the array definition.
107+
* @param \PHP_CodeSniffer\Files\File $phpcsFile The current file being checked.
108+
* @param int $ptr The position of current token.
109+
* @param int $arrayEnd The token that ends the array definition.
110110
*
111111
* @return int
112112
*/

src/Standards/Generic/Docs/Classes/OpeningBraceSameLineStandard.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@ class Foo <em>{</em>
1515
<![CDATA[
1616
class Foo
1717
<em>{</em>
18+
}
19+
]]>
20+
</code>
21+
</code_comparison>
22+
<code_comparison>
23+
<code title="Valid: Opening brace is the last thing on the line.">
24+
<![CDATA[
25+
class Foo <em>{</em>
1826
}
1927
]]>
2028
</code>

src/Standards/Generic/Docs/Formatting/SpaceAfterNotStandard.xml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,10 @@
1010
if (!<em> </em>$someVar || !<em> </em>$x instanceOf stdClass) {};
1111
]]>
1212
</code>
13-
<code title="Invalid: A NOT operator not followed by whitespace.">
13+
<code title="Invalid: A NOT operator not followed by whitespace or followed by too much whitespace.">
1414
<![CDATA[
1515
if (!<em></em>$someVar || !<em></em>$x instanceOf stdClass) {};
16-
]]>
17-
</code>
18-
<code title="Invalid: A NOT operator followed by a new line or more than one space.">
19-
<![CDATA[
16+
2017
if (!<em> </em>$someVar || !<em>
2118
</em>$x instanceOf stdClass) {};
2219
]]>

src/Standards/Generic/Docs/WhiteSpace/ArbitraryParenthesesSpacingStandard.xml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,10 @@
1010
$a = (null !== $extra);
1111
]]>
1212
</code>
13-
<code title="Invalid: spaces on the inside of a set of arbitrary parentheses.">
13+
<code title="Invalid: spaces or new lines on the inside of a set of arbitrary parentheses.">
1414
<![CDATA[
1515
$a = ( null !== $extra );
16-
]]>
17-
</code>
18-
<code title="Invalid: new lines on the inside of a set of arbitrary parentheses.">
19-
<![CDATA[
16+
2017
$a = (
2118
null !== $extra
2219
);

0 commit comments

Comments
 (0)