Skip to content

Commit eb35211

Browse files
Solve deprecations
1 parent 9a18e12 commit eb35211

12 files changed

+40
-49
lines changed

src/Analyser/MutatingScope.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4334,7 +4334,7 @@ public function assignInitializedProperty(Type $fetchedOnType, string $propertyN
43344334
return $this;
43354335
}
43364336

4337-
$propertyReflection = $this->getPropertyReflection($fetchedOnType, $propertyName);
4337+
$propertyReflection = $this->getInstancePropertyReflection($fetchedOnType, $propertyName);
43384338
if ($propertyReflection === null) {
43394339
return $this;
43404340
}
@@ -6214,7 +6214,12 @@ public function getStaticPropertyReflection(Type $typeWithProperty, string $prop
62146214
*/
62156215
private function propertyFetchType(Type $fetchedOnType, string $propertyName, Expr $propertyFetch): ?Type
62166216
{
6217-
$propertyReflection = $this->getPropertyReflection($fetchedOnType, $propertyName);
6217+
if ($propertyFetch instanceof PropertyFetch) {
6218+
$propertyReflection = $this->getInstancePropertyReflection($fetchedOnType, $propertyName);
6219+
} else {
6220+
$propertyReflection = $this->getStaticPropertyReflection($fetchedOnType, $propertyName);
6221+
}
6222+
62186223
if ($propertyReflection === null) {
62196224
return null;
62206225
}

src/Analyser/NodeScopeResolver.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3125,7 +3125,7 @@ static function (): void {
31253125
} else {
31263126
$propertyName = $expr->name->toString();
31273127
$propertyHolderType = $scopeBeforeVar->getType($expr->var);
3128-
$propertyReflection = $scopeBeforeVar->getPropertyReflection($propertyHolderType, $propertyName);
3128+
$propertyReflection = $scopeBeforeVar->getInstancePropertyReflection($propertyHolderType, $propertyName);
31293129
if ($propertyReflection !== null && $this->phpVersion->supportsPropertyHooks()) {
31303130
$propertyDeclaringClass = $propertyReflection->getDeclaringClass();
31313131
if ($propertyDeclaringClass->hasNativeProperty($propertyName)) {
@@ -5755,8 +5755,8 @@ static function (): void {
57555755
}
57565756

57575757
$propertyHolderType = $scope->getType($var->var);
5758-
if ($propertyName !== null && $propertyHolderType->hasProperty($propertyName)->yes()) {
5759-
$propertyReflection = $propertyHolderType->getProperty($propertyName, $scope);
5758+
if ($propertyName !== null && $propertyHolderType->hasInstanceProperty($propertyName)->yes()) {
5759+
$propertyReflection = $propertyHolderType->getInstanceProperty($propertyName, $scope);
57605760
$assignedExprType = $scope->getType($assignedExpr);
57615761
$nodeCallback(new PropertyAssignNode($var, $assignedExpr, $isAssignOp), $scopeBeforeAssignEval);
57625762
if ($propertyReflection->canChangeTypeAfterAssignment()) {
@@ -5848,7 +5848,7 @@ static function (): void {
58485848
$scope = $result->getScope();
58495849

58505850
if ($propertyName !== null) {
5851-
$propertyReflection = $scope->getPropertyReflection($propertyHolderType, $propertyName);
5851+
$propertyReflection = $scope->getStaticPropertyReflection($propertyHolderType, $propertyName);
58525852
$assignedExprType = $scope->getType($assignedExpr);
58535853
$nodeCallback(new PropertyAssignNode($var, $assignedExpr, $isAssignOp), $scopeBeforeAssignEval);
58545854
if ($propertyReflection !== null && $propertyReflection->canChangeTypeAfterAssignment()) {

src/Node/ClassPropertiesNode.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ public function getUninitializedProperties(
201201
continue;
202202
}
203203

204-
$propertyReflection = $usageScope->getPropertyReflection($fetchedOnType, $propertyName);
204+
$propertyReflection = $usageScope->getInstancePropertyReflection($fetchedOnType, $propertyName);
205205
if ($propertyReflection === null) {
206206
continue;
207207
}

src/Reflection/Mixin/MixinPropertiesClassReflectionExtension.php

Lines changed: 2 additions & 2 deletions
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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,14 @@ public function processNode(Node $node, Scope $scope): array
3838
}
3939

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

45-
$property = $classType->getProperty($propertyName, $scope);
45+
$property = $classType->getStaticProperty($propertyName, $scope);
4646
if (!$property->isPrivate()) {
4747
return [];
4848
}
49-
if (!$property->isStatic()) {
50-
return [];
51-
}
5249

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

src/Rules/Properties/AccessStaticPropertiesRule.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ private function processSingleProperty(Scope $scope, StaticPropertyFetch $node,
246246
]);
247247
}
248248

249-
$property = $classType->getProperty($name, $scope);
249+
$property = $classType->getStaticProperty($name, $scope);
250250
if (!$scope->canReadProperty($property)) {
251251
return array_merge($messages, [
252252
RuleErrorBuilder::message(sprintf(

src/Type/IntersectionType.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,7 @@ public function getUnresolvedInstancePropertyPrototype(string $propertyName, Cla
549549
{
550550
$propertyPrototypes = [];
551551
foreach ($this->types as $type) {
552-
if (!$type->hasProperty($propertyName)->yes()) {
552+
if (!$type->hasInstanceProperty($propertyName)->yes()) {
553553
continue;
554554
}
555555

src/Type/ObjectShapeType.php

Lines changed: 17 additions & 7 deletions
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() ? [] : [
@@ -188,7 +188,7 @@ public function accepts(Type $type, bool $strictTypes): AcceptsResult
188188
}
189189

190190
$result = $result->and($hasProperty);
191-
$otherProperty = $type->getProperty($propertyName, $scope);
191+
$otherProperty = $type->getInstanceProperty($propertyName, $scope);
192192
if (!$otherProperty->isPublic()) {
193193
return new AcceptsResult(TrinaryLogic::createNo(), [
194194
sprintf('Property %s::$%s is not public.', $otherProperty->getDeclaringClass()->getDisplayName(), $propertyName),
@@ -262,7 +262,7 @@ public function isSuperTypeOf(Type $type): IsSuperTypeOfResult
262262
$result = IsSuperTypeOfResult::createYes();
263263
$scope = new OutOfClassScope();
264264
foreach ($this->properties as $propertyName => $propertyType) {
265-
$hasProperty = new IsSuperTypeOfResult($type->hasProperty($propertyName), []);
265+
$hasProperty = new IsSuperTypeOfResult($type->hasInstanceProperty($propertyName), []);
266266
if ($hasProperty->no()) {
267267
if (in_array($propertyName, $this->optionalProperties, true)) {
268268
continue;
@@ -280,7 +280,17 @@ public function isSuperTypeOf(Type $type): IsSuperTypeOfResult
280280
}
281281

282282
$result = $result->and($hasProperty);
283+
<<<<<<< HEAD
283284
$otherProperty = $type->getProperty($propertyName, $scope);
285+
=======
286+
287+
try {
288+
$otherProperty = $type->getInstanceProperty($propertyName, $scope);
289+
} catch (MissingPropertyFromReflectionException) {
290+
return $result;
291+
}
292+
293+
>>>>>>> a507ab857 (Solve deprecations)
284294
if (!$otherProperty->isPublic()) {
285295
return IsSuperTypeOfResult::createNo();
286296
}
@@ -373,12 +383,12 @@ public function inferTemplateTypes(Type $receivedType): TemplateTypeMap
373383
$typeMap = TemplateTypeMap::createEmpty();
374384
$scope = new OutOfClassScope();
375385
foreach ($this->properties as $name => $propertyType) {
376-
if ($receivedType->hasProperty($name)->no()) {
386+
if ($receivedType->hasInstanceProperty($name)->no()) {
377387
continue;
378388
}
379389

380390
try {
381-
$receivedProperty = $receivedType->getProperty($name, $scope);
391+
$receivedProperty = $receivedType->getInstanceProperty($name, $scope);
382392
} catch (MissingPropertyFromReflectionException) {
383393
continue;
384394
}
@@ -464,10 +474,10 @@ public function traverseSimultaneously(Type $right, callable $cb): Type
464474

465475
$scope = new OutOfClassScope();
466476
foreach ($this->properties as $name => $propertyType) {
467-
if (!$right->hasProperty($name)->yes()) {
477+
if (!$right->hasInstanceProperty($name)->yes()) {
468478
return $this;
469479
}
470-
$transformed = $cb($propertyType, $right->getProperty($name, $scope)->getReadableType());
480+
$transformed = $cb($propertyType, $right->getInstanceProperty($name, $scope)->getReadableType());
471481
if ($transformed !== $propertyType) {
472482
$stillOriginal = false;
473483
}

src/Type/ObjectType.php

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ public function getUnresolvedInstancePropertyPrototype(string $propertyName, Cla
304304
) {
305305
$properties = [];
306306
foreach ($this->getEnumCases() as $enumCase) {
307-
$properties[] = $enumCase->getUnresolvedPropertyPrototype($propertyName, $scope);
307+
$properties[] = $enumCase->getUnresolvedInstancePropertyPrototype($propertyName, $scope);
308308
}
309309

310310
if (count($properties) > 0) {
@@ -418,27 +418,6 @@ public function getUnresolvedStaticPropertyPrototype(string $propertyName, Class
418418
);
419419
}
420420

421-
/**
422-
* @deprecated Not in use anymore.
423-
*/
424-
public function getPropertyWithoutTransformingStatic(string $propertyName, ClassMemberAccessAnswerer $scope): PropertyReflection
425-
{
426-
$classReflection = $this->getNakedClassReflection();
427-
if ($classReflection === null) {
428-
throw new ClassNotFoundException($this->className);
429-
}
430-
431-
if (!$classReflection->hasProperty($propertyName)) {
432-
$classReflection = $this->getClassReflection();
433-
}
434-
435-
if ($classReflection === null) {
436-
throw new ClassNotFoundException($this->className);
437-
}
438-
439-
return $classReflection->getProperty($propertyName, $scope);
440-
}
441-
442421
public function getReferencedClasses(): array
443422
{
444423
return [$this->className];

src/Type/Php/ReflectionPropertyConstructorThrowTypeExtension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public function getThrowTypeFromStaticMethodCall(MethodReflection $methodReflect
4242

4343
$classReflection = $this->reflectionProvider->getClass($constantString->getValue());
4444
foreach ($propertyType->getConstantStrings() as $constantPropertyString) {
45-
if (!$classReflection->hasProperty($constantPropertyString->getValue())) {
45+
if (!$classReflection->hasInstanceProperty($constantPropertyString->getValue())) {
4646
return $methodReflection->getThrowType();
4747
}
4848
}

0 commit comments

Comments
 (0)