Skip to content

Commit 9653e85

Browse files
Solve deprecations
1 parent fabcf34 commit 9653e85

File tree

4 files changed

+37
-13
lines changed

4 files changed

+37
-13
lines changed

Diff for: src/Reflection/InitializerExprTypeResolver.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -403,11 +403,11 @@ public function getType(Expr $expr, InitializerExprContext $context): Type
403403

404404
if ($expr instanceof PropertyFetch && $expr->name instanceof Identifier) {
405405
$fetchedOnType = $this->getType($expr->var, $context);
406-
if (!$fetchedOnType->hasProperty($expr->name->name)->yes()) {
406+
if (!$fetchedOnType->hasInstanceProperty($expr->name->name)->yes()) {
407407
return new ErrorType();
408408
}
409409

410-
return $fetchedOnType->getProperty($expr->name->name, new OutOfClassScope())->getReadableType();
410+
return $fetchedOnType->getInstanceProperty($expr->name->name, new OutOfClassScope())->getReadableType();
411411
}
412412

413413
return new MixedType();

Diff for: src/Rules/DeadCode/UnusedPrivatePropertyRule.php

+8-1
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,14 @@ public function processNode(Node $node, Scope $scope): array
176176
if (!array_key_exists($propertyName, $properties)) {
177177
continue;
178178
}
179-
$propertyReflection = $usageScope->getPropertyReflection($fetchedOnType, $propertyName);
179+
180+
$propertyNode = $properties[$propertyName]['node'];
181+
if ($propertyNode->isStatic()) {
182+
$propertyReflection = $usageScope->getStaticPropertyReflection($fetchedOnType, $propertyName);
183+
} else {
184+
$propertyReflection = $usageScope->getInstancePropertyReflection($fetchedOnType, $propertyName);
185+
}
186+
180187
if ($propertyReflection === null) {
181188
if (!$classType->isSuperTypeOf($fetchedOnType)->no()) {
182189
if ($usage instanceof PropertyRead) {

Diff for: src/Rules/Properties/PropertyReflectionFinder.php

+25-8
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public function findPropertyReflectionsFromNode($propertyFetch, Scope $scope): a
3131
$reflections = [];
3232
$propertyHolderType = $scope->getType($propertyFetch->var);
3333
foreach ($names as $name) {
34-
$reflection = $this->findPropertyReflection(
34+
$reflection = $this->findInstancePropertyReflection(
3535
$propertyHolderType,
3636
$name,
3737
$propertyFetch->name instanceof Expr ? $scope->filterByTruthyValue(new Expr\BinaryOp\Identical(
@@ -63,7 +63,7 @@ public function findPropertyReflectionsFromNode($propertyFetch, Scope $scope): a
6363

6464
$reflections = [];
6565
foreach ($names as $name) {
66-
$reflection = $this->findPropertyReflection(
66+
$reflection = $this->findStaticPropertyReflection(
6767
$propertyHolderType,
6868
$name,
6969
$propertyFetch->name instanceof Expr ? $scope->filterByTruthyValue(new Expr\BinaryOp\Identical(
@@ -89,13 +89,13 @@ public function findPropertyReflectionFromNode($propertyFetch, Scope $scope): ?F
8989
if ($propertyFetch instanceof Node\Expr\PropertyFetch) {
9090
$propertyHolderType = $scope->getType($propertyFetch->var);
9191
if ($propertyFetch->name instanceof Node\Identifier) {
92-
return $this->findPropertyReflection($propertyHolderType, $propertyFetch->name->name, $scope);
92+
return $this->findInstancePropertyReflection($propertyHolderType, $propertyFetch->name->name, $scope);
9393
}
9494

9595
$nameType = $scope->getType($propertyFetch->name);
9696
$nameTypeConstantStrings = $nameType->getConstantStrings();
9797
if (count($nameTypeConstantStrings) === 1) {
98-
return $this->findPropertyReflection($propertyHolderType, $nameTypeConstantStrings[0]->getValue(), $scope);
98+
return $this->findInstancePropertyReflection($propertyHolderType, $nameTypeConstantStrings[0]->getValue(), $scope);
9999
}
100100

101101
return null;
@@ -111,16 +111,33 @@ public function findPropertyReflectionFromNode($propertyFetch, Scope $scope): ?F
111111
$propertyHolderType = $scope->getType($propertyFetch->class);
112112
}
113113

114-
return $this->findPropertyReflection($propertyHolderType, $propertyFetch->name->name, $scope);
114+
return $this->findStaticPropertyReflection($propertyHolderType, $propertyFetch->name->name, $scope);
115115
}
116116

117-
private function findPropertyReflection(Type $propertyHolderType, string $propertyName, Scope $scope): ?FoundPropertyReflection
117+
private function findInstancePropertyReflection(Type $propertyHolderType, string $propertyName, Scope $scope): ?FoundPropertyReflection
118118
{
119-
if (!$propertyHolderType->hasProperty($propertyName)->yes()) {
119+
if (!$propertyHolderType->hasInstanceProperty($propertyName)->yes()) {
120120
return null;
121121
}
122122

123-
$originalProperty = $propertyHolderType->getProperty($propertyName, $scope);
123+
$originalProperty = $propertyHolderType->getInstanceProperty($propertyName, $scope);
124+
125+
return new FoundPropertyReflection(
126+
$originalProperty,
127+
$scope,
128+
$propertyName,
129+
$originalProperty->getReadableType(),
130+
$originalProperty->getWritableType(),
131+
);
132+
}
133+
134+
private function findStaticPropertyReflection(Type $propertyHolderType, string $propertyName, Scope $scope): ?FoundPropertyReflection
135+
{
136+
if (!$propertyHolderType->hasStaticProperty($propertyName)->yes()) {
137+
return null;
138+
}
139+
140+
$originalProperty = $propertyHolderType->getStaticProperty($propertyName, $scope);
124141

125142
return new FoundPropertyReflection(
126143
$originalProperty,

Diff for: src/Type/Php/ArrayColumnFunctionReturnTypeExtension.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -163,15 +163,15 @@ private function getOffsetOrProperty(Type $type, Type $offsetOrProperty, Scope $
163163
}
164164
foreach ($propertyTypes as $propertyType) {
165165
$propertyName = $propertyType->getValue();
166-
$hasProperty = $type->hasProperty($propertyName);
166+
$hasProperty = $type->hasInstanceProperty($propertyName);
167167
if ($hasProperty->maybe()) {
168168
return $allowMaybe ? new MixedType() : null;
169169
}
170170
if (!$hasProperty->yes()) {
171171
continue;
172172
}
173173

174-
$returnTypes[] = $type->getProperty($propertyName, $scope)->getReadableType();
174+
$returnTypes[] = $type->getInstanceProperty($propertyName, $scope)->getReadableType();
175175
}
176176
}
177177

0 commit comments

Comments
 (0)