Skip to content

Commit 2ca6cf5

Browse files
committed
Fixed bug #1669 : Temporary expression proceeded by curly brace is detected as function call
1 parent 3c2d0a0 commit 2ca6cf5

File tree

6 files changed

+54
-74
lines changed

6 files changed

+54
-74
lines changed

package.xml

Lines changed: 3 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -17,86 +17,16 @@ http://pear.php.net/dtd/package-2.0.xsd">
1717
<date>2017-09-20</date>
1818
<time>08:44:00</time>
1919
<version>
20-
<release>3.1.0</release>
21-
<api>3.1.0</api>
20+
<release>3.1.1</release>
21+
<api>3.1.1</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-
- This release includes a change to support newer versions of PHPUnit (versions 4, 5, and 6 are now supported)
30-
-- The custom PHP_CodeSniffer test runner now requires a bootstrap file
31-
-- Developers with custom standards using the PHP_CodeSniffer test runner will need to do one of the following:
32-
--- run your unit tests from the PHP_CodeSniffer root dir so the bootstrap file is included
33-
--- specify the PHP_CodeSniffer bootstrap file on the command line: phpunit --bootstrap=/path/to/phpcs/tests/bootstrap.php
34-
--- require the PHP_CodeSniffer bootstrap file from your own bootstrap file
35-
-- If you don't run PHP_CodeSniffer unit tests, this change will not affect you
36-
-- Thanks to Juliette Reinders Folmer for the patch
37-
38-
- A phpcs.xml or phpcs.xml.dist file now takes precedence over the default_standard config setting
39-
-- Thanks to Björn Fischer for the patch
40-
- Both phpcs.xml and phpcs.xml.dist files can now be prefixed with a dot (request #1566)
41-
-- The order that the files are searched is: .phpcs.xml, .phpcs.xml.dist, phpcs.xml, phpcs.xml.dist
42-
- The autoloader will now search for files during unit tests runs from the same locations as during normal phpcs runs
43-
-- Allows for easier unit testing of custom standards that use helper classes or custom namespaces
44-
- Include patterns for sniffs now use OR logic instead of AND logic
45-
-- Previously, a file had to be in each of the include patterns to be processed by a sniff
46-
-- Now, a file has to only be in at least one of the patterns
47-
-- This change reflects the original intention of the feature
48-
- PHPCS will now follow symlinks under the list of checked directories
49-
-- This previously only worked if you specified the path to a symlink on the command line
50-
- Output from --config-show, --config-set, and --config-delete now includes the path to the loaded config file
51-
- PHPCS now cleanly exits if its config file is not readable
52-
-- Previously, a combination of PHP notices and PHPCS errors would be generated
53-
- Comment tokens that start with /** are now always tokenized as docblocks
54-
-- Thanks to Michał Bundyra for the patch
55-
- The PHP-supplied T_YIELD and T_YIELD_FROM token have been replicated for older PHP versions
56-
-- Thanks to Michał Bundyra for the patch
57-
- Added new Generic.CodeAnalysis.AssignmentInCondition sniff to warn about variable assignments inside conditions
58-
-- Thanks to Juliette Reinders Folmer for the contribution
59-
- Added Generic.Files.OneObjectStructurePerFile sniff to ensure there is a single class/interface/trait per file
60-
-- Thanks to Mponos George for the contribution
61-
- Function call sniffs now check variable function names and self/static object creation
62-
-- Specific sniffs are Generic.Functions.FunctionCallArgumentSpacing, PEAR.Functions.FunctionCallSignature, and PSR2.Methods.FunctionCallSignature
63-
-- Thanks to Michał Bundyra for the patch
64-
- Generic.Files.LineLength can now be configured to ignore all comment lines, no matter their length
65-
-- Set the ignoreComments property to TRUE (default is FALSE) in your ruleset.xml file to enable this
66-
-- Thanks to Juliette Reinders Folmer for the patch
67-
- Generic.PHP.LowerCaseKeyword now checks self, parent, yield, yield from, and closure (function) keywords
68-
-- Thanks to Michał Bundyra for the patch
69-
- PEAR.Functions.FunctionDeclaration now removes a blank line if it creates one by moving the curly brace during fixing
70-
- Squiz.Commenting.FunctionCommentThrowTag now supports PHP 7.1 multi catch exceptions
71-
- Squiz.Formatting.OperatorBracket no longer throws errors for PHP 7.1 multi catch exceptions
72-
- Squiz.Commenting.LongConditionClosingComment now supports finally statements
73-
- Squiz.Formatting.OperatorBracket now correctly fixes pipe separated flags
74-
- Squiz.Formatting.OperatorBracket now correctly fixes statements containing short array syntax
75-
- Squiz.PHP.EmbeddedPhp now properly fixes cases where the only content in an embedded PHP block is a comment
76-
-- Thanks to Juliette Reinders Folmer for the patch
77-
- Squiz.WhiteSpace.ControlStructureSpacing now ignores comments when checking blank lines at the top of control structures
78-
- Squiz.WhiteSpace.ObjectOperatorSpacing now detects and fixes spaces around double colons
79-
-- Thanks to Julius Šmatavičius for the patch
80-
- Squiz.WhiteSpace.MemberVarSpacing can now be configured to check any number of blank lines between member vars
81-
-- Set the spacing property (default is 1) in your ruleset.xml file to set the spacing
82-
- Squiz.WhiteSpace.MemberVarSpacing can now be configured to check a different number of blank lines before the first member var
83-
-- Set the spacingBeforeFirst property (default is 1) in your ruleset.xml file to set the spacing
84-
- Added a new PHP_CodeSniffer\Util\Tokens::$ooScopeTokens static member var for quickly checking object scope
85-
-- Includes T_CLASS, T_ANON_CLASS, T_INTERFACE, and T_TRAIT
86-
-- Thanks to Juliette Reinders Folmer for the patch
87-
- PHP_CodeSniffer\Files\File::findExtendedClassName() now supports extended interfaces
88-
-- Thanks to Martin Hujer for the patch
89-
- Fixed bug #1550 : Squiz.Commenting.FunctionComment false positive when function contains closure
90-
- Fixed bug #1577 : Generic.InlineControlStructureSniff breaks with a comment between body and condition in do while loops
91-
- Fixed bug #1581 : Sniffs not loaded when one-standard directories are being registered in installed_paths
92-
- Fixed bug #1591 : Autoloader failing to load arbitrary files when installed_paths only set via a custom ruleset
93-
- Fixed bug #1605 : Squiz.WhiteSpace.OperatorSpacing false positive on unary minus after comment
94-
-- Thanks to Juliette Reinders Folmer for the patch
95-
- Fixed bug #1615 : Uncaught RuntimeException when phpcbf fails to fix files
96-
- Fixed bug #1637 : Generic.WhiteSpaceScopeIndent closure argument indenting incorrect with multi-line strings
97-
- Fixed bug #1638 : Squiz.WhiteSpace.ScopeClosingBrace closure argument indenting incorrect with multi-line strings
98-
- Fixed bug #1640 : Squiz.Strings.DoubleQuoteUsage replaces tabs with spaces when fixing
99-
-- Thanks to Juliette Reinders Folmer for the patch
29+
- Fixed bug #1669 : Temporary expression proceeded by curly brace is detected as function call
10030
</notes>
10131
<contents>
10232
<dir name="/">

src/Config.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class Config
2323
*
2424
* @var string
2525
*/
26-
const VERSION = '3.1.0';
26+
const VERSION = '3.1.1';
2727

2828
/**
2929
* Package stability; either stable, beta or alpha.

src/Standards/Generic/Sniffs/Functions/FunctionCallArgumentSpacingSniff.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,13 @@ public function process(File $phpcsFile, $stackPtr)
6161
return;
6262
}
6363

64+
if ($tokens[$stackPtr]['code'] === T_CLOSE_CURLY_BRACKET
65+
&& isset($tokens[$stackPtr]['scope_condition']) === true
66+
) {
67+
// Not a function call.
68+
return;
69+
}
70+
6471
// If the next non-whitespace token after the function or method call
6572
// is not an opening parenthesis then it cant really be a *call*.
6673
$openBracket = $phpcsFile->findNext(Tokens::$emptyTokens, ($functionName + 1), null, true);

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,13 @@ public function process(File $phpcsFile, $stackPtr)
8888
$this->requiredSpacesBeforeClose = (int) $this->requiredSpacesBeforeClose;
8989
$tokens = $phpcsFile->getTokens();
9090

91+
if ($tokens[$stackPtr]['code'] === T_CLOSE_CURLY_BRACKET
92+
&& isset($tokens[$stackPtr]['scope_condition']) === true
93+
) {
94+
// Not a function call.
95+
return;
96+
}
97+
9198
// Find the next non-empty token.
9299
$openBracket = $phpcsFile->findNext(Tokens::$emptyTokens, ($stackPtr + 1), null, true);
93100

src/Standards/PEAR/Tests/Functions/FunctionCallSignatureUnitTest.inc

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,3 +350,21 @@ $obj->{$x}(1,
350350
'a','b'
351351
)('c',
352352
'd');
353+
354+
class Foo
355+
{
356+
public function bar($a, $b)
357+
{
358+
if (!$a || !$b) {
359+
return;
360+
}
361+
362+
(new stdClass())->a = $a;
363+
}
364+
}
365+
366+
(function ($a, $b) {
367+
return function ($c, $d) use ($a, $b) {
368+
echo $a, $b, $c, $d;
369+
};
370+
})('a','b')('c','d');

src/Standards/PEAR/Tests/Functions/FunctionCallSignatureUnitTest.inc.fixed

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,3 +363,21 @@ $obj->{$x}(
363363
'c',
364364
'd'
365365
);
366+
367+
class Foo
368+
{
369+
public function bar($a, $b)
370+
{
371+
if (!$a || !$b) {
372+
return;
373+
}
374+
375+
(new stdClass())->a = $a;
376+
}
377+
}
378+
379+
(function ($a, $b) {
380+
return function ($c, $d) use ($a, $b) {
381+
echo $a, $b, $c, $d;
382+
};
383+
})('a','b')('c','d');

0 commit comments

Comments
 (0)