Skip to content

Commit b8665d7

Browse files
author
dereuromark
committed
Merge remote-tracking branch 'remotes/origin/master' into develop
# Conflicts: # .travis.yml # PSR2R/Sniffs/Classes/BraceOnSameLineSniff.php # PSR2R/Sniffs/Classes/ClassCreateInstanceSniff.php # PSR2R/Sniffs/Classes/ClassFileNameSniff.php # PSR2R/Sniffs/Classes/InterfaceNameSniff.php # PSR2R/Sniffs/Classes/SelfAccessorSniff.php # PSR2R/Sniffs/Classes/TraitNameSniff.php # PSR2R/Sniffs/Commenting/DocBlockEndingSniff.php # PSR2R/Sniffs/Commenting/DocBlockParamAllowDefaultValueSniff.php # PSR2R/Sniffs/Commenting/DocBlockParamArraySniff.php # PSR2R/Sniffs/Commenting/DocBlockParamNoOpSniff.php # PSR2R/Sniffs/Commenting/DocBlockParamNotJustNullSniff.php # PSR2R/Sniffs/Commenting/DocBlockParamSniff.php # PSR2R/Sniffs/Commenting/DocBlockPipeSpacingSniff.php # PSR2R/Sniffs/Commenting/DocBlockReturnSelfSniff.php # PSR2R/Sniffs/Commenting/DocBlockReturnTagSniff.php # PSR2R/Sniffs/Commenting/DocBlockReturnVoidSniff.php # PSR2R/Sniffs/Commenting/DocBlockShortTypeSniff.php # PSR2R/Sniffs/Commenting/DocBlockVarSniff.php # PSR2R/Sniffs/Commenting/DocBlockVarWithoutNameSniff.php # PSR2R/Sniffs/Commenting/DocCommentSniff.php # PSR2R/Sniffs/Commenting/FullyQualifiedClassNameInDocBlockSniff.php # PSR2R/Sniffs/Commenting/InlineDocBlockSniff.php # PSR2R/Sniffs/Commenting/NoControlStructureEndCommentSniff.php # PSR2R/Sniffs/ControlStructures/ConditionalExpressionOrderSniff.php # PSR2R/Sniffs/ControlStructures/ControlStructureSpacingSniff.php # PSR2R/Sniffs/ControlStructures/ElseIfDeclarationSniff.php # PSR2R/Sniffs/ControlStructures/NoInlineAssignmentSniff.php # PSR2R/Sniffs/ControlStructures/SwitchDeclarationSniff.php # PSR2R/Sniffs/ControlStructures/TernarySpacingSniff.php # PSR2R/Sniffs/ControlStructures/UnneededElseSniff.php # PSR2R/Sniffs/Files/ClosingTagSniff.php # PSR2R/Sniffs/Files/EndFileNewlineSniff.php # PSR2R/Sniffs/Methods/MethodDeclarationSniff.php # PSR2R/Sniffs/Methods/MethodMultilineArgumentsSniff.php # PSR2R/Sniffs/Namespaces/NamespaceDeclarationSniff.php # PSR2R/Sniffs/Namespaces/NoInlineFullyQualifiedClassNameSniff.php # PSR2R/Sniffs/Namespaces/UnusedUseStatementSniff.php # PSR2R/Sniffs/Namespaces/UseDeclarationSniff.php # PSR2R/Sniffs/Namespaces/UseInAlphabeticalOrderSniff.php # PSR2R/Sniffs/PHP/DuplicateSemicolonSniff.php # PSR2R/Sniffs/PHP/ListCommaSniff.php # PSR2R/Sniffs/PHP/NoIsNullSniff.php # PSR2R/Sniffs/PHP/NoShortOpenTagSniff.php # PSR2R/Sniffs/PHP/PhpSapiConstantSniff.php # PSR2R/Sniffs/PHP/PreferCastOverFunctionSniff.php # PSR2R/Sniffs/PHP/PreferStaticOverSelfSniff.php # PSR2R/Sniffs/PHP/RemoveFunctionAliasSniff.php # PSR2R/Sniffs/PHP/ShortCastSniff.php # PSR2R/Sniffs/PHP/SingleQuoteSniff.php # PSR2R/Sniffs/WhiteSpace/ArraySpacingSniff.php # PSR2R/Sniffs/WhiteSpace/CastSpacingSniff.php # PSR2R/Sniffs/WhiteSpace/CommaSpacingSniff.php # PSR2R/Sniffs/WhiteSpace/ConcatenationSpacingSniff.php # PSR2R/Sniffs/WhiteSpace/DocBlockAlignmentSniff.php # PSR2R/Sniffs/WhiteSpace/EmptyEnclosingLineSniff.php # PSR2R/Sniffs/WhiteSpace/EmptyLinesSniff.php # PSR2R/Sniffs/WhiteSpace/LanguageConstructSpacingSniff.php # PSR2R/Sniffs/WhiteSpace/MethodSpacingSniff.php # PSR2R/Sniffs/WhiteSpace/ObjectAttributeSpacingSniff.php # PSR2R/Sniffs/WhiteSpace/OperatorSpacingSniff.php # PSR2R/Sniffs/WhiteSpace/TabAndSpaceSniff.php # PSR2R/Sniffs/WhiteSpace/TabIndentSniff.php # PSR2R/Sniffs/WhiteSpace/UnaryOperatorSpacingSniff.php # PSR2R/Tools/AbstractSniff.php # composer.json # tests/Sniffs/Commenting/FullyQualifiedClassNameInDocBlockSniffTest.php
2 parents bb811b2 + de1cd17 commit b8665d7

