Skip to content

Commit aeda1b6

Browse files
Merge pull request #88 from VincentLanglet/declare
💄 Use strict type
2 parents d3b72a4 + 143e5a5 commit aeda1b6

File tree

95 files changed

+408
-544
lines changed

Some content is hidden

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

95 files changed

+408
-544
lines changed

SymfonyCustom/Sniffs/Arrays/ArrayDeclarationSniff.php

Lines changed: 78 additions & 76 deletions
Large diffs are not rendered by default.

SymfonyCustom/Sniffs/Classes/ClassDeclarationSniff.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace SymfonyCustom\Sniffs\Classes;
46

57
use PHP_CodeSniffer\Files\File;

SymfonyCustom/Sniffs/Classes/PropertyDeclarationSniff.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace SymfonyCustom\Sniffs\Classes;
46

57
use PHP_CodeSniffer\Files\File;

SymfonyCustom/Sniffs/Commenting/ClassCommentSniff.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace SymfonyCustom\Sniffs\Commenting;
46

57
use PHP_CodeSniffer\Standards\PEAR\Sniffs\Commenting\ClassCommentSniff as PEARClassCommentSniff;

SymfonyCustom/Sniffs/Commenting/DocCommentForbiddenTagsSniff.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace SymfonyCustom\Sniffs\Commenting;
46

57
use PHP_CodeSniffer\Files\File;

SymfonyCustom/Sniffs/Commenting/DocCommentGroupSameTypeSniff.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace SymfonyCustom\Sniffs\Commenting;
46

57
use PHP_CodeSniffer\Files\File;

SymfonyCustom/Sniffs/Commenting/DocCommentSniff.php

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace SymfonyCustom\Sniffs\Commenting;
46

57
use PHP_CodeSniffer\Files\File;
@@ -28,7 +30,7 @@ public function process(File $phpcsFile, $stackPtr): void
2830

2931
if (!isset($tokens[$stackPtr]['comment_closer'])
3032
|| ('' === $tokens[$tokens[$stackPtr]['comment_closer']]['content']
31-
&& ($phpcsFile->numTokens - 1) === $tokens[$stackPtr]['comment_closer'])
33+
&& $phpcsFile->numTokens - 1 === $tokens[$stackPtr]['comment_closer'])
3234
) {
3335
// Don't process an unfinished comment during live coding.
3436
return;
@@ -41,7 +43,7 @@ public function process(File $phpcsFile, $stackPtr): void
4143
T_DOC_COMMENT_STAR,
4244
];
4345

