Skip to content

Commit 513b816

Browse files
committed
Merge branch 'master' into 3.0
2 parents 8bba8fa + 571e27b commit 513b816

File tree

7 files changed

+168
-7
lines changed

7 files changed

+168
-7
lines changed

package.xml

Lines changed: 98 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ http://pear.php.net/dtd/package-2.0.xsd">
1414
<email>[email protected]</email>
1515
<active>yes</active>
1616
</lead>
17-
<date>2016-07-20</date>
18-
<time>13:30:00</time>
17+
<date>2016-09-02</date>
18+
<time>09:44:00</time>
1919
<version>
2020
<release>3.0.0a2</release>
2121
<api>3.0.0a2</api>
@@ -77,6 +77,8 @@ http://pear.php.net/dtd/package-2.0.xsd">
7777
-- Default remains FALSE, so newlines are not allowed
7878
-- Override the "ignoreNewlines" setting in a ruleset.xml file to change
7979
-- Thanks to Alex Howansky for the patch
80+
- Squiz.Scope.MethodScope now sniffs traits as well as classes and interfaces
81+
-- Thanks to Jesse Donat for the patch
8082
- PHPCBF is now able to fix Squiz.SelfMemberReference.IncorrectCase errors
8183
-- Thanks to Nikola Kovacs for the patch
8284
- PHPCBF is now able to fix Squiz.Commenting.VariableComment.IncorrectVarType
@@ -93,6 +95,8 @@ http://pear.php.net/dtd/package-2.0.xsd">
9395
-- The format of the PHP version is the same as the PHP_VERSION_ID constant (e.g., 50403 for version 5.4.3)
9496
-- Supported sniffs are Generic.PHP.DisallowAlternativePHPTags, PSR1.Classes.ClassDeclaration, Squiz.Commenting.FunctionComment
9597
-- Thanks to Finlay Beaton for the patch
98+
- Fixed bug #985 : Duplicate class definition detection generates false-positives in media queries
99+
-- Thanks to Raphael Horber for the patch
96100
- Fixed bug #1014 : Squiz VariableCommentSniff doesn't always detect a missing comment
97101
- Fixed bug #1066 : Undefined index: quiet in CLI.php during unit test run with -v command line arg
98102
- Fixed bug #1072 : Squiz.SelfMemberReference.NotUsed not detected if leading namespace separator is used
@@ -1554,6 +1558,8 @@ http://pear.php.net/dtd/package-2.0.xsd">
15541558
<install as="CodeSniffer/Core/AllTests.php" name="tests/Core/AllTests.php" />
15551559
<install as="CodeSniffer/Core/IsCamelCapsTest.php" name="tests/Core/IsCamelCapsTest.php" />
15561560
<install as="CodeSniffer/Core/ErrorSuppressionTest.php" name="tests/Core/ErrorSuppressionTest.php" />
1561+
<install as="CodeSniffer/Core/File/FindExtendedClassNameTest.php" name="tests/Core/File/FindExtendedClassNameTest.php" />
1562+
<install as="CodeSniffer/Core/File/FindImplementedInterfaceNamesTest.php" name="tests/Core/File/FindImplementedInterfaceNamesTest.php" />
15571563
<install as="CodeSniffer/Core/File/GetMethodParametersTest.php" name="tests/Core/File/GetMethodParametersTest.php" />
15581564
<install as="CodeSniffer/Standards/AllSniffs.php" name="tests/Standards/AllSniffs.php" />
15591565
<install as="CodeSniffer/Standards/AbstractSniffUnitTest.php" name="tests/Standards/AbstractSniffUnitTest.php" />
@@ -1571,6 +1577,8 @@ http://pear.php.net/dtd/package-2.0.xsd">
15711577
<install as="CodeSniffer/Core/AllTests.php" name="tests/Core/AllTests.php" />
15721578
<install as="CodeSniffer/Core/IsCamelCapsTest.php" name="tests/Core/IsCamelCapsTest.php" />
15731579
<install as="CodeSniffer/Core/ErrorSuppressionTest.php" name="tests/Core/ErrorSuppressionTest.php" />
1580+
<install as="CodeSniffer/Core/File/FindExtendedClassNameTest.php" name="tests/Core/File/FindExtendedClassNameTest.php" />
1581+
<install as="CodeSniffer/Core/File/FindImplementedInterfaceNamesTest.php" name="tests/Core/File/FindImplementedInterfaceNamesTest.php" />
15741582
<install as="CodeSniffer/Core/File/GetMethodParametersTest.php" name="tests/Core/File/GetMethodParametersTest.php" />
15751583
<install as="CodeSniffer/Standards/AllSniffs.php" name="tests/Standards/AllSniffs.php" />
15761584
<install as="CodeSniffer/Standards/AbstractSniffUnitTest.php" name="tests/Standards/AbstractSniffUnitTest.php" />
@@ -1665,6 +1673,94 @@ http://pear.php.net/dtd/package-2.0.xsd">
16651673
-- Hooks for version control systems will no longer be maintained within the PHPCS project
16661674
</notes>
16671675
</release>
1676+
<release>
1677+
<version>
1678+
<release>2.7.0</release>
1679+
<api>2.7.0</api>
1680+
</version>
1681+
<stability>
1682+
<release>stable</release>
1683+
<api>stable</api>
1684+
</stability>
1685+
<date>2016-09-02</date>
1686+
<license uri="https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt">BSD License</license>
1687+
<notes>
1688+
- Added --file-list command line argument to allow a list of files and directories to be specified in an external file
1689+
-- Useful is you have a generated list of files to check that would be too long for the command line
1690+
-- File and directory paths are listed one per line
1691+
-- Usage is: phpcs --file-list=/path/to/file-list ...
1692+
-- Thanks to Blotzu for the patch
1693+
- Values set using @codingStandardsChangeSetting comments can now contain spaces
1694+
- Sniff unit tests can now specify a list of test files instead of letting the runner pick them (request #1078)
1695+
-- Useful if a sniff needs to exclude files based on the environment, or is checking filenames
1696+
-- Override the new getTestFiles() method to specify your own list of test files
1697+
- Generic.Functions.OpeningFunctionBraceKernighanRitchie now ignores spacing for function return types
1698+
-- The sniff code Generic.Functions.OpeningFunctionBraceKernighanRitchie.SpaceAfterBracket has been removed
1699+
-- Replaced by Generic.Functions.OpeningFunctionBraceKernighanRitchie.SpaceBeforeBrace
1700+
-- The new error message is slightly clearer as it indicates that a single space is needed before the brace
1701+
- Squiz.Commenting.LongConditionClosingComment now allows for the length of a code block to be configured
1702+
-- Set the lineLimit property (default is 20) in your ruleset.xml file to set the code block length
1703+
-- When the code block length is reached, the sniff will enforce a closing comment after the closing brace
1704+
-- Thanks to Juliette Reinders Folmer for the patch
1705+
- Squiz.Commenting.LongConditionClosingComment now allows for the end comment format to be configured
1706+
-- Set the commentFormat property (default is "//end %s") in your ruleset.xml file to set the format
1707+
-- The placeholder %s will be replaced with the type of condition opener, e.g., "//end foreach"
1708+
-- Thanks to Juliette Reinders Folmer for the patch
1709+
- Generic.PHPForbiddenFunctions now allows forbidden functions to have mixed case
1710+
-- Previously, it would only do a strtolower comparison
1711+
-- Error message now shows what case was found in the code and what the correct case should be
1712+
-- Thanks to Juliette Reinders Folmer for the patch
1713+
- Added Generic.Classes.OpeningBraceSameLine to ensure opening brace of class/interface/trait is on the same line as the declaration
1714+
-- Thanks to Juliette Reinders Folmer for the patch
1715+
- Added Generic.PHP.BacktickOperator to ban the use of the backtick operator for running shell commands
1716+
-- Thanks to Juliette Reinders Folmer for the patch
1717+
- Added Generic.PHP.DisallowAlternativePHPTags to ban the use of alternate PHP tags
1718+
-- Thanks to Juliette Reinders Folmer for the patch
1719+
- Squiz.WhiteSpace.LanguageConstructSpacing no longer checks for spaces if parenthesis are being used (request #1062)
1720+
-- Makes this sniff more compatibile with those that check parenthesis spacing of function calls
1721+
- Squiz.WhiteSpace.ObjectOperatorSpacing now has a setting to ignore newline characters around object operators
1722+
-- Default remains FALSE, so newlines are not allowed
1723+
-- Override the "ignoreNewlines" setting in a ruleset.xml file to change
1724+
-- Thanks to Alex Howansky for the patch
1725+
- Squiz.Scope.MethodScope now sniffs traits as well as classes and interfaces
1726+
-- Thanks to Jesse Donat for the patch
1727+
- PHPCBF is now able to fix Squiz.SelfMemberReference.IncorrectCase errors
1728+
-- Thanks to Nikola Kovacs for the patch
1729+
- PHPCBF is now able to fix Squiz.Commenting.VariableComment.IncorrectVarType
1730+
-- Thanks to Walt Sorensen for the patch
1731+
- PHPCBF is now able to fix Generic.PHP.DisallowShortOpenTag
1732+
-- Thanks to Juliette Reinders Folmer for the patch
1733+
- Improved the formatting of the end brace when auto fixing InlineControlStructure errors (request #1121)
1734+
- Generic.Functions.OpeningFunctionBraceKernighanRitchie.BraceOnNewLine fix no longer leaves blank line after brace (request #1085)
1735+
- Generic UpperCaseConstantNameSniff now allows lowercase namespaces in constant definitions
1736+
-- Thanks to Daniel Schniepp for the patch
1737+
- Squiz DoubleQuoteUsageSniff is now more tolerant of syntax errors caused by mismatched string tokens
1738+
- A few sniffs that produce errors based on the current PHP version can now be told to run using a specific PHP version
1739+
-- Set the php_version config var using --config-set, --runtime-set, or in a ruleset to specify a specific PHP version
1740+
-- The format of the PHP version is the same as the PHP_VERSION_ID constant (e.g., 50403 for version 5.4.3)
1741+
-- Supported sniffs are Generic.PHP.DisallowAlternativePHPTags, PSR1.Classes.ClassDeclaration, Squiz.Commenting.FunctionComment
1742+
-- Thanks to Finlay Beaton for the patch
1743+
- Fixed bug #985 : Duplicate class definition detection generates false-positives in media queries
1744+
-- Thanks to Raphael Horber for the patch
1745+
- Fixed bug #1014 : Squiz VariableCommentSniff doesn't always detect a missing comment
1746+
- Fixed bug #1066 : Undefined index: quiet in CLI.php during unit test run with -v command line arg
1747+
- Fixed bug #1072 : Squiz.SelfMemberReference.NotUsed not detected if leading namespace separator is used
1748+
- Fixed bug #1089 : Rulesets cannot be loaded if the path contains urlencoded characters
1749+
- Fixed bug #1091 : PEAR and Squiz FunctionComment sniffs throw errors for some invalid @param line formats
1750+
- Fixed bug #1092 : PEAR.Functions.ValidDefaultValue should not flag type hinted methods with a NULL default argument
1751+
- Fixed bug #1095 : Generic LineEndings sniff replaces tabs with spaces with --tab-width is set
1752+
- Fixed bug #1096 : Squiz FunctionDeclarationArgumentSpacing gives incorrect error/fix when variadic operator is followed by a space
1753+
- Fixed bug #1099 : Group use declarations are incorrectly fixed by the PSR2 standard
1754+
-- Thanks to Jason McCreary for the patch
1755+
- Fixed bug #1101 : Incorrect indent errors when breaking out of PHP inside an IF statement
1756+
- Fixed bug #1102 : Squiz.Formatting.OperatorBracket.MissingBrackets faulty bracketing fix
1757+
- Fixed bug #1109 : Wrong scope indent reported in anonymous class
1758+
- Fixed bug #1112 : File docblock not recognized when require_once follows it
1759+
- Fixed bug #1120 : InlineControlStructureSniff does not handle auto-fixing for control structures that make function calls
1760+
- Fixed bug #1124 : Squiz.Operators.ComparisonOperatorUsage does not detect bracketed conditions for inline IF statements
1761+
-- Thanks to Raphael Horber for the patch
1762+
</notes>
1763+
</release>
16681764
<release>
16691765
<version>
16701766
<release>2.6.2</release>

src/Standards/Squiz/Sniffs/CSS/DuplicateClassDefinitionSniff.php

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
use PHP_CodeSniffer\Sniffs\Sniff;
1313
use PHP_CodeSniffer\Files\File;
14+
use PHP_CodeSniffer\Util\Tokens;
1415

1516
class DuplicateClassDefinitionSniff implements Sniff
1617
{
@@ -56,15 +57,28 @@ public function process(File $phpcsFile, $stackPtr)
5657
return;
5758
}
5859

60+
// Save the class names in a "scope",
61+
// to prevent false positives with @media blocks.
62+
$scope = 'main';
63+
5964
$find = array(
6065
T_CLOSE_CURLY_BRACKET,
66+
T_OPEN_CURLY_BRACKET,
6167
T_COMMENT,
6268
T_OPEN_TAG,
6369
);
6470

6571
while ($next !== false) {
6672
$prev = $phpcsFile->findPrevious($find, ($next - 1));
6773

74+
// Check if an inner block was closed.
75+
$beforePrev = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($prev - 1), null, true);
76+
if ($beforePrev !== false
77+
&& $tokens[$beforePrev]['code'] === T_CLOSE_CURLY_BRACKET
78+
) {
79+
$scope = 'main';
80+
}
81+
6882
// Create a sorted name for the class so we can compare classes
6983
// even when the individual names are all over the place.
7084
$name = '';
@@ -81,13 +95,16 @@ public function process(File $phpcsFile, $stackPtr)
8195
sort($names);
8296
$name = implode(',', $names);
8397

84-
if (isset($classNames[$name]) === true) {
85-
$first = $classNames[$name];
98+
if ($name{0} === '@') {
99+
// Media block has its own "scope".
100+
$scope = $name;
101+
} else if (isset($classNames[$scope][$name]) === true) {
102+
$first = $classNames[$scope][$name];
86103
$error = 'Duplicate class definition found; first defined on line %s';
87104
$data = array($tokens[$first]['line']);
88105
$phpcsFile->addError($error, $next, 'Found', $data);
89106
} else {
90-
$classNames[$name] = $next;
107+
$classNames[$scope][$name] = $next;
91108
}
92109

93110
$next = $phpcsFile->findNext(T_OPEN_CURLY_BRACKET, ($next + 1));

src/Standards/Squiz/Sniffs/Scope/MethodScopeSniff.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class MethodScopeSniff extends AbstractScopeSniff
2222
*/
2323
public function __construct()
2424
{
25-
parent::__construct(array(T_CLASS, T_INTERFACE), array(T_FUNCTION));
25+
parent::__construct(array(T_CLASS, T_INTERFACE, T_TRAIT), array(T_FUNCTION));
2626

2727
}//end __construct()
2828

src/Standards/Squiz/Tests/CSS/DuplicateClassDefinitionUnitTest.css

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,40 @@
3131

3232
.YourClass, .MyClass, .OurClass {
3333
}
34+
35+
36+
.ClassAtTopOfMediaBlock {
37+
}
38+
39+
@media print {
40+
.ClassAtTopOfMediaBlock {
41+
}
42+
43+
.ClassInMultipleMediaBlocks {
44+
}
45+
}
46+
47+
.ClassNotAtTopOfMediaBlock {
48+
}
49+
50+
@media handheld {
51+
.SameClassInMediaBlock {
52+
}
53+
54+
.ClassNotAtTopOfMediaBlock {
55+
}
56+
57+
.SameClassInMediaBlock {
58+
}
59+
}
60+
61+
@media braille {
62+
.PlaceholderClass {
63+
}
64+
65+
.ClassNotAtTopOfMediaBlock {
66+
}
67+
68+
.ClassInMultipleMediaBlocks {
69+
}
70+
}

src/Standards/Squiz/Tests/CSS/DuplicateClassDefinitionUnitTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ public function getErrorList()
2828
return array(
2929
9 => 1,
3030
29 => 1,
31+
57 => 1,
3132
);
3233

3334
}//end getErrorList()

src/Standards/Squiz/Tests/Scope/MethodScopeUnitTest.inc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,10 @@ class Closure_Test {
2525
function test() {
2626
$foo = function() { echo 'foo'; };
2727
}
28+
29+
trait Trait_Test {
30+
function func1() {}
31+
public function func1() {}
32+
private function func1() {}
33+
protected function func1() {}
34+
}

src/Standards/Squiz/Tests/Scope/MethodScopeUnitTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@ class MethodScopeUnitTest extends AbstractSniffUnitTest
2525
*/
2626
public function getErrorList()
2727
{
28-
return array(6 => 1);
28+
return array(
29+
6 => 1,
30+
30 => 1,
31+
);
2932

3033
}//end getErrorList()
3134

0 commit comments

Comments
 (0)