Skip to content

Commit

Permalink
Remove __set_state() on objects that should not be serialized in cache
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Sep 30, 2024
1 parent 1fb2cdd commit 38cb5a3
Show file tree
Hide file tree
Showing 67 changed files with 1 addition and 600 deletions.
1 change: 1 addition & 0 deletions UPGRADING.md
Original file line number Diff line number Diff line change
Expand Up @@ -280,3 +280,4 @@ Instead of `PHPStanTestCase::createBroker()`, call `PHPStanTestCase::createRefle
* Remove `FunctionReflection::isFinal()`
* [`Type::getProperty()`](https://apiref.phpstan.org/2.0.x/PHPStan.Type.Type.html#_getProperty) now returns [`ExtendedPropertyReflection`](https://apiref.phpstan.org/2.0.x/PHPStan.Reflection.ExtendedPropertyReflection.html)
* `additionalConfigFiles` config parameter must be a list
* Remove `__set_state()` on objects that should not be serialized in cache
17 changes: 0 additions & 17 deletions src/Analyser/NameScope.php
Original file line number Diff line number Diff line change
Expand Up @@ -222,21 +222,4 @@ public function hasTypeAlias(string $alias): bool
return array_key_exists($alias, $this->typeAliasesMap);
}

/**
* @param mixed[] $properties
*/
public static function __set_state(array $properties): self
{
return new self(
$properties['namespace'],
$properties['uses'],
$properties['className'],
$properties['functionName'],
$properties['templateTypeMap'],
$properties['typeAliasesMap'],
$properties['bypassTypeAliases'],
$properties['constUses'],
);
}

}
15 changes: 0 additions & 15 deletions src/Reflection/Native/NativeParameterReflection.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,19 +63,4 @@ public function union(self $other): self
);
}

/**
* @param mixed[] $properties
*/
public static function __set_state(array $properties): self
{
return new self(
$properties['name'],
$properties['optional'],
$properties['type'],
$properties['passedByReference'],
$properties['variadic'],
$properties['defaultValue'],
);
}

}
20 changes: 0 additions & 20 deletions src/Reflection/Native/NativeParameterWithPhpDocsReflection.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,24 +81,4 @@ public function getClosureThisType(): ?Type
return $this->closureThisType;
}

/**
* @param mixed[] $properties
*/
public static function __set_state(array $properties): self
{
return new self(
$properties['name'],
$properties['optional'],
$properties['type'],
$properties['phpDocType'],
$properties['nativeType'],
$properties['passedByReference'],
$properties['variadic'],
$properties['defaultValue'],
$properties['outType'],
$properties['immediatelyInvokedCallable'],
$properties['closureThisType'],
);
}

}
8 changes: 0 additions & 8 deletions src/Reflection/PassedByReference.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,4 @@ public function combine(self $other): self
return $this;
}

/**
* @param mixed[] $properties
*/
public static function __set_state(array $properties): self
{
return new self($properties['value']);
}

}
8 changes: 0 additions & 8 deletions src/TrinaryLogic.php
Original file line number Diff line number Diff line change
Expand Up @@ -251,12 +251,4 @@ public function describe(): string
return $labels[$this->value];
}

/**
* @param mixed[] $properties
*/
public static function __set_state(array $properties): self
{
return self::create($properties['value']);
}

}
5 changes: 0 additions & 5 deletions src/Type/Accessory/AccessoryArrayListType.php
Original file line number Diff line number Diff line change
Expand Up @@ -472,11 +472,6 @@ public function traverseSimultaneously(Type $right, callable $cb): Type
return $this;
}

public static function __set_state(array $properties): Type
{
return new self();
}

public function exponentiate(Type $exponent): Type
{
return new ErrorType();
Expand Down
5 changes: 0 additions & 5 deletions src/Type/Accessory/AccessoryLiteralStringType.php
Original file line number Diff line number Diff line change
Expand Up @@ -352,11 +352,6 @@ public function generalize(GeneralizePrecision $precision): Type
return new StringType();
}

public static function __set_state(array $properties): Type
{
return new self();
}

public function exponentiate(Type $exponent): Type
{
return new BenevolentUnionType([
Expand Down
5 changes: 0 additions & 5 deletions src/Type/Accessory/AccessoryLowercaseStringType.php
Original file line number Diff line number Diff line change
Expand Up @@ -348,11 +348,6 @@ public function generalize(GeneralizePrecision $precision): Type
return new StringType();
}

public static function __set_state(array $properties): Type
{
return new self();
}

public function exponentiate(Type $exponent): Type
{
return new BenevolentUnionType([
Expand Down
5 changes: 0 additions & 5 deletions src/Type/Accessory/AccessoryNonEmptyStringType.php
Original file line number Diff line number Diff line change
Expand Up @@ -344,11 +344,6 @@ public function generalize(GeneralizePrecision $precision): Type
return new StringType();
}

public static function __set_state(array $properties): Type
{
return new self();
}

public function tryRemove(Type $typeToRemove): ?Type
{
if ($typeToRemove instanceof ConstantStringType && $typeToRemove->getValue() === '0') {
Expand Down
5 changes: 0 additions & 5 deletions src/Type/Accessory/AccessoryNonFalsyStringType.php
Original file line number Diff line number Diff line change
Expand Up @@ -344,11 +344,6 @@ public function generalize(GeneralizePrecision $precision): Type
return new StringType();
}

public static function __set_state(array $properties): Type
{
return new self();
}

public function exponentiate(Type $exponent): Type
{
return new BenevolentUnionType([
Expand Down
5 changes: 0 additions & 5 deletions src/Type/Accessory/AccessoryNumericStringType.php
Original file line number Diff line number Diff line change
Expand Up @@ -346,11 +346,6 @@ public function generalize(GeneralizePrecision $precision): Type
return new StringType();
}

public static function __set_state(array $properties): Type
{
return new self();
}

public function tryRemove(Type $typeToRemove): ?Type
{
if ($typeToRemove instanceof ConstantStringType && $typeToRemove->getValue() === '0') {
Expand Down
5 changes: 0 additions & 5 deletions src/Type/Accessory/HasMethodType.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,11 +200,6 @@ public function getFiniteTypes(): array
return [];
}

public static function __set_state(array $properties): Type
{
return new self($properties['methodName']);
}

public function toPhpDocNode(): TypeNode
{
return new IdentifierTypeNode(''); // no PHPDoc representation
Expand Down
5 changes: 0 additions & 5 deletions src/Type/Accessory/HasOffsetType.php
Original file line number Diff line number Diff line change
Expand Up @@ -402,11 +402,6 @@ public function getFiniteTypes(): array
return [];
}

public static function __set_state(array $properties): Type
{
return new self($properties['offsetType']);
}

public function toPhpDocNode(): TypeNode
{
return new IdentifierTypeNode(''); // no PHPDoc representation
Expand Down
5 changes: 0 additions & 5 deletions src/Type/Accessory/HasOffsetValueType.php
Original file line number Diff line number Diff line change
Expand Up @@ -458,11 +458,6 @@ public function getFiniteTypes(): array
return [];
}

public static function __set_state(array $properties): Type
{
return new self($properties['offsetType'], $properties['valueType']);
}

public function toPhpDocNode(): TypeNode
{
return new IdentifierTypeNode(''); // no PHPDoc representation
Expand Down
5 changes: 0 additions & 5 deletions src/Type/Accessory/HasPropertyType.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,11 +162,6 @@ public function getFiniteTypes(): array
return [];
}

public static function __set_state(array $properties): Type
{
return new self($properties['propertyName']);
}

public function toPhpDocNode(): TypeNode
{
return new IdentifierTypeNode(''); // no PHPDoc representation
Expand Down
5 changes: 0 additions & 5 deletions src/Type/Accessory/NonEmptyArrayType.php
Original file line number Diff line number Diff line change
Expand Up @@ -454,11 +454,6 @@ public function getFiniteTypes(): array
return [];
}

public static function __set_state(array $properties): Type
{
return new self();
}

public function toPhpDocNode(): TypeNode
{
return new IdentifierTypeNode('non-empty-array');
Expand Down
5 changes: 0 additions & 5 deletions src/Type/Accessory/OversizedArrayType.php
Original file line number Diff line number Diff line change
Expand Up @@ -450,11 +450,6 @@ public function getFiniteTypes(): array
return [];
}

public static function __set_state(array $properties): Type
{
return new self();
}

public function toPhpDocNode(): TypeNode
{
return new IdentifierTypeNode(''); // no PHPDoc representation
Expand Down
11 changes: 0 additions & 11 deletions src/Type/ArrayType.php
Original file line number Diff line number Diff line change
Expand Up @@ -562,15 +562,4 @@ public function getFiniteTypes(): array
return [];
}

/**
* @param mixed[] $properties
*/
public static function __set_state(array $properties): Type
{
return new self(
$properties['keyType'],
$properties['itemType'],
);
}

}
8 changes: 0 additions & 8 deletions src/Type/BenevolentUnionType.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,12 +173,4 @@ public function traverseSimultaneously(Type $right, callable $cb): Type
return $this;
}

/**
* @param mixed[] $properties
*/
public static function __set_state(array $properties): Type
{
return new self($properties['types']);
}

}
8 changes: 0 additions & 8 deletions src/Type/BooleanType.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,12 +163,4 @@ public function toPhpDocNode(): TypeNode
return new IdentifierTypeNode('bool');
}

/**
* @param mixed[] $properties
*/
public static function __set_state(array $properties): Type
{
return new self();
}

}
16 changes: 0 additions & 16 deletions src/Type/CallableType.php
Original file line number Diff line number Diff line change
Expand Up @@ -680,20 +680,4 @@ public function toPhpDocNode(): TypeNode
);
}

/**
* @param mixed[] $properties
*/
public static function __set_state(array $properties): Type
{
return new self(
(bool) $properties['isCommonCallable'] ? null : $properties['parameters'],
(bool) $properties['isCommonCallable'] ? null : $properties['returnType'],
$properties['variadic'],
$properties['templateTypeMap'],
$properties['resolvedTemplateTypeMap'],
$properties['templateTags'],
$properties['isPure'],
);
}

}
8 changes: 0 additions & 8 deletions src/Type/ClassStringType.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,4 @@ public function toPhpDocNode(): TypeNode
return new IdentifierTypeNode('class-string');
}

/**
* @param mixed[] $properties
*/
public static function __set_state(array $properties): Type
{
return new self();
}

}
21 changes: 0 additions & 21 deletions src/Type/ClosureType.php
Original file line number Diff line number Diff line change
Expand Up @@ -799,25 +799,4 @@ public function toPhpDocNode(): TypeNode
);
}

/**
* @param mixed[] $properties
*/
public static function __set_state(array $properties): Type
{
return new self(
$properties['parameters'],
$properties['returnType'],
$properties['variadic'],
$properties['templateTypeMap'],
$properties['resolvedTemplateTypeMap'],
$properties['callSiteVarianceMap'],
$properties['templateTags'],
$properties['throwPoints'],
$properties['impurePoints'],
$properties['invalidateExpressions'],
$properties['usedVariables'],
$properties['acceptsNamedArguments'],
);
}

}
14 changes: 0 additions & 14 deletions src/Type/ConditionalType.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,20 +188,6 @@ public function toPhpDocNode(): TypeNode
);
}

/**
* @param mixed[] $properties
*/
public static function __set_state(array $properties): Type
{
return new self(
$properties['subject'],
$properties['target'],
$properties['if'],
$properties['else'],
$properties['negated'],
);
}

private function getNormalizedIf(): Type
{
return $this->normalizedIf ??= TypeTraverser::map(
Expand Down
14 changes: 0 additions & 14 deletions src/Type/ConditionalTypeForParameter.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,18 +175,4 @@ public function toPhpDocNode(): TypeNode
);
}

/**
* @param mixed[] $properties
*/
public static function __set_state(array $properties): Type
{
return new self(
$properties['parameterName'],
$properties['target'],
$properties['if'],
$properties['else'],
$properties['negated'],
);
}

}
8 changes: 0 additions & 8 deletions src/Type/Constant/ConstantArrayType.php
Original file line number Diff line number Diff line change
Expand Up @@ -1712,12 +1712,4 @@ public function getFiniteTypes(): array
return $finiteTypes;
}

/**
* @param mixed[] $properties
*/
public static function __set_state(array $properties): Type
{
return new self($properties['keyTypes'], $properties['valueTypes'], $properties['nextAutoIndexes'] ?? $properties['nextAutoIndex'], $properties['optionalKeys'] ?? [], $properties['isList'] ?? TrinaryLogic::createNo());
}

}
Loading

0 comments on commit 38cb5a3

Please sign in to comment.