File tree

267 files changed

+8225
-1778
lines changed

Some content is hidden

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

267 files changed

+8225
-1778
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ script:
2424
- sh -c "if [ '$COVERALLS' = '1' ]; then phpunit --coverage-clover build/logs/clover.xml; fi"
2525
- sh -c "if [ '$COVERALLS' = '1' ]; then vendor/bin/coveralls -c .coveralls.yml -v; fi"
2626

27-
- sh -c "if [ '$PHPCS' = '1' ]; then vendor/bin/phpcs -p --extensions=php --standard=PSR2R/ruleset.xml --ignore=/vendor/,/tests/ . ; fi"
27+
- sh -c "if [ '$PHPCS' = '1' ]; then vendor/bin/phpcs -p --extensions=php --standard=PSR2R/ruleset.xml --ignore=vendor/,tests/files/,*.inc,*.fixed . ; fi"
2828

2929
notifications:
3030
email: false

PSR2R/Sniffs/Classes/BraceOnSameLineSniff.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,6 @@
1313
*/
1414
class BraceOnSameLineSniff implements Sniff {
1515

16-
/**
17-
* @inheritDoc
18-
*/
19-
public function register() {
20-
return [
21-
T_CLASS,
22-
T_INTERFACE,
23-
T_TRAIT,
24-
T_FUNCTION
25-
];
26-
}
27-
2816
/**
2917
* @inheritDoc
3018
*/
@@ -37,7 +25,7 @@ public function process(File $phpcsFile, $stackPtr) {
3725
}
3826

3927
$curlyBrace = $tokens[$stackPtr]['scope_opener'];
40-
$lastContent = $phpcsFile->findPrevious(T_WHITESPACE, ($curlyBrace - 1), $stackPtr, true);
28+
$lastContent = $phpcsFile->findPrevious(T_WHITESPACE, $curlyBrace - 1, $stackPtr, true);
4129
$classLine = $tokens[$lastContent]['line'];
4230
$braceLine = $tokens[$curlyBrace]['line'];
4331
if ($braceLine !== $classLine) {
@@ -59,4 +47,16 @@ public function process(File $phpcsFile, $stackPtr) {
5947
}
6048
}
6149

50+
/**
51+
* @inheritDoc
52+
*/
53+
public function register() {
54+
return [
55+
T_CLASS,
56+
T_INTERFACE,
57+
T_TRAIT,
58+
T_FUNCTION,
59+
];
60+
}
61+
6262
}

PSR2R/Sniffs/Classes/ClassCreateInstanceSniff.php

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
namespace PSR2R\Sniffs\Classes;
34

45
use PHP_CodeSniffer\Files\File;
@@ -7,13 +8,6 @@
78

