Skip to content

Commit 1208925

Browse files
Solve deprecations
1 parent 3dd65e7 commit 1208925

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
@@ -67,6 +67,7 @@ private function processSingleProperty(Scope $scope, PropertyFetch $node, string
6767
$scope,
6868
NullsafeOperatorHelper::getNullsafeShortcircuitedExprRespectingScope($scope, $node->var),
6969
sprintf('Access to property $%s on an unknown class %%s.', SprintfHelper::escapeFormatString($name)),
70+
// TODO use hasInstanceProperty
7071
static fn (Type $type): bool => $type->canAccessProperties()->yes() && $type->hasProperty($name)->yes(),
7172
);
7273
$type = $typeResult->getType();
@@ -93,6 +94,7 @@ private function processSingleProperty(Scope $scope, PropertyFetch $node, string
9394
];
9495
}
9596

97+
// TODO use hasInstanceProperty
9698
$has = $type->hasProperty($name);
9799
if (!$has->no() && $this->canAccessUndefinedProperties($scope, $node)) {
98100
return [];
@@ -124,12 +126,12 @@ private function processSingleProperty(Scope $scope, PropertyFetch $node, string
124126
$propertyClassReflection = $this->reflectionProvider->getClass($classNames[0]);
125127
$parentClassReflection = $propertyClassReflection->getParentClass();
126128
while ($parentClassReflection !== null) {
127-
if ($parentClassReflection->hasProperty($name)) {
129+
if ($parentClassReflection->hasInstanceProperty($name)) {
128130
if ($write) {
129-
if ($scope->canWriteProperty($parentClassReflection->getProperty($name, $scope))) {
131+
if ($scope->canWriteProperty($parentClassReflection->getInstanceProperty($name, $scope))) {
130132
return [];
131133
}
132-
} elseif ($scope->canReadProperty($parentClassReflection->getProperty($name, $scope))) {
134+
} elseif ($scope->canReadProperty($parentClassReflection->getInstanceProperty($name, $scope))) {
133135
return [];
134136
}
135137

@@ -173,6 +175,7 @@ private function processSingleProperty(Scope $scope, PropertyFetch $node, string
173175
];
174176
}
175177

178+
// TODO use getInstanceProperty
176179
$propertyReflection = $type->getProperty($name, $scope);
177180
if ($propertyReflection->isStatic()) {
178181
return [

src/Rules/Properties/AccessStaticPropertiesRule.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ private function processSingleProperty(Scope $scope, StaticPropertyFetch $node,
151151
$scope,
152152
NullsafeOperatorHelper::getNullsafeShortcircuitedExprRespectingScope($scope, $node->class),
153153
sprintf('Access to static property $%s on an unknown class %%s.', SprintfHelper::escapeFormatString($name)),
154+
// TODO Use hasStaticProperty
154155
static fn (Type $type): bool => $type->canAccessProperties()->yes() && $type->hasProperty($name)->yes(),
155156
);
156157
$classType = $classTypeResult->getType();
@@ -183,6 +184,7 @@ private function processSingleProperty(Scope $scope, StaticPropertyFetch $node,
183184
]);
184185
}
185186

187+
// TODO Use hasStaticProperty
186188
$has = $classType->hasProperty($name);
187189
if (!$has->no() && $scope->isUndefinedExpressionAllowed($node)) {
188190
return [];
@@ -199,8 +201,8 @@ private function processSingleProperty(Scope $scope, StaticPropertyFetch $node,
199201
$parentClassReflection = $propertyClassReflection->getParentClass();
200202

201203
while ($parentClassReflection !== null) {
202-
if ($parentClassReflection->hasProperty($name)) {
203-
if ($scope->canReadProperty($parentClassReflection->getProperty($name, $scope))) {
204+
if ($parentClassReflection->hasStaticProperty($name)) {
205+
if ($scope->canReadProperty($parentClassReflection->getStaticProperty($name, $scope))) {
204206
return [];
205207
}
206208
return [
@@ -225,6 +227,7 @@ private function processSingleProperty(Scope $scope, StaticPropertyFetch $node,
225227
]);
226228
}
227229

230+
// TODO Use getStaticProperty and update the if
228231
$property = $classType->getProperty($name, $scope);
229232
if (!$property->isStatic()) {
230233
$hasPropertyTypes = TypeUtils::getHasPropertyTypes($classType);

0 commit comments

Comments
 (0)