Skip to content

Commit 38cb5a3

Browse files
committed
Remove __set_state() on objects that should not be serialized in cache
1 parent 1fb2cdd commit 38cb5a3

File tree

67 files changed

+1
-600
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+1
-600
lines changed

Diff for: UPGRADING.md

+1
Original file line numberDiff line numberDiff line change
@@ -280,3 +280,4 @@ Instead of `PHPStanTestCase::createBroker()`, call `PHPStanTestCase::createRefle
280280
* Remove `FunctionReflection::isFinal()`
281281
* [`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)
282282
* `additionalConfigFiles` config parameter must be a list
283+
* Remove `__set_state()` on objects that should not be serialized in cache

Diff for: src/Analyser/NameScope.php

-17
Original file line numberDiff line numberDiff line change
@@ -222,21 +222,4 @@ public function hasTypeAlias(string $alias): bool
222222
return array_key_exists($alias, $this->typeAliasesMap);
223223
}
224224

225-
/**
226-
* @param mixed[] $properties
227-
*/
228-
public static function __set_state(array $properties): self
229-
{
230-
return new self(
231-
$properties['namespace'],
232-
$properties['uses'],
233-
$properties['className'],
234-
$properties['functionName'],
235-
$properties['templateTypeMap'],
236-
$properties['typeAliasesMap'],
237-
$properties['bypassTypeAliases'],
238-
$properties['constUses'],
239-
);
240-
}
241-
242225
}

Diff for: src/Reflection/Native/NativeParameterReflection.php

-15
Original file line numberDiff line numberDiff line change
@@ -63,19 +63,4 @@ public function union(self $other): self
6363
);
6464
}
6565

66-
/**
67-
* @param mixed[] $properties
68-
*/
69-
public static function __set_state(array $properties): self
70-
{
71-
return new self(
72-
$properties['name'],
73-
$properties['optional'],
74-
$properties['type'],
75-
$properties['passedByReference'],
76-
$properties['variadic'],
77-
$properties['defaultValue'],
78-
);
79-
}
80-
8166
}

Diff for: src/Reflection/Native/NativeParameterWithPhpDocsReflection.php

-20
Original file line numberDiff line numberDiff line change
@@ -81,24 +81,4 @@ public function getClosureThisType(): ?Type
8181
return $this->closureThisType;
8282
}
8383

84-
/**
85-
* @param mixed[] $properties
86-
*/
87-
public static function __set_state(array $properties): self
88-
{
89-
return new self(
90-
$properties['name'],
91-
$properties['optional'],
92-
$properties['type'],
93-
$properties['phpDocType'],
94-
$properties['nativeType'],
95-
$properties['passedByReference'],
96-
$properties['variadic'],
97-
$properties['defaultValue'],
98-
$properties['outType'],
99-
$properties['immediatelyInvokedCallable'],
100-
$properties['closureThisType'],
101-
);
102-
}
103-
10484
}

Diff for: src/Reflection/PassedByReference.php

-8
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,4 @@ public function combine(self $other): self
7676
return $this;
7777
}
7878

79-
/**
80-
* @param mixed[] $properties
81-
*/
82-
public static function __set_state(array $properties): self
83-
{
84-
return new self($properties['value']);
85-
}
86-
8779
}

Diff for: src/TrinaryLogic.php

-8
Original file line numberDiff line numberDiff line change
@@ -251,12 +251,4 @@ public function describe(): string
251251
return $labels[$this->value];
252252
}
253253

254-
/**
255-
* @param mixed[] $properties
256-
*/
257-
public static function __set_state(array $properties): self
258-
{
259-
return self::create($properties['value']);
260-
}
261-
262254
}

Diff for: src/Type/Accessory/AccessoryArrayListType.php

-5
Original file line numberDiff line numberDiff line change
@@ -472,11 +472,6 @@ public function traverseSimultaneously(Type $right, callable $cb): Type
472472
return $this;
473473
}
474474

475-
public static function __set_state(array $properties): Type
476-
{
477-
return new self();
478-
}
479-
480475
public function exponentiate(Type $exponent): Type
481476
{
482477
return new ErrorType();

Diff for: src/Type/Accessory/AccessoryLiteralStringType.php

-5
Original file line numberDiff line numberDiff line change
@@ -352,11 +352,6 @@ public function generalize(GeneralizePrecision $precision): Type
352352
return new StringType();
353353
}
354354

