Skip to content

Commit 92a93e8

Browse files
committed
Merge branch 'feature/support-generics' of github.com:tm1000/PHP_CodeSniffer into feature/support-generics
2 parents a155e9b + da57fd3 commit 92a93e8

File tree

60 files changed

+675
-153
lines changed

Some content is hidden

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

60 files changed

+675
-153
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: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,42 @@ http://pear.php.net/dtd/package-2.0.xsd">
1717
<date>2022-06-18</date>
1818
<time>17:20:00</time>
1919
<version>
20-
<release>3.7.1</release>
21-
<api>3.7.1</api>
20+
<release>3.7.2</release>
21+
<api>3.7.2</api>
2222
</version>
2323
<stability>
2424
<release>stable</release>
2525
<api>stable</api>
2626
</stability>
2727
<license uri="https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt">BSD 3-Clause License</license>
2828
<notes>
29-
- Fixed bug #3609: Methods/constants with name empty/isset/unset are always reported as error
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
3035
-- Thanks to Juliette Reinders Folmer (@jrfnl) for the patch
36+
- Squiz.Formatting.OperatorBracket no longer reports false positives in match() structures
37+
- Fixed bug #3616 : Squiz.PHP.DisallowComparisonAssignment false positive for PHP 8 match expression
38+
-- Thanks to Juliette Reinders Folmer (@jrfnl) for the patch
39+
- Fixed bug #3618 : Generic.WhiteSpace.ArbitraryParenthesesSpacing false positive for return new parent()
40+
-- 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
3156
</notes>
3257
<contents>
3358
<dir name="/">
@@ -141,6 +166,8 @@ http://pear.php.net/dtd/package-2.0.xsd">
141166
<file baseinstalldir="" name="FinallyTest.php" role="test" />
142167
<file baseinstalldir="" name="GotoLabelTest.inc" role="test" />
143168
<file baseinstalldir="" name="GotoLabelTest.php" role="test" />
169+
<file baseinstalldir="" name="HeredocNowdocCloserTest.inc" role="test" />
170+
<file baseinstalldir="" name="HeredocNowdocCloserTest.php" role="test" />
144171
<file baseinstalldir="" name="NamedFunctionCallArgumentsTest.inc" role="test" />
145172
<file baseinstalldir="" name="NamedFunctionCallArgumentsTest.php" role="test" />
146173
<file baseinstalldir="" name="NullsafeObjectOperatorTest.inc" role="test" />
@@ -783,6 +810,8 @@ http://pear.php.net/dtd/package-2.0.xsd">
783810
<file baseinstalldir="PHP/CodeSniffer" name="DisallowTabIndentUnitTest.1.inc.fixed" role="test" />
784811
<file baseinstalldir="PHP/CodeSniffer" name="DisallowTabIndentUnitTest.2.inc" role="test" />
785812
<file baseinstalldir="PHP/CodeSniffer" name="DisallowTabIndentUnitTest.2.inc.fixed" role="test" />
813+
<file baseinstalldir="PHP/CodeSniffer" name="DisallowTabIndentUnitTest.3.inc" role="test" />
814+
<file baseinstalldir="PHP/CodeSniffer" name="DisallowTabIndentUnitTest.3.inc.fixed" role="test" />
786815
<file baseinstalldir="PHP/CodeSniffer" name="DisallowTabIndentUnitTest.js" role="test" />
787816
<file baseinstalldir="PHP/CodeSniffer" name="DisallowTabIndentUnitTest.js.fixed" role="test" />
788817
<file baseinstalldir="PHP/CodeSniffer" name="DisallowTabIndentUnitTest.php" role="test" />
@@ -2114,6 +2143,8 @@ http://pear.php.net/dtd/package-2.0.xsd">
21142143
<install as="CodeSniffer/Core/Tokenizer/FinallyTest.inc" name="tests/Core/Tokenizer/FinallyTest.inc" />
21152144
<install as="CodeSniffer/Core/Tokenizer/GotoLabelTest.php" name="tests/Core/Tokenizer/GotoLabelTest.php" />
21162145
<install as="CodeSniffer/Core/Tokenizer/GotoLabelTest.inc" name="tests/Core/Tokenizer/GotoLabelTest.inc" />
2146+
<install as="CodeSniffer/Core/Tokenizer/HeredocNowdocCloserTest.php" name="tests/Core/Tokenizer/HeredocNowdocCloserTest.php" />
2147+
<install as="CodeSniffer/Core/Tokenizer/HeredocNowdocCloserTest.inc" name="tests/Core/Tokenizer/HeredocNowdocCloserTest.inc" />
21172148
<install as="CodeSniffer/Core/Tokenizer/NamedFunctionCallArgumentsTest.php" name="tests/Core/Tokenizer/NamedFunctionCallArgumentsTest.php" />
21182149
<install as="CodeSniffer/Core/Tokenizer/NamedFunctionCallArgumentsTest.inc" name="tests/Core/Tokenizer/NamedFunctionCallArgumentsTest.inc" />
21192150
<install as="CodeSniffer/Core/Tokenizer/NullsafeObjectOperatorTest.php" name="tests/Core/Tokenizer/NullsafeObjectOperatorTest.php" />
@@ -2218,6 +2249,8 @@ http://pear.php.net/dtd/package-2.0.xsd">
22182249
<install as="CodeSniffer/Core/Tokenizer/FinallyTest.inc" name="tests/Core/Tokenizer/FinallyTest.inc" />
22192250
<install as="CodeSniffer/Core/Tokenizer/GotoLabelTest.php" name="tests/Core/Tokenizer/GotoLabelTest.php" />
22202251
<install as="CodeSniffer/Core/Tokenizer/GotoLabelTest.inc" name="tests/Core/Tokenizer/GotoLabelTest.inc" />
2252+
<install as="CodeSniffer/Core/Tokenizer/HeredocNowdocCloserTest.php" name="tests/Core/Tokenizer/HeredocNowdocCloserTest.php" />
2253+
<install as="CodeSniffer/Core/Tokenizer/HeredocNowdocCloserTest.inc" name="tests/Core/Tokenizer/HeredocNowdocCloserTest.inc" />
22212254
<install as="CodeSniffer/Core/Tokenizer/NamedFunctionCallArgumentsTest.php" name="tests/Core/Tokenizer/NamedFunctionCallArgumentsTest.php" />
22222255
<install as="CodeSniffer/Core/Tokenizer/NamedFunctionCallArgumentsTest.inc" name="tests/Core/Tokenizer/NamedFunctionCallArgumentsTest.inc" />
22232256
<install as="CodeSniffer/Core/Tokenizer/NullsafeObjectOperatorTest.php" name="tests/Core/Tokenizer/NullsafeObjectOperatorTest.php" />
@@ -2255,7 +2288,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
22552288
<date>2022-06-18</date>
22562289
<license uri="https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt">BSD License</license>
22572290
<notes>
2258-
- Fixed bug #3609: Methods/constants with name empty/isset/unset are always reported as error
2291+
- Fixed bug #3609 : Methods/constants with name empty/isset/unset are always reported as error
22592292
-- Thanks to Juliette Reinders Folmer (@jrfnl) for the patch
22602293
</notes>
22612294
</release>

