Skip to content

Commit 637626e

Browse files
Solve deprecations
1 parent 0291c75 commit 637626e

12 files changed

+31
-47
lines changed

src/Analyser/MutatingScope.php

+7-2
Original file line numberDiff line numberDiff line change
@@ -4237,7 +4237,7 @@ public function assignInitializedProperty(Type $fetchedOnType, string $propertyN
42374237
return $this;
42384238
}
42394239

4240-
$propertyReflection = $this->getPropertyReflection($fetchedOnType, $propertyName);
4240+
$propertyReflection = $this->getInstancePropertyReflection($fetchedOnType, $propertyName);
42414241
if ($propertyReflection === null) {
42424242
return $this;
42434243
}
@@ -6109,7 +6109,12 @@ public function getStaticPropertyReflection(Type $typeWithProperty, string $prop
61096109
*/
61106110
private function propertyFetchType(Type $fetchedOnType, string $propertyName, Expr $propertyFetch): ?Type
61116111
{
6112-
$propertyReflection = $this->getPropertyReflection($fetchedOnType, $propertyName);
6112+
if ($propertyFetch instanceof PropertyFetch) {
6113+
$propertyReflection = $this->getInstancePropertyReflection($fetchedOnType, $propertyName);
6114+
} else {
6115+
$propertyReflection = $this->getStaticPropertyReflection($fetchedOnType, $propertyName);
6116+
}
6117+
61136118
if ($propertyReflection === null) {
61146119
return null;
61156120
}

src/Analyser/NodeScopeResolver.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -3021,7 +3021,7 @@ static function (): void {
30213021
} else {
30223022
$propertyName = $expr->name->toString();
30233023
$propertyHolderType = $scopeBeforeVar->getType($expr->var);
3024-
$propertyReflection = $scopeBeforeVar->getPropertyReflection($propertyHolderType, $propertyName);
3024+
$propertyReflection = $scopeBeforeVar->getInstancePropertyReflection($propertyHolderType, $propertyName);
30253025
if ($propertyReflection !== null && $this->phpVersion->supportsPropertyHooks()) {
30263026
$propertyDeclaringClass = $propertyReflection->getDeclaringClass();
30273027
if ($propertyDeclaringClass->hasNativeProperty($propertyName)) {
@@ -5563,8 +5563,8 @@ static function (): void {
55635563
}
55645564

55655565
$propertyHolderType = $scope->getType($var->var);
5566-
if ($propertyName !== null && $propertyHolderType->hasProperty($propertyName)->yes()) {
5567-
$propertyReflection = $propertyHolderType->getProperty($propertyName, $scope);
5566+
if ($propertyName !== null && $propertyHolderType->hasInstanceProperty($propertyName)->yes()) {
5567+
$propertyReflection = $propertyHolderType->getInstanceProperty($propertyName, $scope);
55685568
$assignedExprType = $scope->getType($assignedExpr);
55695569
$nodeCallback(new PropertyAssignNode($var, $assignedExpr, $isAssignOp), $scope);
55705570
if ($propertyReflection->canChangeTypeAfterAssignment()) {
@@ -5635,7 +5635,7 @@ static function (): void {
56355635
$scope = $result->getScope();
56365636

56375637
if ($propertyName !== null) {
5638-
$propertyReflection = $scope->getPropertyReflection($propertyHolderType, $propertyName);
5638+
$propertyReflection = $scope->getStaticPropertyReflection($propertyHolderType, $propertyName);
56395639
$assignedExprType = $scope->getType($assignedExpr);
56405640
$nodeCallback(new PropertyAssignNode($var, $assignedExpr, $isAssignOp), $scope);
56415641
if ($propertyReflection !== null && $propertyReflection->canChangeTypeAfterAssignment()) {

src/Node/ClassPropertiesNode.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ public function getUninitializedProperties(
198198
continue;
199199
}
200200

201-
$propertyReflection = $usageScope->getPropertyReflection($fetchedOnType, $propertyName);
201+
$propertyReflection = $usageScope->getInstancePropertyReflection($fetchedOnType, $propertyName);
202202
if ($propertyReflection === null) {
203203
continue;
204204
}

src/Reflection/Mixin/MixinPropertiesClassReflectionExtension.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,12 @@ private function findProperty(ClassReflection $classReflection, string $property
5454

5555
$this->inProcess[$typeDescription][$propertyName] = true;
5656

57-
if (!$type->hasProperty($propertyName)->yes()) {
57+
if (!$type->hasInstanceProperty($propertyName)->yes()) {
5858
unset($this->inProcess[$typeDescription][$propertyName]);
5959
continue;
6060
}
6161

62-
$property = $type->getProperty($propertyName, new OutOfClassScope());
62+
$property = $type->getInstanceProperty($propertyName, new OutOfClassScope());
6363
unset($this->inProcess[$typeDescription][$propertyName]);
6464

6565
return $property;

src/Rules/Properties/AccessPrivatePropertyThroughStaticRule.php

+2-5
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,14 @@ public function processNode(Node $node, Scope $scope): array
3636
}
3737

3838
$classType = $scope->resolveTypeByName($className);
39-
if (!$classType->hasProperty($propertyName)->yes()) {
39+
if (!$classType->hasStaticProperty($propertyName)->yes()) {
4040
return [];
4141
}
4242

43-
$property = $classType->getProperty($propertyName, $scope);
43+
$property = $classType->getStaticProperty($propertyName, $scope);
4444
if (!$property->isPrivate()) {
4545
return [];
4646
}
47-
if (!$property->isStatic()) {
48-
return [];
49-
}
5047

5148
if ($scope->isInClass() && $scope->getClassReflection()->isFinal()) {
5249
return [];

src/Rules/Properties/AccessStaticPropertiesRule.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ private function processSingleProperty(Scope $scope, StaticPropertyFetch $node,
226226
]);
227227
}
228228

229-
$property = $classType->getProperty($name, $scope);
229+
$property = $classType->getStaticProperty($name, $scope);
230230
if (!$scope->canReadProperty($property)) {
231231
return array_merge($messages, [
232232
RuleErrorBuilder::message(sprintf(

src/Type/IntersectionType.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,7 @@ public function getUnresolvedInstancePropertyPrototype(string $propertyName, Cla
547547
{
548548
$propertyPrototypes = [];
549549
foreach ($this->types as $type) {
550-
if (!$type->hasProperty($propertyName)->yes()) {
550+
if (!$type->hasInstanceProperty($propertyName)->yes()) {
551551
continue;
552552
}
553553

src/Type/ObjectShapeType.php

+8-8
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ public function accepts(Type $type, bool $strictTypes): AcceptsResult
158158
$result = AcceptsResult::createYes();
159159
$scope = new OutOfClassScope();
160160
foreach ($this->properties as $propertyName => $propertyType) {
161-
$typeHasProperty = $type->hasProperty($propertyName);
161+
$typeHasProperty = $type->hasInstanceProperty($propertyName);
162162
$hasProperty = new AcceptsResult(
163163
$typeHasProperty,
164164
$typeHasProperty->yes() ? [] : [
@@ -183,7 +183,7 @@ public function accepts(Type $type, bool $strictTypes): AcceptsResult
183183
$result = $result->and($hasProperty);
184184

185185
try {
186-
$otherProperty = $type->getProperty($propertyName, $scope);
186+
$otherProperty = $type->getInstanceProperty($propertyName, $scope);
187187
} catch (MissingPropertyFromReflectionException) {
188188
return new AcceptsResult(
189189
$result->result,
@@ -270,7 +270,7 @@ public function isSuperTypeOf(Type $type): IsSuperTypeOfResult
270270
$result = IsSuperTypeOfResult::createYes();
271271
$scope = new OutOfClassScope();
272272
foreach ($this->properties as $propertyName => $propertyType) {
273-
$hasProperty = new IsSuperTypeOfResult($type->hasProperty($propertyName), []);
273+
$hasProperty = new IsSuperTypeOfResult($type->hasInstanceProperty($propertyName), []);
274274
if ($hasProperty->no()) {
275275
if (in_array($propertyName, $this->optionalProperties, true)) {
276276
continue;
@@ -284,7 +284,7 @@ public function isSuperTypeOf(Type $type): IsSuperTypeOfResult
284284
$result = $result->and($hasProperty);
285285

286286
try {
287-
$otherProperty = $type->getProperty($propertyName, $scope);
287+
$otherProperty = $type->getInstanceProperty($propertyName, $scope);
288288
} catch (MissingPropertyFromReflectionException) {
289289
return $result;
290290
}
@@ -381,12 +381,12 @@ public function inferTemplateTypes(Type $receivedType): TemplateTypeMap
381381
$typeMap = TemplateTypeMap::createEmpty();
382382
$scope = new OutOfClassScope();
383383
foreach ($this->properties as $name => $propertyType) {
384-
if ($receivedType->hasProperty($name)->no()) {
384+
if ($receivedType->hasInstanceProperty($name)->no()) {
385385
continue;
386386
}
387387

388388
try {
389-
$receivedProperty = $receivedType->getProperty($name, $scope);
389+
$receivedProperty = $receivedType->getInstanceProperty($name, $scope);
390390
} catch (MissingPropertyFromReflectionException) {
391391
continue;
392392
}
@@ -477,10 +477,10 @@ public function traverseSimultaneously(Type $right, callable $cb): Type
477477

478478
$scope = new OutOfClassScope();
479479
foreach ($this->properties as $name => $propertyType) {
480-
if (!$right->hasProperty($name)->yes()) {
480+
if (!$right->hasInstanceProperty($name)->yes()) {
481481
return $this;
482482
}
483-
$transformed = $cb($propertyType, $right->getProperty($name, $scope)->getReadableType());
483+
$transformed = $cb($propertyType, $right->getInstanceProperty($name, $scope)->getReadableType());
484484
if ($transformed !== $propertyType) {
485485
$stillOriginal = false;
486486
}

src/Type/ObjectType.php

+1-19
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ public function getUnresolvedInstancePropertyPrototype(string $propertyName, Cla
303303
) {
304304
$properties = [];
305305
foreach ($this->getEnumCases() as $enumCase) {
306-
$properties[] = $enumCase->getUnresolvedPropertyPrototype($propertyName, $scope);
306+
$properties[] = $enumCase->getUnresolvedInstancePropertyPrototype($propertyName, $scope);
307307
}
308308

309309
if (count($properties) > 0) {
@@ -417,24 +417,6 @@ public function getUnresolvedStaticPropertyPrototype(string $propertyName, Class
417417
);
418418
}
419419

420-
public function getPropertyWithoutTransformingStatic(string $propertyName, ClassMemberAccessAnswerer $scope): PropertyReflection
421-
{
422-
$classReflection = $this->getNakedClassReflection();
423-
if ($classReflection === null) {
424-
throw new ClassNotFoundException($this->className);
425-
}
426-
427-
if (!$classReflection->hasProperty($propertyName)) {
428-
$classReflection = $this->getClassReflection();
429-
}
430-
431-
if ($classReflection === null) {
432-
throw new ClassNotFoundException($this->className);
433-
}
434-
435-
return $classReflection->getProperty($propertyName, $scope);
436-
}
437-
438420
public function getReferencedClasses(): array
439421
{
440422
return [$this->className];

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
}

src/Type/Traits/LateResolvableTypeTrait.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ public function getStaticProperty(string $propertyName, ClassMemberAccessAnswere
140140

141141
public function getUnresolvedStaticPropertyPrototype(string $propertyName, ClassMemberAccessAnswerer $scope): UnresolvedPropertyPrototypeReflection
142142
{
143-
return $this->resolve()->getUnresolvedPropertyPrototype($propertyName, $scope);
143+
return $this->resolve()->getUnresolvedStaticPropertyPrototype($propertyName, $scope);
144144
}
145145

146146
public function canCallMethods(): TrinaryLogic

src/Type/Traits/MaybeObjectTypeTrait.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public function hasInstanceProperty(string $propertyName): TrinaryLogic
6868

6969
public function getInstanceProperty(string $propertyName, ClassMemberAccessAnswerer $scope): ExtendedPropertyReflection
7070
{
71-
return $this->getUnresolvedPropertyPrototype($propertyName, $scope)->getTransformedProperty();
71+
return $this->getUnresolvedInstancePropertyPrototype($propertyName, $scope)->getTransformedProperty();
7272
}
7373

7474
public function getUnresolvedInstancePropertyPrototype(string $propertyName, ClassMemberAccessAnswerer $scope): UnresolvedPropertyPrototypeReflection
@@ -89,7 +89,7 @@ public function hasStaticProperty(string $propertyName): TrinaryLogic
8989

9090
public function getStaticProperty(string $propertyName, ClassMemberAccessAnswerer $scope): ExtendedPropertyReflection
9191
{
92-
return $this->getUnresolvedPropertyPrototype($propertyName, $scope)->getTransformedProperty();
92+
return $this->getUnresolvedStaticPropertyPrototype($propertyName, $scope)->getTransformedProperty();
9393
}
9494

9595
public function getUnresolvedStaticPropertyPrototype(string $propertyName, ClassMemberAccessAnswerer $scope): UnresolvedPropertyPrototypeReflection

0 commit comments

Comments
 (0)