355-
public static function __set_state(array $properties): Type
356-
{
357-
return new self();
358-
}
359-
360355
public function exponentiate(Type $exponent): Type
361356
{
362357
return new BenevolentUnionType([

Diff for: src/Type/Accessory/AccessoryLowercaseStringType.php

-5
Original file line numberDiff line numberDiff line change
@@ -348,11 +348,6 @@ public function generalize(GeneralizePrecision $precision): Type
348348
return new StringType();
349349
}
350350

351-
public static function __set_state(array $properties): Type
352-
{
353-
return new self();
354-
}
355-
356351
public function exponentiate(Type $exponent): Type
357352
{
358353
return new BenevolentUnionType([

Diff for: src/Type/Accessory/AccessoryNonEmptyStringType.php

-5
Original file line numberDiff line numberDiff line change
@@ -344,11 +344,6 @@ public function generalize(GeneralizePrecision $precision): Type
344344
return new StringType();
345345
}
346346

347-
public static function __set_state(array $properties): Type
348-
{
349-
return new self();
350-
}
351-
352347
public function tryRemove(Type $typeToRemove): ?Type
353348
{
354349
if ($typeToRemove instanceof ConstantStringType && $typeToRemove->getValue() === '0') {

Diff for: src/Type/Accessory/AccessoryNonFalsyStringType.php

-5
Original file line numberDiff line numberDiff line change
@@ -344,11 +344,6 @@ public function generalize(GeneralizePrecision $precision): Type
344344
return new StringType();
345345
}
346346

347-
public static function __set_state(array $properties): Type
348-
{
349-
return new self();
350-
}
351-
352347
public function exponentiate(Type $exponent): Type
353348
{
354349
return new BenevolentUnionType([

Diff for: src/Type/Accessory/AccessoryNumericStringType.php

-5
Original file line numberDiff line numberDiff line change
@@ -346,11 +346,6 @@ public function generalize(GeneralizePrecision $precision): Type
346346
return new StringType();
347347
}
348348

349-
public static function __set_state(array $properties): Type
350-
{
351-
return new self();
352-
}
353-
354349
public function tryRemove(Type $typeToRemove): ?Type
355350
{
356351
if ($typeToRemove instanceof ConstantStringType && $typeToRemove->getValue() === '0') {

Diff for: src/Type/Accessory/HasMethodType.php

-5
Original file line numberDiff line numberDiff line change
@@ -200,11 +200,6 @@ public function getFiniteTypes(): array
200200
return [];
201201
}
202202

203-
public static function __set_state(array $properties): Type
204-
{
205-
return new self($properties['methodName']);
206-
}
207-
208203
public function toPhpDocNode(): TypeNode
209204
{
210205
return new IdentifierTypeNode(''); // no PHPDoc representation

Diff for: src/Type/Accessory/HasOffsetType.php

-5
Original file line numberDiff line numberDiff line change
@@ -402,11 +402,6 @@ public function getFiniteTypes(): array
402402
return [];
403403
}
404404

405-
public static function __set_state(array $properties): Type
406-
{
407-
return new self($properties['offsetType']);
408-
}
409-
410405
public function toPhpDocNode(): TypeNode
411406
{
412407
return new IdentifierTypeNode(''); // no PHPDoc representation

Diff for: src/Type/Accessory/HasOffsetValueType.php

-5
Original file line numberDiff line numberDiff line change
@@ -458,11 +458,6 @@ public function getFiniteTypes(): array
458458
return [];
459459
}
460460

461-
public static function __set_state(array $properties): Type
462-
{
463-
return new self($properties['offsetType'], $properties['valueType']);
464-
}
465-
466461
public function toPhpDocNode(): TypeNode
467462
{
468463
return new IdentifierTypeNode(''); // no PHPDoc representation

Diff for: src/Type/Accessory/HasPropertyType.php

-5
Original file line numberDiff line numberDiff line change
@@ -162,11 +162,6 @@ public function getFiniteTypes(): array
162162
return [];
163163
}
164164

165-
public static function __set_state(array $properties): Type
166-
{
167-
return new self($properties['propertyName']);
168-
}
169-
170165
public function toPhpDocNode(): TypeNode
171166
{
172167
return new IdentifierTypeNode(''); // no PHPDoc representation

Diff for: src/Type/Accessory/NonEmptyArrayType.php

-5
Original file line numberDiff line numberDiff line change
@@ -454,11 +454,6 @@ public function getFiniteTypes(): array
454454
return [];
455455
}
456456

457-
public static function __set_state(array $properties): Type
458-
{
459-
return new self();
460-
}
461-
462457
public function toPhpDocNode(): TypeNode
463458
{
464459
return new IdentifierTypeNode('non-empty-array');

Diff for: src/Type/Accessory/OversizedArrayType.php

-5
Original file line numberDiff line numberDiff line change
@@ -450,11 +450,6 @@ public function getFiniteTypes(): array
450450
return [];
451451
}
452452

453-
public static function __set_state(array $properties): Type
454-
{
455-
return new self();
456-
}
457-
458453
public function toPhpDocNode(): TypeNode
459454
{
460455
return new IdentifierTypeNode(''); // no PHPDoc representation

Diff for: src/Type/ArrayType.php

-11
Original file line numberDiff line numberDiff line change
@@ -562,15 +562,4 @@ public function getFiniteTypes(): array
562562
return [];
563563
}
564564

565-
/**
566-
* @param mixed[] $properties
567-
*/
568-
public static function __set_state(array $properties): Type
569-
{
570-
return new self(
571-
$properties['keyType'],
572-
$properties['itemType'],
573-
);
574-
}
575-
576565
}

Diff for: src/Type/BenevolentUnionType.php

-8
Original file line numberDiff line numberDiff line change
@@ -173,12 +173,4 @@ public function traverseSimultaneously(Type $right, callable $cb): Type
173173
return $this;
174174
}
175175

176-
/**
177-
* @param mixed[] $properties
178-
*/
179-
public static function __set_state(array $properties): Type
180-
{
181-
return new self($properties['types']);
182-
}
183-
184176
}

Diff for: src/Type/BooleanType.php

-8
Original file line numberDiff line numberDiff line change
@@ -163,12 +163,4 @@ public function toPhpDocNode(): TypeNode
163163
return new IdentifierTypeNode('bool');
164164
}
165165

166-
/**
167-
* @param mixed[] $properties
168-
*/
169-
public static function __set_state(array $properties): Type
170-
{
171-
return new self();
172-
}
173-
174166
}

Diff for: src/Type/CallableType.php

-16
Original file line numberDiff line numberDiff line change
@@ -680,20 +680,4 @@ public function toPhpDocNode(): TypeNode
680680
);
681681
}
682682

683-
/**
684-
* @param mixed[] $properties
685-
*/
686-
public static function __set_state(array $properties): Type
687-
{
688-
return new self(
689-
(bool) $properties['isCommonCallable'] ? null : $properties['parameters'],
690-
(bool) $properties['isCommonCallable'] ? null : $properties['returnType'],
691-
$properties['variadic'],
692-
$properties['templateTypeMap'],
693-
$properties['resolvedTemplateTypeMap'],
694-
$properties['templateTags'],
695-
$properties['isPure'],
696-
);
697-
}
698-
699683
}

