Skip to content

Commit 47e36ce

Browse files
💄 Typing
1 parent a852c60 commit 47e36ce

32 files changed

+390
-712
lines changed

SymfonyCustom/Sniffs/Arrays/ArrayDeclarationSniff.php

Lines changed: 98 additions & 130 deletions
Large diffs are not rendered by default.

SymfonyCustom/Sniffs/Classes/ClassDeclarationSniff.php

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,36 +10,28 @@
1010
class ClassDeclarationSniff
1111
{
1212
/**
13-
* @return array
13+
* @return int[]
1414
*/
15-
public function register()
15+
public function register(): array
1616
{
17-
return [
18-
T_CLASS,
19-
T_INTERFACE,
20-
T_TRAIT,
21-
];
17+
return [T_CLASS, T_INTERFACE, T_TRAIT];
2218
}
2319

2420
/**
25-
* Processes this test, when one of its tokens is encountered.
26-
*
27-
* @param File $phpcsFile The file being scanned.
28-
* @param int $stackPtr The position of the current token in the stack passed in $tokens.
29-
*
30-
* @return void
21+
* @param File $phpcsFile
22+
* @param int $stackPtr
3123
*/
32-
public function process(File $phpcsFile, $stackPtr)
24+
public function process(File $phpcsFile, $stackPtr): void
3325
{
3426
// Just in case.
3527
$tokens = $phpcsFile->getTokens();
3628
$openingBrace = $tokens[$stackPtr]['scope_opener'];
3729

38-
if (isset($openingBrace) === false) {
30+
if (!isset($openingBrace)) {
3931
return;
4032
}
4133

42-
$nextElement = $phpcsFile->findNext([T_WHITESPACE], $openingBrace + 1, null, true);
34+
$nextElement = $phpcsFile->findNext(T_WHITESPACE, $openingBrace + 1, null, true);
4335

4436
if ($tokens[$openingBrace]['line'] + 1 < $tokens[$nextElement]['line']) {
4537
$fix = $phpcsFile->addFixableError(
@@ -48,7 +40,7 @@ public function process(File $phpcsFile, $stackPtr)
4840
'Invalid'
4941
);
5042

51-
if (true === $fix) {
43+
if ($fix) {
5244
$phpcsFile->fixer->replaceToken($openingBrace + 1, '');
5345
}
5446
}

SymfonyCustom/Sniffs/Classes/PropertyDeclarationSniff.php

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,27 +11,18 @@
1111
class PropertyDeclarationSniff implements Sniff
1212
{
1313
/**
14-
* Returns an array of tokens this test wants to listen for.
15-
*
16-
* @return array
14+
* @return int[]
1715
*/
18-
public function register()
16+
public function register(): array
1917
{
20-
return [
21-
T_CLASS,
22-
];
18+
return [T_CLASS];
2319
}
2420

2521
/**
26-
* Processes this test, when one of its tokens is encountered.
27-
*
28-
* @param File $phpcsFile The file being scanned.
29-
* @param int $stackPtr The position of the current token
30-
* in the stack passed in $tokens.
31-
*
32-
* @return void
22+
* @param File $phpcsFile
23+
* @param int $stackPtr
3324
*/
34-
public function process(File $phpcsFile, $stackPtr)
25+
public function process(File $phpcsFile, $stackPtr): void
3526
{
3627
$tokens = $phpcsFile->getTokens();
3728

SymfonyCustom/Sniffs/Commenting/DocCommentForbiddenTagsSniff.php

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,36 +15,26 @@ class DocCommentForbiddenTagsSniff implements Sniff
1515
*
1616
* @var array
1717
*/
18-
public $tags = [
19-
'@package',
20-
'@subpackage',
21-
];
18+
public $forbiddenTags = ['@package', '@subpackage'];
2219

2320
/**
2421
* A list of tokenizers this sniff supports.
2522
*
2623
* @return array
2724
*/
28-
public function register()
25+
public function register(): array
2926
{
30-
return [
31-
T_DOC_COMMENT_TAG,
32-
];
27+
return [T_DOC_COMMENT_TAG];
3328
}
3429

3530
/**
36-
* Processes this test, when one of its tokens is encountered.
37-
*
38-
* @param File $phpcsFile All the tokens found in the document.
39-
* @param int $stackPtr The position of the current token in
40-
* the stack passed in $tokens.
41-
*
42-
* @return void
31+
* @param File $phpcsFile
32+
* @param int $stackPtr
4333
*/
44-
public function process(File $phpcsFile, $stackPtr)
34+
public function process(File $phpcsFile, $stackPtr): void
4535
{
4636
$tokens = $phpcsFile->getTokens();
47-
if (in_array($tokens[$stackPtr]['content'], $this->tags)) {
37+
if (in_array($tokens[$stackPtr]['content'], $this->forbiddenTags)) {
4838
$phpcsFile->addError(
4939
'The %s annotation is forbidden to use',
5040
$stackPtr,

SymfonyCustom/Sniffs/Commenting/DocCommentGroupSameTypeSniff.php

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use PHP_CodeSniffer\Files\File;
66
use PHP_CodeSniffer\Sniffs\Sniff;
7+
use SymfonyCustom\Sniffs\SniffHelper;
78

89
/**
910
* Throws errors if comments are not grouped by type with one blank line between them.
@@ -54,22 +55,16 @@ class DocCommentGroupSameTypeSniff implements Sniff
5455
*
5556
* @return array
5657
*/
57-
public function register()
58+
public function register(): array
5859
{
59-
return [
60-
T_DOC_COMMENT_OPEN_TAG,
61-
];
60+
return [T_DOC_COMMENT_OPEN_TAG];
6261
}
6362

6463
/**
65-
* Processes this test, when one of its tokens is encountered.
66-
*
67-
* @param File $phpcsFile All the tokens found in the document.
68-
* @param int $stackPtr The position of the current token in the stack passed in $tokens.
69-
*
70-
* @return void
64+
* @param File $phpcsFile
65+
* @param int $stackPtr
7166
*/
72-
public function process(File $phpcsFile, $stackPtr)
67+
public function process(File $phpcsFile, $stackPtr): void
7368
{
7469
$tokens = $phpcsFile->getTokens();
7570

@@ -125,7 +120,7 @@ public function process(File $phpcsFile, $stackPtr)
125120
);
126121
}
127122

128-
if (true === $fix) {
123+
if ($fix) {
129124
$phpcsFile->fixer->beginChangeset();
130125
$this->removeLines(
131126
$phpcsFile,
@@ -144,7 +139,7 @@ public function process(File $phpcsFile, $stackPtr)
144139
'DifferentType'
145140
);
146141

147-
if (true === $fix) {
142+
if ($fix) {
148143
$phpcsFile->fixer->beginChangeset();
149144

150145
if ($previousLine === $commentTagLine - 1) {
@@ -185,17 +180,14 @@ public function process(File $phpcsFile, $stackPtr)
185180

186181
/**
187182
* Remove all tokens on lines (inclusively).
183+
* This method does not start or end changeset.
188184
*
189-
* Note: this method does not start or end changeset.
190-
*
191-
* @param File $phpcsFile File to make changes in
192-
* @param int $fromPtr Start searching tokens from here
193-
* @param int $fromLine First line to delete tokens from
194-
* @param int $toLine Last line to delete tokens from
195-
*
196-
* @return void
185+
* @param File $phpcsFile
186+
* @param int $fromPtr
187+
* @param int $fromLine
188+
* @param int $toLine
197189
*/
198-
protected function removeLines(File $phpcsFile, $fromPtr, $fromLine, $toLine)
190+
private function removeLines(File $phpcsFile, int $fromPtr, int $fromLine, int $toLine): void
199191
{
200192
$tokens = $phpcsFile->getTokens();
201193

SymfonyCustom/Sniffs/Commenting/DocCommentSniff.php

Lines changed: 11 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -11,38 +11,22 @@
1111
class DocCommentSniff implements Sniff
1212
{
1313
/**
14-
* A list of tokenizers this sniff supports.
15-
*
16-
* @var array
14+
* @return int[]
1715
*/
18-
public $supportedTokenizers = [
19-
'PHP',
20-
'JS',
21-
];
22-
23-
/**
24-
* Returns an array of tokens this test wants to listen for.
25-
*
26-
* @return array
27-
*/
28-
public function register()
16+
public function register(): array
2917
{
3018
return [T_DOC_COMMENT_OPEN_TAG];
3119
}
3220

3321
/**
34-
* Processes this test, when one of its tokens is encountered.
35-
*
36-
* @param File $phpcsFile The file being scanned.
37-
* @param int $stackPtr The position of the current token in the stack passed in $tokens.
38-
*
39-
* @return void
22+
* @param File $phpcsFile
23+
* @param int $stackPtr
4024
*/
41-
public function process(File $phpcsFile, $stackPtr)
25+
public function process(File $phpcsFile, $stackPtr): void
4226
{
4327
$tokens = $phpcsFile->getTokens();
4428

45-
if (false === isset($tokens[$stackPtr]['comment_closer'])
29+
if (!isset($tokens[$stackPtr]['comment_closer'])
4630
|| ('' === $tokens[$tokens[$stackPtr]['comment_closer']]['content']
4731
&& ($phpcsFile->numTokens - 1) === $tokens[$stackPtr]['comment_closer'])
4832
) {
@@ -69,7 +53,7 @@ public function process(File $phpcsFile, $stackPtr)
6953

7054
$fix = $phpcsFile->addFixableError($error, $stackPtr, 'Empty');
7155

72-
if (true === $fix) {
56+
if ($fix) {
7357
$phpcsFile->fixer->beginChangeset();
7458

7559
$end = $hasSameLineNext ? $next : $commentEnd + 1;
@@ -101,7 +85,7 @@ public function process(File $phpcsFile, $stackPtr)
10185
if (!$isSingleLine && $tokens[$short]['line'] === $tokens[$stackPtr]['line']) {
10286
$error = 'The open comment tag must be the only content on the line';
10387
$fix = $phpcsFile->addFixableError($error, $stackPtr, 'ContentAfterOpen');
104-
if (true === $fix) {
88+
if ($fix) {
10589
$phpcsFile->fixer->beginChangeset();
10690
for ($i = ($stackPtr + 1); $i < $short; $i++) {
10791
$phpcsFile->fixer->replaceToken($i, '');
@@ -123,7 +107,7 @@ public function process(File $phpcsFile, $stackPtr)
123107
if ($tokens[$stackPtr]['line'] < ($tokens[$short]['line'] - 1)) {
124108
$error = 'Additional blank lines found at beginning of doc comment';
125109
$fix = $phpcsFile->addFixableError($error, $stackPtr, 'SpacingBefore');
126-
if (true === $fix) {
110+
if ($fix) {
127111
$phpcsFile->fixer->beginChangeset();
128112
for ($i = ($stackPtr + 1); $i < $short; $i++) {
129113
if ($tokens[($i + 1)]['line'] === $tokens[$short]['line']) {
@@ -142,7 +126,7 @@ public function process(File $phpcsFile, $stackPtr)
142126
if (!$isSingleLine && $tokens[$prev]['line'] === $tokens[$commentEnd]['line']) {
143127
$error = 'The close comment tag must be the only content on the line';
144128
$fix = $phpcsFile->addFixableError($error, $commentEnd, 'ContentBeforeClose');
145-
if (true === $fix) {
129+
if ($fix) {
146130
$phpcsFile->fixer->beginChangeset();
147131
for ($i = ($prev + 1); $i < $commentEnd; $i++) {
148132
$phpcsFile->fixer->replaceToken($i, '');
@@ -164,7 +148,7 @@ public function process(File $phpcsFile, $stackPtr)
164148
if ($tokens[$prev]['line'] < ($tokens[$commentEnd]['line'] - 1)) {
165149
$error = 'Additional blank lines found at end of doc comment';
166150
$fix = $phpcsFile->addFixableError($error, $commentEnd, 'SpacingAfter');
167-
if (true === $fix) {
151+
if ($fix) {
168152
$phpcsFile->fixer->beginChangeset();
169153
for ($i = ($prev + 1); $i < $commentEnd; $i++) {
170154
if ($tokens[($i + 1)]['line'] === $tokens[$commentEnd]['line']) {

0 commit comments

Comments
 (0)