Skip to content

Commit f19e8bc

Browse files
Solve deprecations
1 parent 859b43d commit f19e8bc

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
@@ -97,6 +97,7 @@ private function processSingleProperty(Scope $scope, PropertyFetch $node, string
9797
$scope,
9898
NullsafeOperatorHelper::getNullsafeShortcircuitedExprRespectingScope($scope, $node->var),
9999
sprintf('Access to property $%s on an unknown class %%s.', SprintfHelper::escapeFormatString($name)),
100+
// TODO use hasInstanceProperty
100101
static fn (Type $type): bool => $type->canAccessProperties()->yes() && $type->hasProperty($name)->yes(),
101102
);
102103
$type = $typeResult->getType();
@@ -123,6 +124,7 @@ private function processSingleProperty(Scope $scope, PropertyFetch $node, string
123124
];
124125
}
125126

127+
// TODO use hasInstanceProperty
126128
$has = $type->hasProperty($name);
127129
if (!$has->no() && $this->canAccessUndefinedProperties($scope, $node)) {
128130
return [];
@@ -154,12 +156,12 @@ private function processSingleProperty(Scope $scope, PropertyFetch $node, string
154156
$propertyClassReflection = $this->reflectionProvider->getClass($classNames[0]);
155157
$parentClassReflection = $propertyClassReflection->getParentClass();
156158
while ($parentClassReflection !== null) {
157-
if ($parentClassReflection->hasProperty($name)) {
159+
if ($parentClassReflection->hasInstanceProperty($name)) {
158160
if ($write) {
159-
if ($scope->canWriteProperty($parentClassReflection->getProperty($name, $scope))) {
161+
if ($scope->canWriteProperty($parentClassReflection->getInstanceProperty($name, $scope))) {
160162
return [];
161163
}
162-
} elseif ($scope->canReadProperty($parentClassReflection->getProperty($name, $scope))) {
164+
} elseif ($scope->canReadProperty($parentClassReflection->getInstanceProperty($name, $scope))) {
163165
return [];
164166
}
165167

@@ -203,6 +205,7 @@ private function processSingleProperty(Scope $scope, PropertyFetch $node, string
203205
];
204206
}
205207

208+
// TODO use getInstanceProperty
206209
$propertyReflection = $type->getProperty($name, $scope);
207210
if ($propertyReflection->isStatic()) {
208211
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)