89
class ClassCreateInstanceSniff extends AbstractSniff {
910

10-
/**
11-
* @inheritDoc
12-
*/
13-
public function register() {
14-
return [T_NEW];
15-
}
16-
1711
/**
1812
* @inheritDoc
1913
*/
@@ -28,7 +22,7 @@ public function process(File $phpcsFile, $stackPtr) {
2822
}
2923

3024
$error = 'Calling class constructors must always include parentheses';
31-
$constructorIndex = $phpcsFile->findNext(Tokens::$emptyTokens, ($stackPtr + 1), null, true, null, true);
25+
$constructorIndex = $phpcsFile->findNext(Tokens::$emptyTokens, $stackPtr + 1, null, true, null, true);
3226

3327
// We can only invoke the fixer if we know this is a static constructor function call.
3428
if ($tokens[$constructorIndex]['code'] !== T_STRING && $tokens[$constructorIndex]['code'] !== T_NS_SEPARATOR) {
@@ -41,14 +35,15 @@ public function process(File $phpcsFile, $stackPtr) {
4135
while (true) {
4236
$nextConstructorPart = $phpcsFile->findNext(
4337
Tokens::$emptyTokens,
44-
($nextConstructorPart + 1),
38+
$nextConstructorPart + 1,
4539
null,
4640
true,
4741
null,
4842
true
4943
);
5044
if ($nextConstructorPart === false
51-
|| ($tokens[$nextConstructorPart]['code'] !== T_STRING && $tokens[$nextConstructorPart]['code'] !== T_NS_SEPARATOR)
45+
|| ($tokens[$nextConstructorPart]['code'] !== T_STRING &&
46+
$tokens[$nextConstructorPart]['code'] !== T_NS_SEPARATOR)
5247
) {
5348
break;
5449
}
@@ -62,4 +57,11 @@ public function process(File $phpcsFile, $stackPtr) {
6257
}
6358
}
6459

60+
/**
61+
* @inheritDoc
62+
*/
63+
public function register() {
64+
return [T_NEW];
65+
}
66+
6567
}

PSR2R/Sniffs/Classes/ClassFileNameSniff.php

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
* @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
1313
* @link http://pear.php.net/package/PHP_CodeSniffer
1414
*/
15+
1516
namespace PSR2R\Sniffs\Classes;
1617

1718
use PHP_CodeSniffer\Files\File;
@@ -23,25 +24,15 @@
2324
* Tests that the file name and the name of the class contained within the file
2425
* match.
2526
*
26-
* @author Greg Sherwood <gsherwood@squiz.net>
27-
* @author Marc McIntyre <mmcintyre@squiz.net>
27+
* @author Greg Sherwood <gsherwood@squiz.net>
28+
* @author Marc McIntyre <mmcintyre@squiz.net>
2829
* @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600)
29-
* @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
30-
* @version Release: @package_version@
31-
* @link http://pear.php.net/package/PHP_CodeSniffer
30+
* @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
31+
* @version Release: @package_version@
32+
* @link http://pear.php.net/package/PHP_CodeSniffer
3233
*/
3334
class ClassFileNameSniff extends AbstractSniff {
3435

35-
/**
36-
* @inheritDoc
37-
*/
38-
public function register() {
39-
return [
40-
T_CLASS,
41-
T_INTERFACE,
42-
];
43-
}
44-
4536
/**
4637
* @inheritDoc
4738
*/
@@ -74,4 +65,14 @@ public function process(File $phpcsFile, $stackPtr) {
7465
}
7566
}
7667

68+
/**
69+
* @inheritDoc
70+
*/
71+
public function register() {
72+
return [
73+
T_CLASS,
74+
T_INTERFACE,
75+
];
76+
}
77+
7778
}
Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
namespace PSR2R\Sniffs\Classes;
34

