Skip to content

Commit 44b105c

Browse files
committed
"squizlabs/php_codesniffer": "^4.0.0"
1 parent ffe2a14 commit 44b105c

File tree

12 files changed

+61
-46
lines changed

12 files changed

+61
-46
lines changed

PhpCollective/Sniffs/Classes/MethodDeclarationSniff.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ protected function processTokenWithinScope(File $phpcsFile, $stackPtr, $currScop
4040
$tokens = $phpcsFile->getTokens();
4141

4242
$methodName = $phpcsFile->getDeclarationName($stackPtr);
43-
if ($methodName === null) {
43+
if (!$methodName) {
4444
// Ignore closures.
4545
return;
4646
}

PhpCollective/Sniffs/Classes/MethodTypeHintSniff.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public function process(File $phpcsFile, $stackPtr): void
5050
$j = $startIndex;
5151
$extractedUseStatement = '';
5252
while (true) {
53-
if (!$this->isGivenKind([T_NS_SEPARATOR, T_STRING, T_RETURN_TYPE], $tokens[$j])) {
53+
if (!$this->isGivenKind([T_NS_SEPARATOR, T_STRING], $tokens[$j])) {
5454
break;
5555
}
5656

PhpCollective/Sniffs/Commenting/DisallowArrayTypeHintSyntaxSniff.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ public function process(File $phpcsFile, $pointer): void
169169
*/
170170
protected function fixAnnotation(File $phpcsFile, Annotation $annotation, string $fixedAnnotation): void
171171
{
172-
/** @var \PHPStan\PhpDocParser\Ast\PhpDoc\ParamTagValueNode|mixed $value */
172+
/** @var \PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagValueNode $value */
173173
$value = $annotation->getNode()->value;
174174
$parameterName = $value->parameterName ?? '';
175175
$variableName = $value->variableName ?? '';
@@ -220,9 +220,9 @@ public function getArrayTypeNodes(Node $node): array
220220
/**
221221
* @param \PHPStan\PhpDocParser\Ast\Node $node
222222
*
223-
* @return \PHPStan\PhpDocParser\Ast\Node|list<\PHPStan\PhpDocParser\Ast\Node>|\PHPStan\PhpDocParser\Ast\NodeTraverser|int|null
223+
* @return int|null
224224
*/
225-
public function enterNode(Node $node): Node|array|\PHPStan\PhpDocParser\Ast\NodeTraverser|int|null
225+
public function enterNode(Node $node): int|null
226226
{
227227
if ($node instanceof ArrayTypeNode) {
228228
$this->nodes[] = $node;

PhpCollective/Sniffs/Commenting/DocBlockReturnVoidSniff.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ protected function assertTypeHint(File $phpcsFile, int $stackPtr, int $docBlockR
320320
$typehint = '?' . $typehint;
321321
}
322322

323-
if ($documentedReturnType !== 'void' && $typeHintIndex !== 'void') {
323+
if ($documentedReturnType !== 'void' && $typehint !== 'void') {
324324
return;
325325
}
326326
if ($documentedReturnType === $typehint) {

PhpCollective/Sniffs/Commenting/DocBlockThrowsSniff.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,12 @@ public function process(File $phpCsFile, $stackPointer): void
5151
return;
5252
}
5353

54-
if ($phpCsFile->getDeclarationName($stackPointer) === null) {
54+
try {
55+
$name = $phpCsFile->getDeclarationName($stackPointer);
56+
} catch (Exception $e) {
57+
return;
58+
}
59+
if (!$name) {
5560
return;
5661
}
5762

PhpCollective/Sniffs/Commenting/TypeHintSniff.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ public function process(File $phpcsFile, $stackPtr): void
126126
continue;
127127
}
128128

129-
/** @phpstan-var \PHPStan\PhpDocParser\Ast\Type\GenericTypeNode|\PHPStan\PhpDocParser\Ast\PhpDoc\PropertyTagValueNode|\PHPStan\PhpDocParser\Ast\PhpDoc\VarTagValueNode|\PHPStan\PhpDocParser\Ast\PhpDoc\ParamTagValueNode|\PHPStan\PhpDocParser\Ast\PhpDoc\ReturnTagValueNode $valueNode */
129+
/** @phpstan-var \PHPStan\PhpDocParser\Ast\PhpDoc\ParamTagValueNode|\PHPStan\PhpDocParser\Ast\PhpDoc\ReturnTagValueNode|\PHPStan\PhpDocParser\Ast\PhpDoc\VarTagValueNode $valueNode */
130130
if ($valueNode->type instanceof UnionTypeNode) {
131131
$types = $valueNode->type->types;
132132
} elseif ($valueNode->type instanceof ArrayTypeNode) {

PhpCollective/Sniffs/Formatting/ArrayDeclarationSniff.php

Lines changed: 27 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -291,39 +291,37 @@ public function processMultiLineArray(File $phpcsFile, int $stackPtr, int $array
291291
continue;
292292
}
293293

294-
if ($tokens[$nextToken]['code'] === T_DOUBLE_ARROW) {
295-
$currentEntry['arrow'] = $nextToken;
296-
$keyUsed = true;
294+
$currentEntry['arrow'] = $nextToken;
295+
$keyUsed = true;
297296

298-
// Find the start of index that uses this double arrow.
299-
$indexEnd = (int)$phpcsFile->findPrevious(T_WHITESPACE, ($nextToken - 1), $arrayStart, true);
300-
$indexStart = $phpcsFile->findStartOfStatement($indexEnd);
297+
// Find the start of index that uses this double arrow.
298+
$indexEnd = (int)$phpcsFile->findPrevious(T_WHITESPACE, ($nextToken - 1), $arrayStart, true);
299+
$indexStart = $phpcsFile->findStartOfStatement($indexEnd);
301300

302-
if ($indexStart === $indexEnd) {
303-
$currentEntry['index'] = $indexEnd;
304-
$currentEntry['index_content'] = $tokens[$indexEnd]['content'];
305-
} else {
306-
$currentEntry['index'] = $indexStart;
307-
$currentEntry['index_content'] = $phpcsFile->getTokensAsString($indexStart, ($indexEnd - $indexStart + 1));
308-
}
309-
310-
$indexLength = strlen($currentEntry['index_content']);
311-
if ($maxLength < $indexLength) {
312-
$maxLength = $indexLength;
313-
}
314-
315-
// Find the value of this index.
316-
$nextContent = $phpcsFile->findNext(
317-
Tokens::$emptyTokens,
318-
($nextToken + 1),
319-
$arrayEnd,
320-
true,
321-
);
301+
if ($indexStart === $indexEnd) {
302+
$currentEntry['index'] = $indexEnd;
303+
$currentEntry['index_content'] = $tokens[$indexEnd]['content'];
304+
} else {
305+
$currentEntry['index'] = $indexStart;
306+
$currentEntry['index_content'] = $phpcsFile->getTokensAsString($indexStart, ($indexEnd - $indexStart + 1));
307+
}
322308

323-
$currentEntry['value'] = $nextContent;
324-
$indices[] = $currentEntry;
325-
$lastToken = $nextToken;
309+
$indexLength = strlen($currentEntry['index_content']);
310+
if ($maxLength < $indexLength) {
311+
$maxLength = $indexLength;
326312
}
313+
314+
// Find the value of this index.
315+
$nextContent = $phpcsFile->findNext(
316+
Tokens::$emptyTokens,
317+
($nextToken + 1),
318+
$arrayEnd,
319+
true,
320+
);
321+
322+
$currentEntry['value'] = $nextContent;
323+
$indices[] = $currentEntry;
324+
$lastToken = $nextToken;
327325
}
328326

329327
$numValues = count($indices);

PhpCollective/Sniffs/Namespaces/UseStatementSniff.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,7 @@ protected function checkUseForReturnTypeHint(File $phpcsFile, int $stackPtr): vo
574574
$extractedUseStatement = '';
575575
$lastSeparatorIndex = null;
576576
while (true) {
577-
if (!$this->isGivenKind([T_NS_SEPARATOR, T_STRING, T_RETURN_TYPE], $tokens[$j])) {
577+
if (!$this->isGivenKind([T_NS_SEPARATOR, T_STRING], $tokens[$j])) {
578578
break;
579579
}
580580

@@ -644,7 +644,7 @@ protected function checkPropertyForInstanceOf(File $phpcsFile, int $stackPtr): v
644644
$extractedUseStatement = '';
645645
$lastSeparatorIndex = null;
646646
while (true) {
647-
if (!$this->isGivenKind([T_NS_SEPARATOR, T_STRING, T_RETURN_TYPE], $tokens[$j])) {
647+
if (!$this->isGivenKind([T_NS_SEPARATOR, T_STRING], $tokens[$j])) {
648648
break;
649649
}
650650

PhpCollective/Sniffs/WhiteSpace/DocBlockSpacingSniff.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,14 @@ class DocBlockSpacingSniff implements Sniff
2323
*/
2424
public function register(): array
2525
{
26-
return [T_CLASS, T_INTERFACE, T_TRAIT, T_FUNCTION, T_PROPERTY];
26+
$tokens = [T_CLASS, T_INTERFACE, T_TRAIT, T_FUNCTION];
27+
28+
// T_PROPERTY was introduced in PHP 8.4 for property hooks
29+
if (defined('T_PROPERTY')) {
30+
$tokens[] = T_PROPERTY;
31+
}
32+
33+
return $tokens;
2734
}
2835

2936
/**

composer.json

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@
2323
],
2424
"require": {
2525
"php": ">=8.1",
26-
"phpcsstandards/phpcsextra": "^1.2.0",
27-
"slevomat/coding-standard": "^8.16.0",
28-
"squizlabs/php_codesniffer": "^3.11.3"
26+
"phpcsstandards/phpcsextra": "dev-develop",
27+
"slevomat/coding-standard": "dev-phpcs4",
28+
"squizlabs/php_codesniffer": "^4.0.0"
2929
},
3030
"require-dev": {
31-
"phpstan/phpstan": "^1.0.0",
31+
"phpstan/phpstan": "^2.0.0",
3232
"phpunit/phpunit": "^10.3 || ^11.2 || ^12.0"
3333
},
3434
"autoload": {
@@ -72,5 +72,7 @@
7272
"allow-plugins": {
7373
"dealerdirect/phpcodesniffer-composer-installer": true
7474
}
75-
}
75+
},
76+
"minimum-stability": "dev",
77+
"prefer-stable": true
7678
}

0 commit comments

Comments
 (0)