Skip to content

Commit a466298

Browse files
Solve deprecations
1 parent 0edde2b commit a466298

File tree

4 files changed

+18
-8
lines changed

4 files changed

+18
-8
lines changed

Diff for: src/Dependency/DependencyResolver.php

+6-2
Original file line numberDiff line numberDiff line change
@@ -369,8 +369,12 @@ public function resolveDependencies(Node $node, Scope $scope): NodeDependencies
369369
$className = $scope->resolveName($node->class);
370370
if ($this->reflectionProvider->hasClass($className)) {
371371
$propertyClassReflection = $this->reflectionProvider->getClass($className);
372-
if ($propertyClassReflection->hasProperty($node->name->toString())) {
373-
$propertyReflection = $propertyClassReflection->getProperty($node->name->toString(), $scope);
372+
if ($propertyClassReflection->hasInstanceProperty($node->name->toString())) {
373+
$propertyReflection = $propertyClassReflection->getInstanceProperty($node->name->toString(), $scope);
374+
$this->addClassToDependencies($propertyReflection->getDeclaringClass()->getName(), $dependenciesReflections);
375+
}
376+
if ($propertyClassReflection->hasStaticProperty($node->name->toString())) {
377+
$propertyReflection = $propertyClassReflection->getStaticProperty($node->name->toString(), $scope);
374378
$this->addClassToDependencies($propertyReflection->getDeclaringClass()->getName(), $dependenciesReflections);
375379
}
376380
}

Diff for: src/Rules/Properties/AccessPropertiesCheck.php

+6-3
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ private function processSingleProperty(Scope $scope, PropertyFetch $node, string
6464
$scope,
6565
NullsafeOperatorHelper::getNullsafeShortcircuitedExprRespectingScope($scope, $node->var),
6666
sprintf('Access to property $%s on an unknown class %%s.', SprintfHelper::escapeFormatString($name)),
67+
// TODO use hasInstanceProperty
6768
static fn (Type $type): bool => $type->canAccessProperties()->yes() && $type->hasProperty($name)->yes(),
6869
);
6970
$type = $typeResult->getType();
@@ -90,6 +91,7 @@ private function processSingleProperty(Scope $scope, PropertyFetch $node, string
9091
];
9192
}
9293

94+
// TODO use hasInstanceProperty
9395
$has = $type->hasProperty($name);
9496
if (!$has->no() && $this->canAccessUndefinedProperties($scope, $node)) {
9597
return [];
@@ -121,12 +123,12 @@ private function processSingleProperty(Scope $scope, PropertyFetch $node, string
121123
$propertyClassReflection = $this->reflectionProvider->getClass($classNames[0]);
122124
$parentClassReflection = $propertyClassReflection->getParentClass();
123125
while ($parentClassReflection !== null) {
124-
if ($parentClassReflection->hasProperty($name)) {
126+
if ($parentClassReflection->hasInstanceProperty($name)) {
125127
if ($write) {
126-
if ($scope->canWriteProperty($parentClassReflection->getProperty($name, $scope))) {
128+
if ($scope->canWriteProperty($parentClassReflection->getInstanceProperty($name, $scope))) {
127129
return [];
128130
}
129-
} elseif ($scope->canReadProperty($parentClassReflection->getProperty($name, $scope))) {
131+
} elseif ($scope->canReadProperty($parentClassReflection->getInstanceProperty($name, $scope))) {
130132
return [];
131133
}
132134

@@ -159,6 +161,7 @@ private function processSingleProperty(Scope $scope, PropertyFetch $node, string
159161
];
160162
}
161163

164+
// TODO use getInstanceProperty
162165
$propertyReflection = $type->getProperty($name, $scope);
163166
if ($propertyReflection->isStatic()) {
164167
return [

Diff for: src/Rules/Properties/AccessStaticPropertiesRule.php

+5-2
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ private function processSingleProperty(Scope $scope, StaticPropertyFetch $node,
135135
$scope,
136136
NullsafeOperatorHelper::getNullsafeShortcircuitedExprRespectingScope($scope, $node->class),
137137
sprintf('Access to static property $%s on an unknown class %%s.', SprintfHelper::escapeFormatString($name)),
138+
// TODO Use hasStaticProperty
138139
static fn (Type $type): bool => $type->canAccessProperties()->yes() && $type->hasProperty($name)->yes(),
139140
);
140141
$classType = $classTypeResult->getType();
@@ -167,6 +168,7 @@ private function processSingleProperty(Scope $scope, StaticPropertyFetch $node,
167168
]);
168169
}
169170

171+
// TODO Use hasStaticProperty
170172
$has = $classType->hasProperty($name);
171173
if (!$has->no() && $scope->isUndefinedExpressionAllowed($node)) {
172174
return [];
@@ -183,8 +185,8 @@ private function processSingleProperty(Scope $scope, StaticPropertyFetch $node,
183185
$parentClassReflection = $propertyClassReflection->getParentClass();
184186

185187
while ($parentClassReflection !== null) {
186-
if ($parentClassReflection->hasProperty($name)) {
187-
if ($scope->canReadProperty($parentClassReflection->getProperty($name, $scope))) {
188+
if ($parentClassReflection->hasStaticProperty($name)) {
189+
if ($scope->canReadProperty($parentClassReflection->getStaticProperty($name, $scope))) {
188190
return [];
189191
}
190192
return [
@@ -209,6 +211,7 @@ private function processSingleProperty(Scope $scope, StaticPropertyFetch $node,
209211
]);
210212
}
211213

214+
// TODO Use getStaticProperty and update the if
212215
$property = $classType->getProperty($name, $scope);
213216
if (!$property->isStatic()) {
214217
$hasPropertyTypes = TypeUtils::getHasPropertyTypes($classType);

Diff for: src/Type/Php/ReflectionPropertyConstructorThrowTypeExtension.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public function getThrowTypeFromStaticMethodCall(MethodReflection $methodReflect
4040

4141
$classReflection = $this->reflectionProvider->getClass($constantString->getValue());
4242
foreach ($propertyType->getConstantStrings() as $constantPropertyString) {
43-
if (!$classReflection->hasProperty($constantPropertyString->getValue())) {
43+
if (!$classReflection->hasInstanceProperty($constantPropertyString->getValue())) {
4444
return $methodReflection->getThrowType();
4545
}
4646
}

0 commit comments

Comments
 (0)