Skip to content

Commit 1c67dc6

Browse files
phpstan-botclaude
andcommitted
Extract magic string to named constant DYNAMIC_PROPERTY_NAME
Address review feedback: the magic string '__phpstan_dynamic_property' is now a private constant with a docblock explaining its purpose. It serves as a representative property name for dynamic property access resolution ($obj->{$expr}), allowing PropertiesClassReflectionExtensions that accept any property name to return the correct type. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 721d265 commit 1c67dc6

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/Analyser/ExprHandler/PropertyFetchHandler.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,14 @@
3333
final class PropertyFetchHandler implements ExprHandler
3434
{
3535

36+
/**
37+
* Representative property name used when resolving dynamic property access ($obj->{$expr}).
38+
* The actual name doesn't matter — it just needs to be non-empty so that
39+
* PropertiesClassReflectionExtensions (e.g. SimpleXMLElement) that accept
40+
* any property name can return the correct type.
41+
*/
42+
private const DYNAMIC_PROPERTY_NAME = '__phpstan_dynamic_property';
43+
3644
public function __construct(
3745
private PhpVersion $phpVersion,
3846
private PropertyReflectionFinder $propertyReflectionFinder,
@@ -132,7 +140,7 @@ public function resolveType(MutatingScope $scope, Expr $expr): Type
132140

133141
if ($nameType->isString()->yes()) {
134142
$fetchedOnType = $scope->getType($expr->var);
135-
$returnType = $this->propertyFetchType($scope, $fetchedOnType, '__phpstan_dynamic_property', $expr);
143+
$returnType = $this->propertyFetchType($scope, $fetchedOnType, self::DYNAMIC_PROPERTY_NAME, $expr);
136144
if ($returnType !== null) {
137145
return NullsafeShortCircuitingHelper::getType($scope, $expr->var, $returnType);
138146
}

0 commit comments

Comments
 (0)