Skip to content

Commit 7906f19

Browse files
authored
Merge pull request #43 from KateSyrotchuk/fix-unused-imports
fix sniffs after update escapestudios/symfony2-coding-standard
2 parents 47befa2 + 72dba7b commit 7906f19

File tree

48 files changed

+112
-116
lines changed

Some content is hidden

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

48 files changed

+112
-116
lines changed

.github/workflows/tests.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
with:
1919
coverage: "none"
2020
ini-values: "memory_limit=-1"
21-
php-version: "8.2"
21+
php-version: "8.4"
2222
tools: "composer"
2323

2424
- name: Install vendors
@@ -43,7 +43,7 @@ jobs:
4343
with:
4444
coverage: "none"
4545
ini-values: "memory_limit=-1"
46-
php-version: "8.2"
46+
php-version: "8.4"
4747
tools: "composer"
4848

4949
- name: Install vendors
@@ -58,7 +58,7 @@ jobs:
5858

5959
strategy:
6060
matrix:
61-
php: [ '8.2', '8.3', '8.4' ]
61+
php: [ '8.4', '8.5' ]
6262

6363
steps:
6464
- name: Checkout

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM php:8.2-cli
1+
FROM php:8.4-cli
22

33
LABEL org.opencontainers.image.authors="Vitalii Zhuk <v.zhuk@fivelab.org>"
44

composer.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,17 @@
1818
],
1919

2020
"require": {
21-
"php": "~8.2"
21+
"php": "~8.4"
22+
},
23+
24+
"conflict": {
25+
"squizlabs/php_codesniffer": "<4"
2226
},
2327

2428
"require-dev": {
2529
"phpunit/phpunit": "~11.0",
2630
"phpstan/phpstan": "~2.0",
27-
"escapestudios/symfony2-coding-standard": "~3.13"
31+
"escapestudios/symfony2-coding-standard": "~3.17"
2832
},
2933