45
use PHP_CodeSniffer\Files\File;
@@ -9,20 +10,13 @@
910
*/
1011
class InterfaceNameSniff extends AbstractSniff {
1112

12-
/**
13-
* @inheritDoc
14-
*/
15-
public function register() {
16-
return [T_INTERFACE];
17-
}
18-
1913
/**
2014
* @inheritDoc
2115
*/
2216
public function process(File $phpcsFile, $stackPtr) {
2317
$tokens = $phpcsFile->getTokens();
2418

25-
$nameIndex = $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 1), null, true);
19+
$nameIndex = $phpcsFile->findNext(T_WHITESPACE, $stackPtr + 1, null, true);
2620
$name = $tokens[$nameIndex]['content'];
2721
if (substr($name, -9) === 'Interface') {
2822
return;
@@ -32,4 +26,11 @@ public function process(File $phpcsFile, $stackPtr) {
3226
$phpcsFile->addWarning($warn, $nameIndex, 'MissingSuffix');
3327
}
3428

29+
/**
30+
* @inheritDoc
31+
*/
32+
public function register() {
33+
return [T_INTERFACE];
34+
}
35+
3536
}

PSR2R/Sniffs/Classes/PropertyDeclarationSniff.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@
99
/**
1010
* Verifies that properties are declared correctly.
1111
*
12-
* @author Greg Sherwood <gsherwood@squiz.net>
12+
* @author Greg Sherwood <gsherwood@squiz.net>
1313
* @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600)
14-
* @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
14+
* @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
1515
*
16-
* @version Release: @package_version@
16+
* @version Release: @package_version@
1717
*
18-
* @link http://pear.php.net/package/PHP_CodeSniffer
18+
* @link http://pear.php.net/package/PHP_CodeSniffer
1919
*/
2020
class PropertyDeclarationSniff extends AbstractVariableSniff {
2121
/**
@@ -29,7 +29,7 @@ protected function processMemberVar(File $phpcsFile, $stackPtr) {
2929
// repeat errors.
3030
$find = Tokens::$scopeModifiers;
3131
$find = array_merge($find, [T_VARIABLE, T_VAR, T_SEMICOLON]);
32-
$prev = $phpcsFile->findPrevious($find, ($stackPtr - 1));
32+
$prev = $phpcsFile->findPrevious($find, $stackPtr - 1);
3333
if ($tokens[$prev]['code'] === T_VARIABLE) {
3434
return;
3535
}
@@ -39,7 +39,7 @@ protected function processMemberVar(File $phpcsFile, $stackPtr) {
3939
$phpcsFile->addError($error, $stackPtr, 'VarUsed');
4040
}
4141

42-
$next = $phpcsFile->findNext([T_VARIABLE, T_SEMICOLON], ($stackPtr + 1));
42+
$next = $phpcsFile->findNext([T_VARIABLE, T_SEMICOLON], $stackPtr + 1);
4343
if ($tokens[$next]['code'] === T_VARIABLE) {
4444
$error = 'There must not be more than one property declared per statement';
4545
$phpcsFile->addError($error, $stackPtr, 'Multiple');

PSR2R/Sniffs/Classes/SelfAccessorSniff.php

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,6 @@
1616
*/
1717
class SelfAccessorSniff extends AbstractSniff {
1818

19-
/**
20-
* @inheritDoc
21-
*/
22-
public function register() {
23-
return [T_SELF, T_CLASS, T_INTERFACE, T_TRAIT];
24-
}
25-
2619
/**
2720
* @inheritDoc
2821
*/
@@ -40,7 +33,7 @@ public function process(File $phpcsFile, $stackPtr) {
4033
}
4134
$endIndex = $tokens[$stackPtr]['scope_closer'];
4235

43-
$nameIndex = $phpcsFile->findNext(Tokens::$emptyTokens, ($stackPtr + 1), null, true);
36+
$nameIndex = $phpcsFile->findNext(Tokens::$emptyTokens, $stackPtr + 1, null, true);
4437
if ($tokens[$nameIndex]['code'] !== T_STRING) {
4538
return;
4639
}
@@ -60,6 +53,13 @@ public function process(File $phpcsFile, $stackPtr) {
6053
}
6154
}
6255

56+
/**
57+
* @inheritDoc
58+
*/
59+
public function register() {
60+
return [T_SELF, T_CLASS, T_INTERFACE, T_TRAIT];
61+
}
62+
6363
/**
6464
* @param \PHP_CodeSniffer\Files\File $phpcsFile
6565
* @param int $stackPtr
@@ -73,7 +73,7 @@ protected function checkSelf(File $phpcsFile, $stackPtr) {
7373
return;
7474
}
7575

76-
$fix = $phpcsFile->addFixableError('Expected `self::`, got `' . $content . '::`', $stackPtr, 'SelfToStatic');
76+
$fix = $phpcsFile->addFixableError('Expected `self::`, got `' . $content . '::`', $stackPtr, 'ExpectedSelf1');
7777
if ($fix) {
7878
$phpcsFile->fixer->replaceToken($stackPtr, 'self');
7979
}
@@ -88,11 +88,11 @@ protected function checkSelf(File $phpcsFile, $stackPtr) {
8888
protected function checkNew(File $phpcsFile, $i, $name) {
8989
$tokens = $phpcsFile->getTokens();
9090

91-
$nextIndex = $phpcsFile->findNext(Tokens::$emptyTokens, ($i + 1), null, true);
91+
$nextIndex = $phpcsFile->findNext(Tokens::$emptyTokens, $i + 1, null, true);
9292
if ($tokens[$nextIndex]['code'] !== T_STRING) {
9393
return;
9494
}
95-
$openingBraceIndex = $phpcsFile->findNext(Tokens::$emptyTokens, ($nextIndex + 1), null, true);
95+
$openingBraceIndex = $phpcsFile->findNext(Tokens::$emptyTokens, $nextIndex + 1, null, true);
9696
if ($tokens[$openingBraceIndex]['code'] !== T_OPEN_PARENTHESIS) {
9797
return;
9898
}
@@ -102,44 +102,44 @@ protected function checkNew(File $phpcsFile, $i, $name) {
102102

103103
/**
104104
* @param \PHP_CodeSniffer\Files\File $phpcsFile
105-
* @param int $i
105+
* @param int $index
106106
* @param string $name
107107
* @return void
108108
*/
109-
protected function checkDoubleColon(File $phpcsFile, $i, $name) {
109+
protected function fixNameToSelf(File $phpcsFile, $index, $name) {
110110
$tokens = $phpcsFile->getTokens();
111111

112-
$prevIndex = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($i - 1), null, true);
113-
if ($tokens[$prevIndex]['code'] !== T_STRING) {
114-
return;
115-
}
116-
$possibleSeparatorIndex = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($prevIndex - 1), null, true);
117-
if ($tokens[$possibleSeparatorIndex]['code'] === T_NS_SEPARATOR) {
112+
$content = $tokens[$index]['content'];
113+
114+
if (strtolower($content) !== strtolower($name)) {
118115
return;
119116
}
120117

121-
$this->fixNameToSelf($phpcsFile, $prevIndex, $name);
118+
$fix = $phpcsFile->addFixableError('Expected `self::`, got `' . $content . '::`', $index, 'ExpectedSelf2');
119+
if ($fix) {
120+
$phpcsFile->fixer->replaceToken($index, 'self');
121+
}
122122
}
123123

124124
/**
125125
* @param \PHP_CodeSniffer\Files\File $phpcsFile
126-
* @param int $index
126+
* @param int $i
127127
* @param string $name
128128
* @return void
129129
*/
130-
protected function fixNameToSelf(File $phpcsFile, $index, $name) {
130+
protected function checkDoubleColon(File $phpcsFile, $i, $name) {
131131
$tokens = $phpcsFile->getTokens();
132132

133-
$content = $tokens[$index]['content'];
134-
135-
if (strtolower($content) !== strtolower($name)) {
133+
$prevIndex = $phpcsFile->findPrevious(Tokens::$emptyTokens, $i - 1, null, true);
134+
if ($tokens[$prevIndex]['code'] !== T_STRING) {
136135
return;
137136
}
138-
139-
$fix = $phpcsFile->addFixableError('Expected `self::`, got `' . $content . '::`', $index, 'DoubleColon');
140-
if ($fix) {
141-
$phpcsFile->fixer->replaceToken($index, 'self');
137+
$possibleSeparatorIndex = $phpcsFile->findPrevious(Tokens::$emptyTokens, $prevIndex - 1, null, true);
138+
if ($tokens[$possibleSeparatorIndex]['code'] === T_NS_SEPARATOR) {
139+
return;
142140
}
141+
142+
$this->fixNameToSelf($phpcsFile, $prevIndex, $name);
143143
}
144144

145145
}

0 commit comments

Comments
 (0)