Skip to content

Commit b063e6b

Browse files
dereuromarkclaude
andcommitted
Fix false positive in DocBlockVarSniff for array property types.
Resolves issue where the sniff incorrectly reported errors for array properties using alternative syntax like string[], int[], or array<K,V> in doc blocks when the property was typed as array. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent df955c5 commit b063e6b

File tree

3 files changed

+51
-2
lines changed

3 files changed

+51
-2
lines changed

PhpCollective/Sniffs/Commenting/DocBlockVarSniff.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,11 @@ protected function typesMatch(File $phpCsFile, string $docBlockType, string $pro
406406
return true;
407407
}
408408

409+
// Check if property type is 'array' and doc block contains array syntax
410+
if ($propertyType === 'array' && $this->containsTypeArray([$docBlockType])) {
411+
return true;
412+
}
413+
409414
// Get use statements
410415
$useStatements = $this->getUseStatements($phpCsFile);
411416

tests/_data/DocBlockVar/after.php

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class FixMe
3232
*
3333
* @var list<string|null>
3434
*/
35-
protected $left = [];
35+
protected array $left = [];
3636

3737
/**
3838
* @var \Tools\Mailer\Message
@@ -48,4 +48,26 @@ class FixMe
4848
* @var \Yet\Another\Thing
4949
*/
5050
protected AnotherAlias $another;
51+
52+
/**
53+
* @var string[]
54+
*/
55+
protected array $fixtures = [
56+
'plugin.QueueScheduler.SchedulerRows',
57+
];
58+
59+
/**
60+
* @var int[]
61+
*/
62+
protected array $numbers = [1, 2, 3];
63+
64+
/**
65+
* @var array<string, mixed>
66+
*/
67+
protected array $config = [];
68+
69+
/**
70+
* @var MyClass[]
71+
*/
72+
protected array $objects;
5173
}

tests/_data/DocBlockVar/before.php

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class FixMe
3232
*
3333
* @var list<string|null>
3434
*/
35-
protected $left = [];
35+
protected array $left = [];
3636

3737
/**
3838
* @var \Tools\Mailer\Message
@@ -48,4 +48,26 @@ class FixMe
4848
* @var \Yet\Another\Thing
4949
*/
5050
protected AnotherAlias $another;
51+
52+
/**
53+
* @var string[]
54+
*/
55+
protected array $fixtures = [
56+
'plugin.QueueScheduler.SchedulerRows',
57+
];
58+
59+
/**
60+
* @var int[]
61+
*/
62+
protected array $numbers = [1, 2, 3];
63+
64+
/**
65+
* @var array<string, mixed>
66+
*/
67+
protected array $config = [];
68+
69+
/**
70+
* @var MyClass[]
71+
*/
72+
protected array $objects;
5173
}

0 commit comments

Comments
 (0)