44-
$short = $phpcsFile->findNext($empty, ($stackPtr + 1), $commentEnd, true);
46+
$short = $phpcsFile->findNext($empty, $stackPtr + 1, $commentEnd, true);
4547
if (false === $short) {
4648
// No content at all.
4749
$next = $phpcsFile->findNext(T_WHITESPACE, $commentEnd + 1, null, true);
@@ -87,7 +89,7 @@ public function process(File $phpcsFile, $stackPtr): void
8789

8890
if ($fix) {
8991
$phpcsFile->fixer->beginChangeset();
90-
for ($i = ($stackPtr + 1); $i < $short; $i++) {
92+
for ($i = $stackPtr + 1; $i < $short; $i++) {
9193
$phpcsFile->fixer->replaceToken($i, '');
9294
}
9395
$phpcsFile->fixer->addNewline($stackPtr);
@@ -104,7 +106,7 @@ public function process(File $phpcsFile, $stackPtr): void
104106
}
105107

106108
// Check for additional blank lines at the beginning of the comment.
107-
if ($tokens[$stackPtr]['line'] < ($tokens[$short]['line'] - 1)) {
109+
if ($tokens[$stackPtr]['line'] < $tokens[$short]['line'] - 1) {
108110
$fix = $phpcsFile->addFixableError(
109111
'Additional blank lines found at beginning of doc comment',
110112
$stackPtr,
@@ -113,8 +115,8 @@ public function process(File $phpcsFile, $stackPtr): void
113115

114116
if ($fix) {
115117
$phpcsFile->fixer->beginChangeset();
116-
for ($i = ($stackPtr + 1); $i < $short; $i++) {
117-
if ($tokens[($i + 1)]['line'] === $tokens[$short]['line']) {
118+
for ($i = $stackPtr + 1; $i < $short; $i++) {
119+
if ($tokens[$i + 1]['line'] === $tokens[$short]['line']) {
118120
break;
119121
}
120122

@@ -126,7 +128,7 @@ public function process(File $phpcsFile, $stackPtr): void
126128
}
127129

128130
// The last line of the comment should just be the */ code.
129-
$prev = $phpcsFile->findPrevious($empty, ($commentEnd - 1), $stackPtr, true);
131+
$prev = $phpcsFile->findPrevious($empty, $commentEnd - 1, $stackPtr, true);
130132
if (!$isSingleLine && $tokens[$prev]['line'] === $tokens[$commentEnd]['line']) {
131133
$fix = $phpcsFile->addFixableError(
132134
'The close comment tag must be the only content on the line',
@@ -136,7 +138,7 @@ public function process(File $phpcsFile, $stackPtr): void
136138

137139
if ($fix) {
138140
$phpcsFile->fixer->beginChangeset();
139-
for ($i = ($prev + 1); $i < $commentEnd; $i++) {
141+
for ($i = $prev + 1; $i < $commentEnd; $i++) {
140142
$phpcsFile->fixer->replaceToken($i, '');
141143
}
142144
$phpcsFile->fixer->replaceToken(
@@ -153,7 +155,7 @@ public function process(File $phpcsFile, $stackPtr): void
153155
}
154156

155157
// Check for additional blank lines at the end of the comment.
156-
if ($tokens[$prev]['line'] < ($tokens[$commentEnd]['line'] - 1)) {
158+
if ($tokens[$prev]['line'] < $tokens[$commentEnd]['line'] - 1) {
157159
$fix = $phpcsFile->addFixableError(
158160
'Additional blank lines found at end of doc comment',
159161
$commentEnd,
@@ -162,8 +164,8 @@ public function process(File $phpcsFile, $stackPtr): void
162164

163165
if ($fix) {
164166
$phpcsFile->fixer->beginChangeset();
165-
for ($i = ($prev + 1); $i < $commentEnd; $i++) {
166-
if ($tokens[($i + 1)]['line'] === $tokens[$commentEnd]['line']) {
167+
for ($i = $prev + 1; $i < $commentEnd; $i++) {
168+
if ($tokens[$i + 1]['line'] === $tokens[$commentEnd]['line']) {
167169
break;
168170
}
169171

SymfonyCustom/Sniffs/Commenting/FunctionCommentSniff.php

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace SymfonyCustom\Sniffs\Commenting;
46

57
use PHP_CodeSniffer\Files\File;
@@ -18,15 +20,15 @@ class FunctionCommentSniff extends PEARFunctionCommentSniff
1820
public function process(File $phpcsFile, $stackPtr): void
1921
{
2022
$tokens = $phpcsFile->getTokens();
21-
$find = Tokens::$methodPrefixes;
23+
$find = Tokens::$methodPrefixes;
2224
$find[] = T_WHITESPACE;
2325

24-
$commentEnd = $phpcsFile->findPrevious($find, ($stackPtr - 1), null, true);
26+
$commentEnd = $phpcsFile->findPrevious($find, $stackPtr - 1, null, true);
2527
if (T_COMMENT === $tokens[$commentEnd]['code']) {
2628
// Inline comments might just be closing comments for control structures or functions
2729
// instead of function comments using the wrong comment type.
2830
// If there is other code on the line, assume they relate to that code.
29-
$prev = $phpcsFile->findPrevious($find, ($commentEnd - 1), null, true);
31+
$prev = $phpcsFile->findPrevious($find, $commentEnd - 1, null, true);
3032
if (false !== $prev && $tokens[$prev]['line'] === $tokens[$commentEnd]['line']) {
3133
$commentEnd = $prev;
3234
}
@@ -46,7 +48,7 @@ public function process(File $phpcsFile, $stackPtr): void
4648
return;
4749
}
4850

49-
if (($tokens[$stackPtr]['line'] - 1) !== $tokens[$commentEnd]['line']) {
51+
if ($tokens[$stackPtr]['line'] - 1 !== $tokens[$commentEnd]['line']) {
5052
$phpcsFile->addError(
5153
'There must be no blank lines after the function comment',
5254
$commentEnd,
@@ -183,9 +185,9 @@ protected function processThrows(File $phpcsFile, $stackPtr, $commentStart): voi
183185

184186
if (null !== $throw) {
185187
$exception = null;
186-
if (T_DOC_COMMENT_STRING === $tokens[($throw + 2)]['code']) {
188+
if (T_DOC_COMMENT_STRING === $tokens[$throw + 2]['code']) {
187189
$matches = [];
188-
preg_match('/([^\s]+)(?:\s+(.*))?/', $tokens[($throw + 2)]['content'], $matches);
190+
preg_match('/([^\s]+)(?:\s+(.*))?/', $tokens[$throw + 2]['content'], $matches);
189191
$exception = $matches[1];
190192
}
191193

@@ -221,7 +223,7 @@ protected function processParams(File $phpcsFile, $stackPtr, $commentStart): voi
221223
private function processWhitespace(File $phpcsFile, int $commentStart, bool $hasComment = true): void
222224
{
223225
$tokens = $phpcsFile->getTokens();
224-
$before = $phpcsFile->findPrevious(T_WHITESPACE, ($commentStart - 1), null, true);
226+
$before = $phpcsFile->findPrevious(T_WHITESPACE, $commentStart - 1, null, true);
225227

226228
$startLine = $tokens[$commentStart]['line'];
227229
$prevLine = $tokens[$before]['line'];
@@ -248,14 +250,14 @@ private function processWhitespace(File $phpcsFile, int $commentStart, bool $has
248250
if ($found > 1) {
249251
$phpcsFile->fixer->beginChangeset();
250252

251-
for ($i = ($before + 1); $i < ($commentStart - 1); $i++) {
253+
for ($i = $before + 1; $i < $commentStart - 1; $i++) {
252254
$phpcsFile->fixer->replaceToken($i, '');
253255
}
254256

255257
$phpcsFile->fixer->endChangeset();
256258
} else {
257259
// Try and maintain indentation.
258-
if (T_WHITESPACE === $tokens[($commentStart - 1)]['code']) {
260+
if (T_WHITESPACE === $tokens[$commentStart - 1]['code']) {
259261
$phpcsFile->fixer->addNewlineBefore($commentStart - 1);
260262
} else {
261263
$phpcsFile->fixer->addNewlineBefore($commentStart);

SymfonyCustom/Sniffs/Commenting/VariableCommentSniff.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace SymfonyCustom\Sniffs\Commenting;
46

57
use PHP_CodeSniffer\Files\File;
@@ -26,7 +28,7 @@ public function processMemberVar(File $phpcsFile, $stackPtr): void
2628
T_WHITESPACE,
2729
];
2830

29-
$commentEnd = $phpcsFile->findPrevious($ignore, ($stackPtr - 1), null, true);
31+
$commentEnd = $phpcsFile->findPrevious($ignore, $stackPtr - 1, null, true);
3032
if (false === $commentEnd
3133
|| (T_DOC_COMMENT_CLOSE_TAG !== $tokens[$commentEnd]['code']
3234
&& T_COMMENT !== $tokens[$commentEnd]['code'])
@@ -135,7 +137,7 @@ protected function processVariableInString(File $phpcsFile, $stackPtr): void
135137
private function processWhitespace(File $phpcsFile, int $commentStart): void
136138
{
137139
$tokens = $phpcsFile->getTokens();
138-
$before = $phpcsFile->findPrevious(T_WHITESPACE, ($commentStart - 1), null, true);
140+
$before = $phpcsFile->findPrevious(T_WHITESPACE, $commentStart - 1, null, true);
139141

140142
$startLine = $tokens[$commentStart]['line'];
141143
$prevLine = $tokens[$before]['line'];
@@ -159,14 +161,14 @@ private function processWhitespace(File $phpcsFile, int $commentStart): void
159161
if ($found > 1) {
160162
$phpcsFile->fixer->beginChangeset();
161163

162-
for ($i = ($before + 1); $i < ($commentStart - 1); $i++) {
164+
for ($i = $before + 1; $i < $commentStart - 1; $i++) {
163165
$phpcsFile->fixer->replaceToken($i, '');
164166
}
165167

166168
$phpcsFile->fixer->endChangeset();
167169
} else {
168170
// Try and maintain indentation.
169-
if (T_WHITESPACE === $tokens[($commentStart - 1)]['code']) {
171+
if (T_WHITESPACE === $tokens[$commentStart - 1]['code']) {
170172
$phpcsFile->fixer->addNewlineBefore($commentStart - 1);
171173
} else {
172174
$phpcsFile->fixer->addNewlineBefore($commentStart);

SymfonyCustom/Sniffs/Errors/ExceptionMessageSniff.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace SymfonyCustom\Sniffs\Errors;
46

57
use PHP_CodeSniffer\Files\File;

SymfonyCustom/Sniffs/Errors/UserDeprecatedSniff.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace SymfonyCustom\Sniffs\Errors;
46

57
use PHP_CodeSniffer\Files\File;

SymfonyCustom/Sniffs/Formatting/BlankLineBeforeReturnSniff.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace SymfonyCustom\Sniffs\Formatting;
46

57
use PHP_CodeSniffer\Files\File;

SymfonyCustom/Sniffs/Formatting/ConditionalReturnOrThrowSniff.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace SymfonyCustom\Sniffs\Formatting;
46

57
use PHP_CodeSniffer\Files\File;

SymfonyCustom/Sniffs/Formatting/StrictComparisonSniff.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace SymfonyCustom\Sniffs\Formatting;
46

57
use PHP_CodeSniffer\Files\File;

SymfonyCustom/Sniffs/Formatting/YodaConditionSniff.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace SymfonyCustom\Sniffs\Formatting;
46

57
use PHP_CodeSniffer\Files\File;
@@ -27,7 +29,7 @@ public function process(File $phpcsFile, $stackPtr): void
2729
{
2830
$tokens = $phpcsFile->getTokens();
2931

30-
$beginners = Tokens::$booleanOperators;
32+
$beginners = Tokens::$booleanOperators;
3133
$beginners[] = T_IF;
3234
$beginners[] = T_ELSEIF;
3335
$beginners[] = T_EQUAL;
@@ -65,12 +67,12 @@ public function process(File $phpcsFile, $stackPtr): void
6567
}
6668

6769
// Check if this is a var to var comparison, e.g.: if ( $var1 == $var2 ).
68-
$nextNonEmpty = $phpcsFile->findNext(Tokens::$emptyTokens, ($stackPtr + 1), null, true);
70+
$nextNonEmpty = $phpcsFile->findNext(Tokens::$emptyTokens, $stackPtr + 1, null, true);
6971

7072
if (isset(Tokens::$castTokens[$tokens[$nextNonEmpty]['code']])) {
7173
$nextNonEmpty = $phpcsFile->findNext(
7274
Tokens::$emptyTokens,
73-
($nextNonEmpty + 1),
75+
$nextNonEmpty + 1,
7476
null,
7577
true
7678
);
@@ -79,7 +81,7 @@ public function process(File $phpcsFile, $stackPtr): void
7981
if (in_array($tokens[$nextNonEmpty]['code'], [T_SELF, T_PARENT, T_STATIC], true)) {
8082
$nextNonEmpty = $phpcsFile->findNext(
8183
array_merge(Tokens::$emptyTokens, [T_DOUBLE_COLON]),
82-
($nextNonEmpty + 1),
84+
$nextNonEmpty + 1,
8385
null,
8486
true
8587
);

SymfonyCustom/Sniffs/Functions/ScopeOrderSniff.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace SymfonyCustom\Sniffs\Functions;
46

57
use PHP_CodeSniffer\Files\File;

SymfonyCustom/Sniffs/Namespaces/AlphabeticallySortedUseSniff.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace SymfonyCustom\Sniffs\Namespaces;
46

57
use PHP_CodeSniffer\Files\File;

SymfonyCustom/Sniffs/Namespaces/NamespaceDeclarationSniff.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace SymfonyCustom\Sniffs\Namespaces;
46

57
use PHP_CodeSniffer\Files\File;

SymfonyCustom/Sniffs/Namespaces/UnusedUseSniff.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace SymfonyCustom\Sniffs\Namespaces;
46

57
use PHP_CodeSniffer\Files\File;

0 commit comments

Comments
 (0)