Skip to content

Commit 02d3d7f

Browse files
committed
Fix linting errors
1 parent b9bf7ed commit 02d3d7f

File tree

3 files changed

+73
-31
lines changed

3 files changed

+73
-31
lines changed

VariableAnalysis/Lib/Helpers.php

Lines changed: 20 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public static function findContainingOpeningBracket(File $phpcsFile, $stackPtr)
9393
$tokens = $phpcsFile->getTokens();
9494
if (isset($tokens[$stackPtr]['nested_parenthesis'])) {
9595
/**
96-
* @var array<int|string|null>
96+
* @var list<int|string>
9797
*/
9898
$openPtrs = array_keys($tokens[$stackPtr]['nested_parenthesis']);
9999
return (int)end($openPtrs);
@@ -364,9 +364,6 @@ public static function findFunctionCallArguments(File $phpcsFile, $stackPtr)
364364
if (self::findContainingOpeningBracket($phpcsFile, $nextPtr) === $openPtr) {
365365
// Comma is at our level of brackets, it's an argument delimiter.
366366
$range = range($lastArgComma + 1, $nextPtr - 1);
367-
$range = array_filter($range, function ($element) {
368-
return is_int($element);
369-
});
370367
array_push($argPtrs, $range);
371368
$lastArgComma = $nextPtr;
372369
}
@@ -384,93 +381,85 @@ public static function findFunctionCallArguments(File $phpcsFile, $stackPtr)
384381

385382
/**
386383
* Compatibility handler for phpcs 3.x/4.x
387-
* @return array
384+
* @return array<int|string, int|string>
388385
*/
389386
public static function getOoScopeTokens()
390387
{
391388
if (defined('Tokens::OO_SCOPE_TOKENS')) {
392389
return Tokens::OO_SCOPE_TOKENS;
393390
}
394-
if (isset(Tokens::$ooScopeTokens)) {
395-
return Tokens::$ooScopeTokens;
396-
}
397-
return [];
391+
return Tokens::$ooScopeTokens;
398392
}
399393

400394
/**
401395
* Compatibility handler for phpcs 3.x/4.x
402-
* @return array
396+
* @return array<int|string, int|string>
403397
*/
404398
public static function getFunctionNameTokens()
405399
{
406400
if (defined('Tokens::FUNCTION_NAME_TOKENS')) {
407401
return Tokens::FUNCTION_NAME_TOKENS;
408402
}
409-
if (isset(Tokens::$functionNameTokens)) {
410-
return Tokens::$functionNameTokens;
411-
}
412-
return [];
403+
return Tokens::$functionNameTokens;
413404
}
414405

415406
/**
416407
* Compatibility handler for phpcs 3.x/4.x
417-
* @return array
408+
* @return array<int|string, int|string>
418409
*/
419410
public static function getEmptyTokens()
420411
{
421412
if (defined('Tokens::EMPTY_TOKENS')) {
422413
return Tokens::EMPTY_TOKENS;
423414
}
424-
if (isset(Tokens::$emptyTokens)) {
425-
return Tokens::$emptyTokens;
426-
}
427-
return [];
415+
return Tokens::$emptyTokens;
428416
}
429417

430418
/**
431419
* Compatibility handler for phpcs 3.x/4.x
432-
* @return array
420+
* @return array<int|string, int|string>
433421
*/
434422
private static function getScopeModifiers()
435423
{
436424
if (defined('Tokens::SCOPE_MODIFIERS')) {
437425
return Tokens::SCOPE_MODIFIERS;
438426
}
439-
if (isset(Tokens::$scopeModifiers)) {
440-
return Tokens::$scopeModifiers;
441-
}
442-
return [];
427+
return Tokens::$scopeModifiers;
443428
}
444429

445430
/**
446431
* Compatibility handler for phpcs 3.x/4.x
447-
* @param array $tokens
448-
* @param int $tokenIndex
432+
* @param array<int|string, array<int|string, int|string|array<int|string, int|string>>> $tokens
433+
* @param int $tokenIndex
449434
* @return bool
450435
*/
451436
private static function hasScopeOpener($tokens, $tokenIndex)
452437
{
438+
/** @phpstan-ignore-next-line offsetAccess.invalidOffset - code is always int|string */
453439
if (defined('Tokens::SCOPE_OPENERS') && isset(Tokens::SCOPE_OPENERS[$tokens[$tokenIndex]['code']])) {
454440
return true;
455441
}
456-
if (isset(Tokens::$scopeOpeners) && isset(Tokens::$scopeOpeners[$tokens[$tokenIndex]['code']])) {
442+
/** @phpstan-ignore-next-line property.notFound,offsetAccess.invalidOffset - property exists in PHPCS 3.x */
443+
if (isset(Tokens::$scopeOpeners[$tokens[$tokenIndex]['code']])) {
457444
return true;
458445
}
459446
return false;
460447
}
461448

462449
/**
463450
* Compatibility handler for phpcs 3.x/4.x
464-
* @param array $tokens
465-
* @param int $tokenIndex
451+
* @param array<int|string, array<int|string, int|string|array<int|string, int|string>>> $tokens
452+
* @param int $tokenIndex
466453
* @return bool
467454
*/
468455
private static function hasAssignmentToken($tokens, $tokenIndex)
469456
{
457+
/** @phpstan-ignore-next-line offsetAccess.invalidOffset - code is always int|string */
470458
if (defined('Tokens::ASSIGNMENT_TOKENS') && isset(Tokens::ASSIGNMENT_TOKENS[$tokens[$tokenIndex]['code']])) {
471459
return true;
472460
}
473-
if (isset(Tokens::$assignmentTokens) && isset(Tokens::$assignmentTokens[$tokens[$tokenIndex]['code']])) {
461+
/** @phpstan-ignore-next-line property.notFound,offsetAccess.invalidOffset - property exists in PHPCS 3.x */
462+
if (isset(Tokens::$assignmentTokens[$tokens[$tokenIndex]['code']])) {
474463
return true;
475464
}
476465
return false;
@@ -1386,7 +1375,7 @@ public static function getFunctionIndexForFunctionCallArgument(File $phpcsFile,
13861375
return null;
13871376
}
13881377
/**
1389-
* @var array<int|string|null>
1378+
* @var list<int|string>
13901379
*/
13911380
$startingParenthesis = array_keys($token['nested_parenthesis']);
13921381
$startOfArguments = end($startingParenthesis);

psalm-baseline.xml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<files psalm-version="6.13.1@1e3b7f0a8ab32b23197b91107adc0a7ed8a05b51">
3+
<file src="VariableAnalysis/Lib/EnumInfo.php">
4+
<PossiblyUnusedProperty>
5+
<code><![CDATA[$enumIndex]]></code>
6+
</PossiblyUnusedProperty>
7+
</file>
8+
<file src="VariableAnalysis/Lib/ForLoopInfo.php">
9+
<PossiblyUnusedProperty>
10+
<code><![CDATA[$conditionEnd]]></code>
11+
<code><![CDATA[$conditionStart]]></code>
12+
<code><![CDATA[$forIndex]]></code>
13+
<code><![CDATA[$initEnd]]></code>
14+
<code><![CDATA[$initStart]]></code>
15+
</PossiblyUnusedProperty>
16+
</file>
17+
<file src="VariableAnalysis/Lib/Helpers.php">
18+
<InvalidArgument>
19+
<code><![CDATA[$closePtr]]></code>
20+
</InvalidArgument>
21+
<InvalidOperand>
22+
<code><![CDATA[$closePtr]]></code>
23+
</InvalidOperand>
24+
<PossiblyFalseArgument>
25+
<code><![CDATA[$varName]]></code>
26+
<code><![CDATA[$varName]]></code>
27+
</PossiblyFalseArgument>
28+
<PossiblyInvalidOperand>
29+
<code><![CDATA[$message]]></code>
30+
</PossiblyInvalidOperand>
31+
<PossiblyUnusedMethod>
32+
<code><![CDATA[isTokenInsideArrowFunctionDefinition]]></code>
33+
</PossiblyUnusedMethod>
34+
<UnusedVariable>
35+
<code><![CDATA[$isNestedAssignment]]></code>
36+
</UnusedVariable>
37+
</file>
38+
<file src="VariableAnalysis/Lib/VariableInfo.php">
39+
<PossiblyUnusedProperty>
40+
<code><![CDATA[$typeHint]]></code>
41+
</PossiblyUnusedProperty>
42+
</file>
43+
<file src="VariableAnalysis/Sniffs/CodeAnalysis/VariableAnalysisSniff.php">
44+
<MissingOverrideAttribute>
45+
<code><![CDATA[public function process(File $phpcsFile, $stackPtr)]]></code>
46+
<code><![CDATA[public function register()]]></code>
47+
</MissingOverrideAttribute>
48+
<UnusedClass>
49+
<code><![CDATA[VariableAnalysisSniff]]></code>
50+
</UnusedClass>
51+
</file>
52+
</files>

psalm.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
77
xmlns="https://getpsalm.org/schema/config"
88
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
9+
errorBaseline="psalm-baseline.xml"
910
>
1011
<projectFiles>
1112
<directory name="VariableAnalysis" />

0 commit comments

Comments
 (0)