Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions src/Analyser/MutatingScope.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
use PHPStan\Node\Expr\GetIterableKeyTypeExpr;
use PHPStan\Node\Expr\GetIterableValueTypeExpr;
use PHPStan\Node\Expr\GetOffsetValueTypeExpr;
use PHPStan\Node\Expr\OriginalPropertyTypeExpr;
use PHPStan\Node\Expr\ParameterVariableOriginalValueExpr;
use PHPStan\Node\Expr\PropertyInitializationExpr;
use PHPStan\Node\Expr\SetExistingOffsetValueTypeExpr;
Expand Down Expand Up @@ -690,15 +689,6 @@ public function getType(Expr $node): Type
return $node->getExprType();
}

if ($node instanceof OriginalPropertyTypeExpr) {
$propertyReflection = $this->propertyReflectionFinder->findPropertyReflectionFromNode($node->getPropertyFetch(), $this);
if ($propertyReflection === null) {
return new ErrorType();
}

return $propertyReflection->getReadableType();
}

$key = $this->getNodeKey($node);

if (!array_key_exists($key, $this->resolvedTypes)) {
Expand Down
13 changes: 2 additions & 11 deletions src/Analyser/NodeScopeResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@
use PHPStan\Node\Expr\GetIterableKeyTypeExpr;
use PHPStan\Node\Expr\GetIterableValueTypeExpr;
use PHPStan\Node\Expr\GetOffsetValueTypeExpr;
use PHPStan\Node\Expr\OriginalPropertyTypeExpr;
use PHPStan\Node\Expr\PropertyInitializationExpr;
use PHPStan\Node\Expr\SetExistingOffsetValueTypeExpr;
use PHPStan\Node\Expr\SetOffsetValueTypeExpr;
Expand Down Expand Up @@ -5016,12 +5015,8 @@ private function processAssignVar(
$originalVar = $var;
$assignedPropertyExpr = $assignedExpr;
while ($var instanceof ArrayDimFetch) {
$varForSetOffsetValue = $var->var;
if ($varForSetOffsetValue instanceof PropertyFetch || $varForSetOffsetValue instanceof StaticPropertyFetch) {
$varForSetOffsetValue = new OriginalPropertyTypeExpr($varForSetOffsetValue);
}
$assignedPropertyExpr = new SetOffsetValueTypeExpr(
$varForSetOffsetValue,
$var->var,
$var->dim,
$assignedPropertyExpr,
);
Expand Down Expand Up @@ -5336,12 +5331,8 @@ static function (): void {
$dimFetchStack = [];
$assignedPropertyExpr = $assignedExpr;
while ($var instanceof ExistingArrayDimFetch) {
$varForSetOffsetValue = $var->getVar();
if ($varForSetOffsetValue instanceof PropertyFetch || $varForSetOffsetValue instanceof StaticPropertyFetch) {
$varForSetOffsetValue = new OriginalPropertyTypeExpr($varForSetOffsetValue);
}
$assignedPropertyExpr = new SetExistingOffsetValueTypeExpr(
$varForSetOffsetValue,
$var->getVar(),
$var->getDim(),
$assignedPropertyExpr,
);
Expand Down
34 changes: 0 additions & 34 deletions src/Node/Expr/OriginalPropertyTypeExpr.php

This file was deleted.

6 changes: 0 additions & 6 deletions src/Node/Printer/Printer.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use PHPStan\Node\Expr\GetIterableKeyTypeExpr;
use PHPStan\Node\Expr\GetIterableValueTypeExpr;
use PHPStan\Node\Expr\GetOffsetValueTypeExpr;
use PHPStan\Node\Expr\OriginalPropertyTypeExpr;
use PHPStan\Node\Expr\ParameterVariableOriginalValueExpr;
use PHPStan\Node\Expr\PropertyInitializationExpr;
use PHPStan\Node\Expr\SetExistingOffsetValueTypeExpr;
Expand Down Expand Up @@ -55,11 +54,6 @@ protected function pPHPStan_Node_ExistingArrayDimFetch(ExistingArrayDimFetch $ex
return sprintf('__phpstanExistingArrayDimFetch(%s, %s)', $this->p($expr->getVar()), $this->p($expr->getDim()));
}

protected function pPHPStan_Node_OriginalPropertyTypeExpr(OriginalPropertyTypeExpr $expr): string // phpcs:ignore
{
return sprintf('__phpstanOriginalPropertyType(%s)', $this->p($expr->getPropertyFetch()));
}

protected function pPHPStan_Node_SetOffsetValueTypeExpr(SetOffsetValueTypeExpr $expr): string // phpcs:ignore
{
return sprintf('__phpstanSetOffsetValueType(%s, %s, %s)', $this->p($expr->getVar()), $expr->getDim() !== null ? $this->p($expr->getDim()) : 'null', $this->p($expr->getValue()));
Expand Down
12 changes: 11 additions & 1 deletion src/Rules/Properties/TypesAssignedToPropertiesRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use PhpParser\Node;
use PHPStan\Analyser\Scope;
use PHPStan\Node\Expr\SetOffsetValueTypeExpr;
use PHPStan\Node\PropertyAssignNode;
use PHPStan\Reflection\PropertyReflection;
use PHPStan\Rules\IdentifierRuleError;
Expand Down Expand Up @@ -61,7 +62,16 @@ private function processSingleProperty(

$propertyType = $propertyReflection->getWritableType();
$scope = $propertyReflection->getScope();
$assignedValueType = $scope->getType($assignedExpr);

if ($assignedExpr instanceof SetOffsetValueTypeExpr) {
// TODO: Document why we need this only for setting offset values, do we actually need this?! xD
$assignedValueType = $propertyType->setOffsetValueType(
$assignedExpr->getDim() !== null ? $scope->getType($assignedExpr->getDim()) : null,
$scope->getType($assignedExpr->getValue()),
);
} else {
$assignedValueType = $scope->getType($assignedExpr);
}

$accepts = $this->ruleLevelHelper->accepts($propertyType, $assignedValueType, $scope->isDeclareStrictTypes());
if (!$accepts->result) {
Expand Down
Loading