Skip to content

Commit 1a846a0

Browse files
Merge pull request #3 from VincentLanglet/staging
Staging
2 parents b0bb443 + 76ba861 commit 1a846a0

Some content is hidden

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

41 files changed

+496
-399
lines changed

Symfony3Custom/Sniffs/Arrays/MultiLineArrayCommaSniff.php

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,16 @@
33
/**
44
* Throws warnings if the last item in a multi line array does not have a trailing comma
55
*/
6-
class Symfony3Custom_Sniffs_Arrays_MultiLineArrayCommaSniff
7-
implements PHP_CodeSniffer_Sniff
6+
class Symfony3Custom_Sniffs_Arrays_MultiLineArrayCommaSniff implements PHP_CodeSniffer_Sniff
87
{
98
/**
109
* A list of tokenizers this sniff supports.
1110
*
1211
* @var array
1312
*/
1413
public $supportedTokenizers = array(
15-
'PHP',
16-
);
14+
'PHP',
15+
);
1716

1817
/**
1918
* Returns an array of tokens this test wants to listen for.
@@ -23,10 +22,9 @@ class Symfony3Custom_Sniffs_Arrays_MultiLineArrayCommaSniff
2322
public function register()
2423
{
2524
return array(
26-
T_ARRAY,
27-
T_OPEN_SHORT_ARRAY,
28-
);
29-
25+
T_ARRAY,
26+
T_OPEN_SHORT_ARRAY,
27+
);
3028
}
3129

3230
/**
@@ -79,7 +77,12 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
7977
);
8078

8179
if ($fix === true) {
82-
$ptr = $phpcsFile->findPrevious(array(T_WHITESPACE, T_COMMENT), $closePtr-1, $stackPtr, true);
80+
$ptr = $phpcsFile->findPrevious(
81+
array(T_WHITESPACE, T_COMMENT),
82+
$closePtr - 1,
83+
$stackPtr,
84+
true
85+
);
8386
$phpcsFile->fixer->addContent($ptr, ',');
8487
$phpcsFile->fixer->endChangeset();
8588
}
@@ -89,7 +92,5 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
8992
}
9093
}
9194
}
92-
9395
}
94-
9596
}

Symfony3Custom/Sniffs/Classes/MultipleClassesOneFileSniff.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
* Throws errors if multiple classes are defined in a single file.
55
* Symfony coding standard specifies: "Define one class per file;"
66
*/
7-
class Symfony3Custom_Sniffs_Classes_MultipleClassesOneFileSniff
8-
implements PHP_CodeSniffer_Sniff
7+
class Symfony3Custom_Sniffs_Classes_MultipleClassesOneFileSniff implements PHP_CodeSniffer_Sniff
98
{
109
/**
1110
* The number of times the T_CLASS token is encountered in the file.

Symfony3Custom/Sniffs/Classes/PropertyDeclarationSniff.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
/**
44
* Throws warnings if properties are declared after methods
55
*/
6-
class Symfony3Custom_Sniffs_Classes_PropertyDeclarationSniff
7-
implements PHP_CodeSniffer_Sniff
6+
class Symfony3Custom_Sniffs_Classes_PropertyDeclarationSniff implements PHP_CodeSniffer_Sniff
87
{
98
/**
109
* A list of tokenizers this sniff supports.
@@ -54,7 +53,7 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
5453
$wantedTokens = array(
5554
T_PUBLIC,
5655
T_PROTECTED,
57-
T_PRIVATE
56+
T_PRIVATE,
5857
);
5958

6059
while ($scope) {
@@ -73,5 +72,4 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
7372
}
7473
}
7574
}
76-
7775
}

Symfony3Custom/Sniffs/Commenting/ClassCommentSniff.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@
2424
* <li>Check required and optional tags and the format of their content.</li>
2525
* </ul>
2626
*/
27-
class Symfony3Custom_Sniffs_Commenting_ClassCommentSniff
28-
extends PEAR_Sniffs_Commenting_ClassCommentSniff
27+
class Symfony3Custom_Sniffs_Commenting_ClassCommentSniff extends PEAR_Sniffs_Commenting_ClassCommentSniff
2928
{
3029
/**
3130
* Tags in correct order and related info.

Symfony3Custom/Sniffs/Commenting/DocCommentForbiddenTagsSniff.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,17 @@
33
/**
44
* Throws errors if forbidden tags are met.
55
*/
6-
class Symfony3Custom_Sniffs_Commenting_DocCommentForbiddenTagsSniff
7-
implements PHP_CodeSniffer_Sniff
6+
class Symfony3Custom_Sniffs_Commenting_DocCommentForbiddenTagsSniff implements PHP_CodeSniffer_Sniff
87
{
98
/**
109
* A list of PHPDoc tags that are forbidden.
1110
*
1211
* @var array
1312
*/
14-
public $tags = array('@package', '@subpackage');
13+
public $tags = array(
14+
'@package',
15+
'@subpackage',
16+
);
1517

1618
/**
1719
* A list of tokenizers this sniff supports.

Symfony3Custom/Sniffs/Commenting/DocCommentGroupSameTypeSniff.php

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
/**
44
* Throws errors if comments are not grouped by type with one blank line between them.
55
*/
6-
class Symfony3Custom_Sniffs_Commenting_DocCommentGroupSameTypeSniff
7-
implements PHP_CodeSniffer_Sniff
6+
class Symfony3Custom_Sniffs_Commenting_DocCommentGroupSameTypeSniff implements PHP_CodeSniffer_Sniff
87
{
98
/**
109
* A list of tokenizers this sniff supports.
@@ -42,15 +41,17 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
4241
if (false !== $previousString) {
4342
$previousStringLine = $tokens[$previousString]['line'];
4443
$commentTagLine = $tokens[$commentTag]['line'];
44+
4545
if ($previousType === $currentType) {
4646
if ($previousStringLine !== $commentTagLine - 1) {
4747
$fix = $phpcsFile->addFixableError(
4848
'Expected no empty lines '
49-
.'between annotations of the same type',
49+
. 'between annotations of the same type',
5050
$commentTag,
5151
'SameType'
5252
);
53-
if ($fix) {
53+
54+
if ($fix === true) {
5455
$phpcsFile->fixer->beginChangeset();
5556
$this->removeLines(
5657
$phpcsFile,
@@ -65,11 +66,12 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
6566
if ($previousStringLine !== $commentTagLine - 2) {
6667
$fix = $phpcsFile->addFixableError(
6768
'Expected exactly one empty line '
68-
.'between annotations of different types',
69+
. 'between annotations of different types',
6970
$commentTag,
7071
'DifferentType'
7172
);
72-
if ($fix) {
73+
74+
if ($fix === true) {
7375
$phpcsFile->fixer->beginChangeset();
7476
if ($previousStringLine === $commentTagLine - 1) {
7577
$firstOnLine = $phpcsFile->findFirstOnLine(
@@ -87,7 +89,7 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
8789
);
8890
$phpcsFile->fixer->addContentBefore(
8991
$firstOnLine,
90-
$content.$phpcsFile->eolChar
92+
$content . $phpcsFile->eolChar
9193
);
9294
} else {
9395
$this->removeLines(
@@ -120,10 +122,14 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
120122
* @return void
121123
*/
122124
protected function removeLines(
123-
PHP_CodeSniffer_File $phpcsFile, $fromPtr, $fromLine, $toLine
125+
PHP_CodeSniffer_File $phpcsFile,
126+
$fromPtr,
127+
$fromLine,
128+
$toLine
124129
) {
125130
$tokens = $phpcsFile->getTokens();
126-
for ($i = $fromPtr; ; $i++) {
131+
132+
for ($i = $fromPtr;; $i++) {
127133
if ($tokens[$i]['line'] > $toLine) {
128134
break;
129135
}

Symfony3Custom/Sniffs/Commenting/FunctionCommentSniff.php

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@
1515
* </li>
1616
* </ul>
1717
*/
18-
class Symfony3Custom_Sniffs_Commenting_FunctionCommentSniff
19-
extends PEAR_Sniffs_Commenting_FunctionCommentSniff
18+
class Symfony3Custom_Sniffs_Commenting_FunctionCommentSniff extends PEAR_Sniffs_Commenting_FunctionCommentSniff
2019
{
2120
/**
2221
* Processes this test, when one of its tokens is encountered.
@@ -90,6 +89,7 @@ protected function processReturn(
9089
$stackPtr,
9190
$tokens[$stackPtr]['scope_closer']
9291
);
92+
9393
for ($i = $start; $i < $tokens[$stackPtr]['scope_closer']; ++$i) {
9494
// Skip closures
9595
if ($tokens[$i]['code'] === T_CLOSURE) {
@@ -114,8 +114,11 @@ protected function processReturn(
114114
* @param int $stackPtr
115115
* @param int $commentStart
116116
*/
117-
protected function processWhitespace(PHP_CodeSniffer_File $phpcsFile, int $stackPtr, int $commentStart)
118-
{
117+
protected function processWhitespace(
118+
PHP_CodeSniffer_File $phpcsFile,
119+
$stackPtr,
120+
$commentStart
121+
) {
119122
$tokens = $phpcsFile->getTokens();
120123
$before = $phpcsFile->findPrevious(T_WHITESPACE, ($commentStart - 1), null, true);
121124

@@ -137,11 +140,11 @@ protected function processWhitespace(PHP_CodeSniffer_File $phpcsFile, int $stack
137140
if ($fix === true) {
138141
if ($found > 1) {
139142
$phpcsFile->fixer->beginChangeset();
143+
140144
for ($i = ($before + 1); $i < ($commentStart - 1); $i++) {
141145
$phpcsFile->fixer->replaceToken($i, '');
142146
}
143147

144-
$phpcsFile->fixer->replaceToken($i, $phpcsFile->eolChar);
145148
$phpcsFile->fixer->endChangeset();
146149
} else {
147150
// Try and maintain indentation.
@@ -162,7 +165,7 @@ protected function processWhitespace(PHP_CodeSniffer_File $phpcsFile, int $stack
162165
* @param int $stackPtr The position of the current token
163166
* in the stack passed in $tokens.
164167
*
165-
* @return boolean True if the comment is an inheritdoc
168+
* @return bool True if the comment is an inheritdoc
166169
*/
167170
protected function isInheritDoc(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
168171
{
@@ -201,7 +204,6 @@ protected function processParams(
201204
$this->processWhitespace($phpcsFile, $stackPtr, $commentStart);
202205

203206
parent::processParams($phpcsFile, $stackPtr, $commentStart);
204-
205207
}
206208

207209
/**
@@ -210,7 +212,7 @@ protected function processParams(
210212
* @param array $tokens Array of tokens
211213
* @param int $returnPos Stack position of the T_RETURN token to process
212214
*
213-
* @return boolean True if the return does not return anything
215+
* @return bool True if the return does not return anything
214216
*/
215217
protected function isMatchingReturn($tokens, $returnPos)
216218
{

Symfony3Custom/Sniffs/Formatting/BlankLineBeforeReturnSniff.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
* Symfony coding standard specifies: "Add a blank line before return statements,
66
* unless the return is alone inside a statement-group (like an if statement);"
77
*/
8-
class Symfony3Custom_Sniffs_Formatting_BlankLineBeforeReturnSniff
9-
implements PHP_CodeSniffer_Sniff
8+
class Symfony3Custom_Sniffs_Formatting_BlankLineBeforeReturnSniff implements PHP_CodeSniffer_Sniff
109
{
1110
/**
1211
* A list of tokenizers this sniff supports.
@@ -39,9 +38,9 @@ public function register()
3938
*/
4039
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
4140
{
42-
$tokens = $phpcsFile->getTokens();
43-
$current = $stackPtr;
44-
$previousLine = $tokens[$stackPtr]['line'] - 1;
41+
$tokens = $phpcsFile->getTokens();
42+
$current = $stackPtr;
43+
$previousLine = $tokens[$stackPtr]['line'] - 1;
4544
$prevLineTokens = array();
4645

4746
while ($current >= 0 && $tokens[$current]['line'] >= $previousLine) {
@@ -61,7 +60,7 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
6160
|| $prevLineTokens[0] === 'T_COLON')
6261
) {
6362
return;
64-
} else if (count($prevLineTokens) > 0) {
63+
} elseif (count($prevLineTokens) > 0) {
6564
$fix = $phpcsFile->addFixableError(
6665
'Missing blank line before return statement',
6766
$stackPtr,
@@ -71,7 +70,7 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
7170
if ($fix === true) {
7271
$phpcsFile->fixer->beginChangeset();
7372
$i = 1;
74-
while($tokens[$stackPtr-$i]['type'] == "T_WHITESPACE") {
73+
while ($tokens[$stackPtr-$i]['type'] == "T_WHITESPACE") {
7574
$i++;
7675
}
7776
$phpcsFile->fixer->addNewLine($stackPtr-$i);

Symfony3Custom/Sniffs/Functions/ScopeOrderSniff.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@
33
/**
44
* Throws warnings if properties are declared after methods
55
*/
6-
class Symfony3Custom_Sniffs_Functions_ScopeOrderSniff
7-
implements PHP_CodeSniffer_Sniff
6+
class Symfony3Custom_Sniffs_Functions_ScopeOrderSniff implements PHP_CodeSniffer_Sniff
87
{
9-
108
/**
119
* A list of tokenizers this sniff supports.
1210
*
@@ -83,11 +81,11 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
8381
$whitelisted
8482
)
8583
) {
86-
$current = array_keys($scopes, $tokens[$scope]['code']);
84+
$current = array_keys($scopes, $tokens[$scope]['code']);
8785
$current = $current[0];
8886

8987
$error = 'Declare public methods first,'
90-
.'then protected ones and finally private ones';
88+
. 'then protected ones and finally private ones';
9189

9290
if (isset($previous) && $current < $previous) {
9391
$phpcsFile->addError(
@@ -102,5 +100,4 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
102100
}
103101
}
104102
}
105-
106103
}

Symfony3Custom/Sniffs/NamingConventions/ValidClassNameSniff.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
/**
44
* Throws errors if symfony's naming conventions are not met.
55
*/
6-
class Symfony3Custom_Sniffs_NamingConventions_ValidClassNameSniff
7-
implements PHP_CodeSniffer_Sniff
6+
class Symfony3Custom_Sniffs_NamingConventions_ValidClassNameSniff implements PHP_CodeSniffer_Sniff
87
{
98
/**
109
* A list of tokenizers this sniff supports.
@@ -26,7 +25,7 @@ public function register()
2625
T_INTERFACE,
2726
T_TRAIT,
2827
T_EXTENDS,
29-
T_ABSTRACT
28+
T_ABSTRACT,
3029
);
3130
}
3231

@@ -41,11 +40,10 @@ public function register()
4140
*/
4241
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
4342
{
44-
$tokens = $phpcsFile->getTokens();
45-
$line = $tokens[$stackPtr]['line'];
43+
$tokens = $phpcsFile->getTokens();
44+
$line = $tokens[$stackPtr]['line'];
4645

4746
while ($tokens[$stackPtr]['line'] == $line) {
48-
4947
/*
5048
* Suffix interfaces with Interface;
5149
*/
@@ -110,7 +108,7 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
110108
$name = $phpcsFile->findNext(T_STRING, $stackPtr);
111109
$function = $phpcsFile->findNext(T_FUNCTION, $stackPtr);
112110

113-
// making sure we're not dealing with an abstract function
111+
// Making sure we're not dealing with an abstract function
114112
if ($name && (false === $function || $name < $function)
115113
&& substr($tokens[$name]['content'], 0, 8) != 'Abstract'
116114
) {

0 commit comments

Comments
 (0)