Skip to content

Commit d1aa8fa

Browse files
Merge pull request #16 from VincentLanglet/staging
Staging
2 parents 8c43f5e + 26fd135 commit d1aa8fa

24 files changed

+553
-279
lines changed

Symfony3Custom/Sniffs/Arrays/ArrayDeclarationSniff.php

Lines changed: 100 additions & 90 deletions
Large diffs are not rendered by default.

Symfony3Custom/Sniffs/Classes/PropertyDeclarationSniff.php

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,6 @@
55
*/
66
class Symfony3Custom_Sniffs_Classes_PropertyDeclarationSniff implements PHP_CodeSniffer_Sniff
77
{
8-
/**
9-
* A list of tokenizers this sniff supports.
10-
*
11-
* @var array
12-
*/
13-
public $supportedTokenizers = array(
14-
'PHP',
15-
);
16-
178
/**
189
* Returns an array of tokens this test wants to listen for.
1910
*
@@ -63,7 +54,7 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
6354
$end
6455
);
6556

66-
if ($scope && $tokens[$scope + 2]['code'] === T_VARIABLE) {
57+
if ($scope && T_VARIABLE === $tokens[$scope + 2]['code']) {
6758
$phpcsFile->addError(
6859
'Declare class properties before methods',
6960
$scope,

Symfony3Custom/Sniffs/Commenting/DocCommentForbiddenTagsSniff.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ class Symfony3Custom_Sniffs_Commenting_DocCommentForbiddenTagsSniff implements P
2222
*/
2323
public function register()
2424
{
25-
return array(T_DOC_COMMENT_TAG);
25+
return array(
26+
T_DOC_COMMENT_TAG
27+
);
2628
}
2729

2830
/**

Symfony3Custom/Sniffs/Commenting/DocCommentGroupSameTypeSniff.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ class Symfony3Custom_Sniffs_Commenting_DocCommentGroupSameTypeSniff implements P
4848
*/
4949
public function register()
5050
{
51-
return array(T_DOC_COMMENT_OPEN_TAG);
51+
return array(
52+
T_DOC_COMMENT_OPEN_TAG
53+
);
5254
}
5355

5456
/**
@@ -87,7 +89,7 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
8789
$previousLine = max($previousStringLine, $previousTagLine);
8890

8991
$currentIsCustom = !in_array($currentType, $this->tags);
90-
$previousIsCustom = ($previousType !== '')
92+
$previousIsCustom = ('' !== $previousType)
9193
&& !in_array($previousType, $this->tags);
9294

9395
if (($previousType === $currentType)
@@ -110,7 +112,7 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
110112
);
111113
}
112114

113-
if ($fix === true) {
115+
if (true === $fix) {
114116
$phpcsFile->fixer->beginChangeset();
115117
$this->removeLines(
116118
$phpcsFile,
@@ -130,7 +132,7 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
130132
'DifferentType'
131133
);
132134

133-
if ($fix === true) {
135+
if (true === $fix) {
134136
$phpcsFile->fixer->beginChangeset();
135137

136138
if ($previousLine === $commentTagLine - 1) {

Symfony3Custom/Sniffs/Commenting/FunctionCommentSniff.php

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -33,24 +33,24 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
3333
$find[] = T_WHITESPACE;
3434

3535
$commentEnd = $phpcsFile->findPrevious($find, ($stackPtr - 1), null, true);
36-
if ($tokens[$commentEnd]['code'] === T_COMMENT) {
36+
if (T_COMMENT === $tokens[$commentEnd]['code']) {
3737
// Inline comments might just be closing comments for
3838
// control structures or functions instead of function comments
3939
// using the wrong comment type. If there is other code on the line,
4040
// assume they relate to that code.
4141
$prev = $phpcsFile->findPrevious($find, ($commentEnd - 1), null, true);
42-
if ($prev !== false && $tokens[$prev]['line'] === $tokens[$commentEnd]['line']) {
42+
if (false !== $prev && $tokens[$prev]['line'] === $tokens[$commentEnd]['line']) {
4343
$commentEnd = $prev;
4444
}
4545
}
4646

4747
$name = $phpcsFile->getDeclarationName($stackPtr);
4848
$commentRequired = strpos($name, 'test') !== 0
49-
&& $name !== 'setUp'
50-
&& $name !== 'tearDown';
49+
&& 'setUp' !== $name
50+
&& 'tearDown' !== $name;
5151

52-
if ($tokens[$commentEnd]['code'] !== T_DOC_COMMENT_CLOSE_TAG
53-
&& $tokens[$commentEnd]['code'] !== T_COMMENT
52+
if (T_DOC_COMMENT_CLOSE_TAG !== $tokens[$commentEnd]['code']
53+
&& T_COMMENT !== $tokens[$commentEnd]['code']
5454
) {
5555
$hasComment = false;
5656
$phpcsFile->recordMetric($stackPtr, 'Function has doc comment', 'no');
@@ -68,7 +68,7 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
6868
}
6969

7070
if ($hasComment) {
71-
if ($tokens[$commentEnd]['code'] === T_COMMENT) {
71+
if (T_COMMENT === $tokens[$commentEnd]['code']) {
7272
$phpcsFile->addError(
7373
'You must use "/**" style comments for a function comment',
7474
$stackPtr,
@@ -78,17 +78,17 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
7878
return;
7979
}
8080

81-
if ($tokens[$commentEnd]['line'] !== ($tokens[$stackPtr]['line'] - 1)) {
81+
if (($tokens[$stackPtr]['line'] - 1) !== $tokens[$commentEnd]['line']) {
8282
$error = 'There must be no blank lines after the function comment';
8383
$phpcsFile->addError($error, $commentEnd, 'SpacingAfter');
8484
}
8585

8686
$commentStart = $tokens[$commentEnd]['comment_opener'];
8787
foreach ($tokens[$commentStart]['comment_tags'] as $tag) {
88-
if ($tokens[$tag]['content'] === '@see') {
88+
if ('@see' === $tokens[$tag]['content']) {
8989
// Make sure the tag isn't empty.
9090
$string = $phpcsFile->findNext(T_DOC_COMMENT_STRING, $tag, $commentEnd);
91-
if ($string === false || $tokens[$string]['line'] !== $tokens[$tag]['line']) {
91+
if (false === $string || $tokens[$string]['line'] !== $tokens[$tag]['line']) {
9292
$error = 'Content missing for @see tag in function comment';
9393
$phpcsFile->addError($error, $tag, 'EmptySees');
9494
}
@@ -101,7 +101,7 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
101101
$stackPtr
102102
);
103103

104-
if ($methodPrefixes !== false) {
104+
if (false !== $methodPrefixes) {
105105
$commentStart = $methodPrefixes;
106106
} else {
107107
// No comment and no method prefix
@@ -117,8 +117,6 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
117117
$this->processParams($phpcsFile, $stackPtr, $commentStart);
118118
$this->processThrows($phpcsFile, $stackPtr, $commentStart);
119119
} else {
120-
$this->processWhitespace($phpcsFile, $commentStart, $hasComment);
121-
122120
if (count($realParams) > 0) {
123121
foreach ($realParams as $neededParam) {
124122
$error = 'Doc comment for parameter "%s" missing';
@@ -127,6 +125,8 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
127125
}
128126
}
129127
}
128+
129+
$this->processWhitespace($phpcsFile, $commentStart);
130130
}
131131

132132
/**
@@ -165,14 +165,14 @@ protected function processReturn(
165165

166166
for ($i = $start; $i < $tokens[$stackPtr]['scope_closer']; ++$i) {
167167
// Skip closures
168-
if ($tokens[$i]['code'] === T_CLOSURE) {
168+
if (T_CLOSURE === $tokens[$i]['code']) {
169169
$i = $tokens[$i]['scope_closer'];
170170
continue;
171171
}
172172

173173
// Found a return not in a closure statement
174174
// Run the check on the first which is not only 'return;'
175-
if ($tokens[$i]['code'] === T_RETURN
175+
if (T_RETURN === $tokens[$i]['code']
176176
&& $this->isMatchingReturn($tokens, $i)
177177
) {
178178
if ($hasRealComment) {
@@ -208,7 +208,7 @@ protected function processWhitespace(
208208
$found = $startLine - $prevLine - 1;
209209

210210
// Skip for class opening
211-
if ($found < 1 && !($found === 0 && $tokens[$before]['type'] === 'T_OPEN_CURLY_BRACKET')) {
211+
if ($found < 1 && !(0 === $found && 'T_OPEN_CURLY_BRACKET' === $tokens[$before]['type'])) {
212212
if ($found < 0) {
213213
$found = 0;
214214
}
@@ -224,7 +224,7 @@ protected function processWhitespace(
224224
$data = array($found);
225225
$fix = $phpcsFile->addFixableError($error, $commentStart, $rule, $data);
226226

227-
if ($fix === true) {
227+
if (true === $fix) {
228228
if ($found > 1) {
229229
$phpcsFile->fixer->beginChangeset();
230230

@@ -235,7 +235,7 @@ protected function processWhitespace(
235235
$phpcsFile->fixer->endChangeset();
236236
} else {
237237
// Try and maintain indentation.
238-
if ($tokens[($commentStart - 1)]['code'] === T_WHITESPACE) {
238+
if (T_WHITESPACE === $tokens[($commentStart - 1)]['code']) {
239239
$phpcsFile->fixer->addNewlineBefore($commentStart - 1);
240240
} else {
241241
$phpcsFile->fixer->addNewlineBefore($commentStart);
@@ -284,8 +284,6 @@ protected function processParams(
284284
return;
285285
}
286286

287-
$this->processWhitespace($phpcsFile, $commentStart);
288-
289287
parent::processParams($phpcsFile, $stackPtr, $commentStart);
290288
}
291289

@@ -301,8 +299,8 @@ protected function isMatchingReturn($tokens, $returnPos)
301299
{
302300
do {
303301
$returnPos++;
304-
} while ($tokens[$returnPos]['code'] === T_WHITESPACE);
302+
} while (T_WHITESPACE === $tokens[$returnPos]['code']);
305303

306-
return $tokens[$returnPos]['code'] !== T_SEMICOLON;
304+
return T_SEMICOLON !== $tokens[$returnPos]['code'];
307305
}
308306
}

Symfony3Custom/Sniffs/Commenting/VariableCommentSniff.php

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,16 @@ public function processMemberVar(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
3131
);
3232

3333
$commentEnd = $phpcsFile->findPrevious($ignore, ($stackPtr - 1), null, true);
34-
if ($commentEnd === false
35-
|| ($tokens[$commentEnd]['code'] !== T_DOC_COMMENT_CLOSE_TAG
36-
&& $tokens[$commentEnd]['code'] !== T_COMMENT)
34+
if (false === $commentEnd
35+
|| (T_DOC_COMMENT_CLOSE_TAG !== $tokens[$commentEnd]['code']
36+
&& T_COMMENT !== $tokens[$commentEnd]['code'])
3737
) {
3838
$phpcsFile->addError('Missing member variable doc comment', $stackPtr, 'Missing');
3939

4040
return;
4141
}
4242

43-
if ($tokens[$commentEnd]['code'] === T_COMMENT) {
43+
if (T_COMMENT === $tokens[$commentEnd]['code']) {
4444
$phpcsFile->addError(
4545
'You must use "/**" style comments for a member variable comment',
4646
$stackPtr,
@@ -54,40 +54,40 @@ public function processMemberVar(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
5454

5555
$foundVar = null;
5656
foreach ($tokens[$commentStart]['comment_tags'] as $tag) {
57-
if ($tokens[$tag]['content'] === '@var') {
58-
if ($foundVar !== null) {
57+
if ('@var' === $tokens[$tag]['content']) {
58+
if (null !== $foundVar) {
5959
$error = 'Only one @var tag is allowed in a member variable comment';
6060
$phpcsFile->addError($error, $tag, 'DuplicateVar');
6161
} else {
6262
$foundVar = $tag;
6363
}
64-
} elseif ($tokens[$tag]['content'] === '@see') {
64+
} elseif ('@see' === $tokens[$tag]['content']) {
6565
// Make sure the tag isn't empty.
6666
$string = $phpcsFile->findNext(T_DOC_COMMENT_STRING, $tag, $commentEnd);
67-
if ($string === false || $tokens[$string]['line'] !== $tokens[$tag]['line']) {
67+
if (false === $string || $tokens[$string]['line'] !== $tokens[$tag]['line']) {
6868
$error = 'Content missing for @see tag in member variable comment';
6969
$phpcsFile->addError($error, $tag, 'EmptySees');
7070
}
7171
}
7272
}
7373

7474
// The @var tag is the only one we require.
75-
if ($foundVar === null) {
75+
if (null === $foundVar) {
7676
$error = 'Missing @var tag in member variable comment';
7777
$phpcsFile->addError($error, $commentEnd, 'MissingVar');
7878

7979
return;
8080
}
8181

8282
$firstTag = $tokens[$commentStart]['comment_tags'][0];
83-
if ($foundVar !== null && $tokens[$firstTag]['content'] !== '@var') {
83+
if (null !== $foundVar && '@var' !== $tokens[$firstTag]['content']) {
8484
$error = 'The @var tag must be the first tag in a member variable comment';
8585
$phpcsFile->addError($error, $foundVar, 'VarOrder');
8686
}
8787

8888
// Make sure the tag isn't empty and has the correct padding.
8989
$string = $phpcsFile->findNext(T_DOC_COMMENT_STRING, $foundVar, $commentEnd);
90-
if ($string === false || $tokens[$string]['line'] !== $tokens[$foundVar]['line']) {
90+
if (false === $string || $tokens[$string]['line'] !== $tokens[$foundVar]['line']) {
9191
$error = 'Content missing for @var tag in member variable comment';
9292
$phpcsFile->addError($error, $foundVar, 'EmptyVar');
9393

@@ -114,7 +114,10 @@ protected function processWhitespace(
114114
$found = $startLine - $prevLine - 1;
115115

116116
// Skip for class opening
117-
if ($found < 1 && !($found === 0 && $tokens[$before]['type'] === 'T_OPEN_CURLY_BRACKET')) {
117+
if ($found < 1
118+
&& !(0 === $found
119+
&& 'T_OPEN_CURLY_BRACKET' === $tokens[$before]['type'])
120+
) {
118121
if ($found < 0) {
119122
$found = 0;
120123
}
@@ -125,7 +128,7 @@ protected function processWhitespace(
125128
$data = array($found);
126129
$fix = $phpcsFile->addFixableError($error, $commentStart, $rule, $data);
127130

128-
if ($fix === true) {
131+
if (true === $fix) {
129132
if ($found > 1) {
130133
$phpcsFile->fixer->beginChangeset();
131134

@@ -136,7 +139,7 @@ protected function processWhitespace(
136139
$phpcsFile->fixer->endChangeset();
137140
} else {
138141
// Try and maintain indentation.
139-
if ($tokens[($commentStart - 1)]['code'] === T_WHITESPACE) {
142+
if (T_WHITESPACE === $tokens[($commentStart - 1)]['code']) {
140143
$phpcsFile->fixer->addNewlineBefore($commentStart - 1);
141144
} else {
142145
$phpcsFile->fixer->addNewlineBefore($commentStart);

Symfony3Custom/Sniffs/Formatting/BlankLineBeforeReturnSniff.php

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,16 @@
77
*/
88
class Symfony3Custom_Sniffs_Formatting_BlankLineBeforeReturnSniff implements PHP_CodeSniffer_Sniff
99
{
10-
/**
11-
* A list of tokenizers this sniff supports.
12-
*
13-
* @var array
14-
*/
15-
public $supportedTokenizers = array(
16-
'PHP',
17-
'JS',
18-
);
19-
2010
/**
2111
* Returns an array of tokens this test wants to listen for.
2212
*
2313
* @return array
2414
*/
2515
public function register()
2616
{
27-
return array(T_RETURN);
17+
return array(
18+
T_RETURN
19+
);
2820
}
2921

3022
/**
@@ -44,20 +36,20 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
4436
$prevLineTokens = array();
4537

4638
while ($current >= 0 && $tokens[$current]['line'] >= $previousLine) {
47-
if ($tokens[$current]['line'] == $previousLine
48-
&& $tokens[$current]['type'] !== 'T_WHITESPACE'
49-
&& $tokens[$current]['type'] !== 'T_COMMENT'
50-
&& $tokens[$current]['type'] !== 'T_DOC_COMMENT_CLOSE_TAG'
51-
&& $tokens[$current]['type'] !== 'T_DOC_COMMENT_WHITESPACE'
39+
if ($tokens[$current]['line'] === $previousLine
40+
&& 'T_WHITESPACE' !== $tokens[$current]['type']
41+
&& 'T_COMMENT' !== $tokens[$current]['type']
42+
&& 'T_DOC_COMMENT_CLOSE_TAG' !== $tokens[$current]['type']
43+
&& 'T_DOC_COMMENT_WHITESPACE' !== $tokens[$current]['type']
5244
) {
5345
$prevLineTokens[] = $tokens[$current]['type'];
5446
}
5547
$current--;
5648
}
5749

5850
if (isset($prevLineTokens[0])
59-
&& ($prevLineTokens[0] === 'T_OPEN_CURLY_BRACKET'
60-
|| $prevLineTokens[0] === 'T_COLON')
51+
&& ('T_OPEN_CURLY_BRACKET' === $prevLineTokens[0]
52+
|| 'T_COLON' === $prevLineTokens[0])
6153
) {
6254
return;
6355
} elseif (count($prevLineTokens) > 0) {
@@ -67,10 +59,10 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
6759
'MissedBlankLineBeforeRetrun'
6860
);
6961

70-
if ($fix === true) {
62+
if (true === $fix) {
7163
$phpcsFile->fixer->beginChangeset();
7264
$i = 1;
73-
while ($tokens[$stackPtr - $i]['type'] == 'T_WHITESPACE') {
65+
while ('T_WHITESPACE' === $tokens[$stackPtr - $i]['type']) {
7466
$i++;
7567
}
7668
$phpcsFile->fixer->addNewLine($stackPtr - $i);

0 commit comments

Comments
 (0)