Skip to content

Commit 0873de4

Browse files
Solve deprecations
1 parent 8029167 commit 0873de4

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

src/Rules/Properties/AccessPropertiesCheck.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ private function processSingleProperty(Scope $scope, PropertyFetch $node, string
9191
$scope,
9292
NullsafeOperatorHelper::getNullsafeShortcircuitedExprRespectingScope($scope, $node->var),
9393
sprintf('Access to property $%s on an unknown class %%s.', SprintfHelper::escapeFormatString($name)),
94+
// TODO use hasInstanceProperty
9495
static fn (Type $type): bool => $type->canAccessProperties()->yes() && $type->hasProperty($name)->yes(),
9596
);
9697
$type = $typeResult->getType();
@@ -117,6 +118,7 @@ private function processSingleProperty(Scope $scope, PropertyFetch $node, string
117118
];
118119
}
119120

121+
// TODO use hasInstanceProperty
120122
$has = $type->hasProperty($name);
121123
if (!$has->no() && $this->canAccessUndefinedProperties($scope, $node)) {
122124
return [];
@@ -148,12 +150,12 @@ private function processSingleProperty(Scope $scope, PropertyFetch $node, string
148150
$propertyClassReflection = $this->reflectionProvider->getClass($classNames[0]);
149151
$parentClassReflection = $propertyClassReflection->getParentClass();
150152
while ($parentClassReflection !== null) {
151-
if ($parentClassReflection->hasProperty($name)) {
153+
if ($parentClassReflection->hasInstanceProperty($name)) {
152154
if ($write) {
153-
if ($scope->canWriteProperty($parentClassReflection->getProperty($name, $scope))) {
155+
if ($scope->canWriteProperty($parentClassReflection->getInstanceProperty($name, $scope))) {
154156
return [];
155157
}
156-
} elseif ($scope->canReadProperty($parentClassReflection->getProperty($name, $scope))) {
158+
} elseif ($scope->canReadProperty($parentClassReflection->getInstanceProperty($name, $scope))) {
157159
return [];
158160
}
159161

@@ -197,6 +199,7 @@ private function processSingleProperty(Scope $scope, PropertyFetch $node, string
197199
];
198200
}
199201

202+
// TODO use getInstanceProperty
200203
$propertyReflection = $type->getProperty($name, $scope);
201204
if ($propertyReflection->isStatic()) {
202205
return [

src/Rules/Properties/AccessStaticPropertiesRule.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ private function processSingleProperty(Scope $scope, StaticPropertyFetch $node,
155155
$scope,
156156
NullsafeOperatorHelper::getNullsafeShortcircuitedExprRespectingScope($scope, $node->class),
157157
sprintf('Access to static property $%s on an unknown class %%s.', SprintfHelper::escapeFormatString($name)),
158+
// TODO Use hasStaticProperty
158159
static fn (Type $type): bool => $type->canAccessProperties()->yes() && $type->hasProperty($name)->yes(),
159160
);
160161
$classType = $classTypeResult->getType();
@@ -187,6 +188,7 @@ private function processSingleProperty(Scope $scope, StaticPropertyFetch $node,
187188
]);
188189
}
189190

191+
// TODO Use hasStaticProperty
190192
$has = $classType->hasProperty($name);
191193
if (!$has->no() && $scope->isUndefinedExpressionAllowed($node)) {
192194
return [];
@@ -203,8 +205,8 @@ private function processSingleProperty(Scope $scope, StaticPropertyFetch $node,
203205
$parentClassReflection = $propertyClassReflection->getParentClass();
204206

205207
while ($parentClassReflection !== null) {
206-
if ($parentClassReflection->hasProperty($name)) {
207-
if ($scope->canReadProperty($parentClassReflection->getProperty($name, $scope))) {
208+
if ($parentClassReflection->hasStaticProperty($name)) {
209+
if ($scope->canReadProperty($parentClassReflection->getStaticProperty($name, $scope))) {
208210
return [];
209211
}
210212
return [
@@ -229,6 +231,7 @@ private function processSingleProperty(Scope $scope, StaticPropertyFetch $node,
229231
]);
230232
}
231233

234+
// TODO Use getStaticProperty and update the if
232235
$property = $classType->getProperty($name, $scope);
233236
if (!$property->isStatic()) {
234237
$hasPropertyTypes = TypeUtils::getHasPropertyTypes($classType);

0 commit comments

Comments
 (0)