Diff for: src/Type/ClassStringType.php

-8
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,4 @@ public function toPhpDocNode(): TypeNode
9494
return new IdentifierTypeNode('class-string');
9595
}
9696

97-
/**
98-
* @param mixed[] $properties
99-
*/
100-
public static function __set_state(array $properties): Type
101-
{
102-
return new self();
103-
}
104-
10597
}

Diff for: src/Type/ClosureType.php

-21
Original file line numberDiff line numberDiff line change
@@ -799,25 +799,4 @@ public function toPhpDocNode(): TypeNode
799799
);
800800
}
801801

802-
/**
803-
* @param mixed[] $properties
804-
*/
805-
public static function __set_state(array $properties): Type
806-
{
807-
return new self(
808-
$properties['parameters'],
809-
$properties['returnType'],
810-
$properties['variadic'],
811-
$properties['templateTypeMap'],
812-
$properties['resolvedTemplateTypeMap'],
813-
$properties['callSiteVarianceMap'],
814-
$properties['templateTags'],
815-
$properties['throwPoints'],
816-
$properties['impurePoints'],
817-
$properties['invalidateExpressions'],
818-
$properties['usedVariables'],
819-
$properties['acceptsNamedArguments'],
820-
);
821-
}
822-
823802
}

Diff for: src/Type/ConditionalType.php

-14
Original file line numberDiff line numberDiff line change
@@ -188,20 +188,6 @@ public function toPhpDocNode(): TypeNode
188188
);
189189
}
190190

191-
/**
192-
* @param mixed[] $properties
193-
*/
194-
public static function __set_state(array $properties): Type
195-
{
196-
return new self(
197-
$properties['subject'],
198-
$properties['target'],
199-
$properties['if'],
200-
$properties['else'],
201-
$properties['negated'],
202-
);
203-
}
204-
205191
private function getNormalizedIf(): Type
206192
{
207193
return $this->normalizedIf ??= TypeTraverser::map(

Diff for: src/Type/ConditionalTypeForParameter.php

-14
Original file line numberDiff line numberDiff line change
@@ -175,18 +175,4 @@ public function toPhpDocNode(): TypeNode
175175
);
176176
}
177177

178-
/**
179-
* @param mixed[] $properties
180-
*/
181-
public static function __set_state(array $properties): Type
182-
{
183-
return new self(
184-
$properties['parameterName'],
185-
$properties['target'],
186-
$properties['if'],
187-
$properties['else'],
188-
$properties['negated'],
189-
);
190-
}
191-
192178
}

Diff for: src/Type/Constant/ConstantArrayType.php

-8
Original file line numberDiff line numberDiff line change
@@ -1712,12 +1712,4 @@ public function getFiniteTypes(): array
17121712
return $finiteTypes;
17131713
}
17141714

1715-
/**
1716-
* @param mixed[] $properties
1717-
*/
1718-
public static function __set_state(array $properties): Type
1719-
{
1720-
return new self($properties['keyTypes'], $properties['valueTypes'], $properties['nextAutoIndexes'] ?? $properties['nextAutoIndex'], $properties['optionalKeys'] ?? [], $properties['isList'] ?? TrinaryLogic::createNo());
1721-
}
1722-
17231715
}

0 commit comments

Comments
 (0)