src/Config.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ class Config
8080
*
8181
* @var string
8282
*/
83-
const VERSION = '3.7.1';
83+
const VERSION = '3.7.2';
8484

8585
/**
8686
* Package stability; either stable, beta or alpha.

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/Standards/Generic/Sniffs/Functions/FunctionCallArgumentSpacingSniff.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public function register()
3030
T_UNSET,
3131
T_SELF,
3232
T_STATIC,
33+
T_PARENT,
3334
T_VARIABLE,
3435
T_CLOSE_CURLY_BRACKET,
3536
T_CLOSE_PARENTHESIS,

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ public function register()
5252
$tokens = Tokens::$castTokens;
5353
$tokens[] = T_FUNCTION;
5454
$tokens[] = T_CLOSURE;
55+
$tokens[] = T_FN;
5556
$tokens[] = T_VARIABLE;
5657
return $tokens;
5758

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
namespace PHP_CodeSniffer\Standards\Generic\Sniffs\PHP;
1111

1212
use PHP_CodeSniffer\Files\File;
13-
use PHP_CodeSniffer\Sniffs\Sniff;
14-
use PHP_CodeSniffer\Util\Tokens;
1513

1614
class UpperCaseConstantSniff extends LowerCaseConstantSniff
1715
{

src/Standards/Generic/Sniffs/WhiteSpace/DisallowTabIndentSniff.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ public function process(File $phpcsFile, $stackPtr)
7676
T_DOC_COMMENT_WHITESPACE => true,
7777
T_DOC_COMMENT_STRING => true,
7878
T_COMMENT => true,
79+
T_END_HEREDOC => true,
80+
T_END_NOWDOC => true,
7981
];
8082

8183
for ($i = 0; $i < $phpcsFile->numTokens; $i++) {

src/Standards/Generic/Sniffs/WhiteSpace/ScopeIndentSniff.php

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -142,12 +142,13 @@ public function process(File $phpcsFile, $stackPtr)
142142
}
143143
}
144144

145-
$lastOpenTag = $stackPtr;
146-
$lastCloseTag = null;
147-
$openScopes = [];
148-
$adjustments = [];
149-
$setIndents = [];
150-
$disableExactEnd = 0;
145+
$lastOpenTag = $stackPtr;
146+
$lastCloseTag = null;
147+
$openScopes = [];
148+
$adjustments = [];
149+
$setIndents = [];
150+
$disableExactStack = [];
151+
$disableExactEnd = 0;
151152

152153
$tokens = $phpcsFile->getTokens();
153154
$first = $phpcsFile->findFirstOnLine(T_INLINE_HTML, $stackPtr);
@@ -232,6 +233,7 @@ public function process(File $phpcsFile, $stackPtr)
232233
if ($tokens[$i]['code'] === T_OPEN_PARENTHESIS
233234
&& isset($tokens[$i]['parenthesis_closer']) === true
234235
) {
236+
$disableExactStack[$tokens[$i]['parenthesis_closer']] = $tokens[$i]['parenthesis_closer'];
235237
$disableExactEnd = max($disableExactEnd, $tokens[$i]['parenthesis_closer']);
236238
if ($this->debug === true) {
237239
$line = $tokens[$i]['line'];
@@ -802,9 +804,17 @@ public function process(File $phpcsFile, $stackPtr)
802804
&& isset($tokens[$checkToken]['scope_opener']) === true
803805
) {
804806
$exact = true;
807+
805808
if ($disableExactEnd > $checkToken) {
806-
if ($tokens[$checkToken]['conditions'] === $tokens[$disableExactEnd]['conditions']) {
807-
$exact = false;
809+
foreach ($disableExactStack as $disableExactStackEnd) {
810+
if ($disableExactStackEnd < $checkToken) {
811+
continue;
812+
}
813+
814+
if ($tokens[$checkToken]['conditions'] === $tokens[$disableExactStackEnd]['conditions']) {
815+
$exact = false;
816+
break;
817+
}
808818
}
809819
}
810820

@@ -1035,6 +1045,7 @@ public function process(File $phpcsFile, $stackPtr)
10351045

10361046
// Don't check indents exactly between arrays as they tend to have custom rules.
10371047
if ($tokens[$i]['code'] === T_OPEN_SHORT_ARRAY) {
1048+
$disableExactStack[$tokens[$i]['bracket_closer']] = $tokens[$i]['bracket_closer'];
10381049
$disableExactEnd = max($disableExactEnd, $tokens[$i]['bracket_closer']);
10391050
if ($this->debug === true) {
10401051
$line = $tokens[$i]['line'];
@@ -1056,7 +1067,6 @@ public function process(File $phpcsFile, $stackPtr)
10561067
) {
10571068
if ($this->debug === true) {
10581069
$line = $tokens[$i]['line'];
1059-
$type = $tokens[$disableExactEnd]['type'];
10601070
echo "Here/nowdoc found on line $line".PHP_EOL;
10611071
}
10621072

0 commit comments

Comments
 (0)