Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,10 @@ protected function isProperty(File $phpcsFile, int $stackPtr): bool {
T_TYPE_INTERSECTION,
T_ATTRIBUTE,
T_ATTRIBUTE_END,
// PHP 8+ namespaced type tokens.
T_NAME_FULLY_QUALIFIED,
T_NAME_QUALIFIED,
T_NAME_RELATIVE,
],
$stackPtr - 1,
NULL,
Expand Down Expand Up @@ -401,6 +405,10 @@ protected function isPromotedProperty(File $phpcs_file, int $stack_ptr): bool {
T_TYPE_INTERSECTION,
T_ATTRIBUTE,
T_ATTRIBUTE_END,
// PHP 8+ namespaced type tokens.
T_NAME_FULLY_QUALIFIED,
T_NAME_QUALIFIED,
T_NAME_RELATIVE,
],
$stack_ptr - 1,
NULL,
Expand Down
7 changes: 7 additions & 0 deletions tests/Fixtures/VariableNaming.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ class ClassWithMixedVariableNaming {

public static $camelCaseStaticProperty;

protected ?string $nullableProperty = NULL;

protected ?\DOMDocument $xmlDom = NULL;

protected ?\DateTime $dateTime = NULL;

public function methodWithMixedLocalVariables(): void {
$valid_snake_case_local = 'valid';
$another_valid_local = 123;
Expand Down Expand Up @@ -65,6 +71,7 @@ class ClassWithPromotedProperties {
public function __construct(
public string $promotedPropertyOne,
public string $promoted_property_two,
public ?\DOMDocument $promotedNullableProperty = NULL,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick | 🔵 Trivial

Consider shortening the variable name.

PHPMD flags $promotedNullableProperty as exceeding the recommended 20-character limit (26 characters). While this is test fixture code and the name is descriptive, consider a shorter alternative like $promotedNullableDom or $nullableDom for better readability.

Based on learnings from static analysis hints.

🧰 Tools
🪛 PHPMD (2.15.0)

74-74: Avoid excessively long variable names like $promotedNullableProperty. Keep variable name length under 20. (undefined)

(LongVariable)

🤖 Prompt for AI Agents
In tests/Fixtures/VariableNaming.php around line 74, the property name
$promotedNullableProperty is too long per PHPMD; shorten it (for example to
$promotedNullableDom or $nullableDom) and update every occurrence in this file
(constructor promotion, any references, docblocks) so the type and nullability
remain the same (\DOMDocument|null). Ensure consistency by renaming usages in
related tests/fixtures if referenced elsewhere.

) {
$localVar = 'invalid';
$valid_local = 'valid';
Expand Down
30 changes: 30 additions & 0 deletions tests/Unit/AbstractVariableNamingSniffTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,26 @@ public static function providerIsProperty(): array {
'bar',
FALSE,
],
'typed_property' => [
'<?php class Test { protected string $typedProperty; }',
'typedProperty',
TRUE,
],
'nullable_property' => [
'<?php class Test { protected ?string $nullableProperty = NULL; }',
'nullableProperty',
TRUE,
],
'nullable_fully_qualified_property' => [
'<?php class Test { protected ?\DOMDocument $xmlDom = NULL; }',
'xmlDom',
TRUE,
],
'nullable_qualified_property' => [
'<?php namespace App; class Test { protected ?Some\Type $property = NULL; }',
'property',
TRUE,
],
];
}

Expand Down Expand Up @@ -328,6 +348,16 @@ public static function providerIsPromotedProperty(): array {
'variable',
FALSE,
],
'promoted_nullable_property' => [
'<?php class Test { public function __construct(public ?string $property) {} }',
'property',
TRUE,
],
'promoted_nullable_fully_qualified_property' => [
'<?php class Test { public function __construct(public ?\DOMDocument $dom) {} }',
'dom',
TRUE,
],
];
}

Expand Down
Loading