3034
"suggest": {

src/PhpCs/FiveLab/PhpCsUtils.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,15 @@ public static function getDiffLines(File $file, int $fromPtr, int $toPtr): int
6161

6262
if ($token['code'] === T_WHITESPACE && $token['content'] === $file->eolChar) {
6363
$diffLines++;
64-
} elseif (\in_array($token['code'], Tokens::$commentTokens, true)) {
64+
} elseif (\in_array($token['code'], Tokens::COMMENT_TOKENS, true)) {
6565
if ($token['code'] === T_DOC_COMMENT_OPEN_TAG) {
6666
$i = $file->findNext([T_DOC_COMMENT_CLOSE_TAG], $i + 1);
6767
} elseif ($token['code'] === T_COMMENT) {
6868
$tokensOnLine = self::getTokensOnLine($file, $token['line']);
6969
$existCodeOnLine = false;
7070

7171
foreach ($tokensOnLine as $tokenOnLine) {
72-
if (!\in_array($tokenOnLine['code'], Tokens::$emptyTokens, true)) {
72+
if (!\in_array($tokenOnLine['code'], Tokens::EMPTY_TOKENS, true)) {
7373
$existCodeOnLine = true;
7474
}
7575
}
@@ -146,7 +146,7 @@ public static function getDeclaredClassName(File $file): ?string
146146
if ($nsStart) {
147147
$nsEnd = $file->findNext([T_NS_SEPARATOR, T_STRING, T_WHITESPACE], $nsStart + 1, null, true);
148148

149-
$namespace = \trim(self::getContentsBetweenPtrs($file, $nsStart + 1, (int) $nsEnd));
149+
$namespace = \trim(self::getContentsBetweenPtrs($file, $nsStart + 1, (int) $nsEnd + 1));
150150
}
151151

152152
$declaredPtr = $file->findNext([T_CLASS, T_INTERFACE, T_TRAIT], 0);

src/PhpCs/FiveLab/Sniffs/AbstractFunctionCallSniff.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ abstract class AbstractFunctionCallSniff implements Sniff
2424
{
2525
public function register(): array
2626
{
27-
return Tokens::$functionNameTokens;
27+
return Tokens::FUNCTION_NAME_TOKENS;
2828
}
2929

3030
final public function process(File $phpcsFile, mixed $stackPtr): void
3131
{
3232
$tokens = $phpcsFile->getTokens();
3333

34-
$ignoreTokens = Tokens::$emptyTokens;
34+
$ignoreTokens = Tokens::EMPTY_TOKENS;
3535
$ignoreTokens[] = T_BITWISE_AND;
3636

3737
$specialKeywordPtr = $phpcsFile->findPrevious($ignoreTokens, $stackPtr - 1, null, true);
@@ -42,7 +42,7 @@ final public function process(File $phpcsFile, mixed $stackPtr): void
4242
return;
4343
}
4444

45-
$openParenthesisPtr = $phpcsFile->findNext(Tokens::$emptyTokens, $stackPtr + 1, null, true);
45+
$openParenthesisPtr = $phpcsFile->findNext(Tokens::EMPTY_TOKENS, $stackPtr + 1, null, true);
4646

4747
if (!$openParenthesisPtr || $tokens[$openParenthesisPtr]['code'] !== T_OPEN_PARENTHESIS) {
4848
return;

src/PhpCs/FiveLab/Sniffs/Formatting/MultiLineSniff.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public function process(File $phpcsFile, mixed $stackPtr): void
4646
return (string) $token['code'];
4747
}, PhpCsUtils::getTokensOnLine($phpcsFile, $stmt['line']));
4848

49-
$diff = \array_values(\array_diff($lineTokens, Tokens::$emptyTokens));
49+
$diff = \array_values(\array_diff($lineTokens, Tokens::EMPTY_TOKENS));
5050

5151
$then = \array_search(T_INLINE_THEN, $diff);
5252
$else = \array_search(T_INLINE_ELSE, $diff);

src/PhpCs/FiveLab/Sniffs/Formatting/SemicolonSingleCharSniff.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function process(File $phpcsFile, mixed $stackPtr): void
3737
return (string) $token['code'];
3838
}, PhpCsUtils::getTokensOnLine($phpcsFile, $phpcsFile->getTokens()[$stackPtr]['line']));
3939

40-
$diff = \array_diff($tokens, Tokens::$emptyTokens);
40+
$diff = \array_diff($tokens, Tokens::EMPTY_TOKENS);
4141

4242
if (1 === \count($diff)) {
4343
$phpcsFile->addError(

src/PhpCs/FiveLab/Sniffs/Formatting/ThrowSniff.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public function register(): array
3434
public function process(File $phpcsFile, mixed $stackPtr): void
3535
{
3636
// Check blank lines before
37-
$prevTokenPtr = $phpcsFile->findPrevious(Tokens::$emptyTokens, $stackPtr - 1, null, true);
37+
$prevTokenPtr = $phpcsFile->findPrevious(Tokens::EMPTY_TOKENS, $stackPtr - 1, null, true);
3838

3939
$prevToken = $phpcsFile->getTokens()[$prevTokenPtr];
4040
$diffLinesBefore = PhpCsUtils::getDiffLines($phpcsFile, (int) $prevTokenPtr, $stackPtr);
@@ -67,7 +67,7 @@ private function checkSprintfOnSameLine(File $phpcsFile, int $stackPtr): void
6767
}
6868

6969
$endOfMessagePtr = $phpcsFile->findNext([T_COMMA, T_SEMICOLON], $openParenthesisPtr);
70-
$sprintfTokenPtr = $phpcsFile->findNext([], $openParenthesisPtr, (int) $endOfMessagePtr, true, 'sprintf', true);
70+
$sprintfTokenPtr = $phpcsFile->findNext([], $openParenthesisPtr, (int) $endOfMessagePtr, true, '\sprintf', true);
7171

7272
if ($sprintfTokenPtr) {
7373
$tokens = $phpcsFile->getTokens();

src/PhpCs/FiveLab/Sniffs/Formatting/UnusedImportsSniff.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ public function process(File $phpcsFile, mixed $stackPtr): void
5454

5555
$import = $tokens[$currentStackPtr - 1]['content'];
5656

57+
$parts = \explode('\\', $import);
58+
$import = \end($parts);
59+
5760
$importStackPtr = $stackPtr;
5861

5962
while ($currentStackPtr = $phpcsFile->findNext(T_USE, ++$currentStackPtr)) {

src/PhpCs/FiveLab/Sniffs/Formatting/WhiteSpaceAroundControlStatementSniff.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,13 @@ public function process(File $phpcsFile, mixed $stackPtr): void
6969
}
7070

7171
// Check blank lines before statement
72-
$prevTokenPtr = $phpcsFile->findPrevious(Tokens::$emptyTokens, $stackPtr - 1, null, true);
72+
$prevTokenPtr = $phpcsFile->findPrevious(Tokens::EMPTY_TOKENS, $stackPtr - 1, null, true);
7373
$prevToken = $phpcsFile->getTokens()[$prevTokenPtr];
7474

7575
if (($prevToken['code'] === T_EQUAL || $prevToken['code'] === T_RETURN || $prevToken['code'] === T_DOUBLE_ARROW) && $stackToken['code'] === T_MATCH) {
7676
// Use "match" construction.
7777
$firstTokenPtr = PhpCsUtils::findFirstTokenOnLine($phpcsFile, $stackToken['line']);
78-
$prevTokenPtr = $phpcsFile->findPrevious(Tokens::$emptyTokens, $firstTokenPtr - 1, null, true);
78+
$prevTokenPtr = $phpcsFile->findPrevious(Tokens::EMPTY_TOKENS, $firstTokenPtr - 1, null, true);
7979
$prevToken = $phpcsFile->getTokens()[$prevTokenPtr];
8080
}
8181

@@ -92,14 +92,14 @@ public function process(File $phpcsFile, mixed $stackPtr): void
9292

9393
// Check blank lines after
9494
$scopeCloserPtr = $stackToken['scope_closer'];
95-
$nextTokenPtr = $phpcsFile->findNext(Tokens::$emptyTokens, $scopeCloserPtr + 1, null, true);
95+
$nextTokenPtr = $phpcsFile->findNext(Tokens::EMPTY_TOKENS, $scopeCloserPtr + 1, null, true);
9696

9797
if ($nextTokenPtr) {
9898
$nextToken = $phpcsFile->getTokens()[$nextTokenPtr];
9999

100100
if ($nextToken['code'] === T_SEMICOLON && $stackToken['code'] === T_MATCH) {
101101
// Use "match" construction.
102-
$nextTokenPtr = $phpcsFile->findNext(Tokens::$emptyTokens, $nextTokenPtr + 1, null, true);
102+
$nextTokenPtr = $phpcsFile->findNext(Tokens::EMPTY_TOKENS, $nextTokenPtr + 1, null, true);
103103
$nextToken = $nextTokenPtr ? $phpcsFile->getTokens()[$nextTokenPtr] : null;
104104
}
105105

0 commit comments

Comments
 (0)