Skip to content

Commit 63bb48e

Browse files
derrabusnicolas-grekas
authored andcommitted
[Serializer] Add types to private and internal properties
1 parent bfd34b3 commit 63bb48e

40 files changed

+171
-204
lines changed

src/Symfony/Component/Serializer/Annotation/Context.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ class Context
3333
* @throws InvalidArgumentException
3434
*/
3535
public function __construct(
36-
private array $context = [],
37-
private array $normalizationContext = [],
38-
private array $denormalizationContext = [],
36+
private readonly array $context = [],
37+
private readonly array $normalizationContext = [],
38+
private readonly array $denormalizationContext = [],
3939
string|array $groups = [],
4040
) {
4141
if (!$context && !$normalizationContext && !$denormalizationContext) {

src/Symfony/Component/Serializer/Annotation/DiscriminatorMap.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626
class DiscriminatorMap
2727
{
2828
public function __construct(
29-
private string $typeProperty,
30-
private array $mapping,
29+
private readonly string $typeProperty,
30+
private readonly array $mapping,
3131
) {
3232
if (empty($typeProperty)) {
3333
throw new InvalidArgumentException(sprintf('Parameter "typeProperty" of annotation "%s" cannot be empty.', static::class));

src/Symfony/Component/Serializer/Annotation/Groups.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class Groups
2828
/**
2929
* @var string[]
3030
*/
31-
private array $groups;
31+
private readonly array $groups;
3232

3333
/**
3434
* @param string|string[] $groups

src/Symfony/Component/Serializer/Annotation/MaxDepth.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
#[\Attribute(\Attribute::TARGET_METHOD | \Attribute::TARGET_PROPERTY)]
2626
class MaxDepth
2727
{
28-
public function __construct(private int $maxDepth)
28+
public function __construct(private readonly int $maxDepth)
2929
{
3030
if ($maxDepth <= 0) {
3131
throw new InvalidArgumentException(sprintf('Parameter of annotation "%s" must be a positive integer.', static::class));

src/Symfony/Component/Serializer/Annotation/SerializedName.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
#[\Attribute(\Attribute::TARGET_METHOD | \Attribute::TARGET_PROPERTY)]
2626
final class SerializedName
2727
{
28-
public function __construct(private string $serializedName)
28+
public function __construct(private readonly string $serializedName)
2929
{
3030
if ('' === $serializedName) {
3131
throw new InvalidArgumentException(sprintf('Parameter of annotation "%s" must be a non-empty string.', self::class));

src/Symfony/Component/Serializer/CacheWarmer/CompiledClassMetadataCacheWarmer.php

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,12 @@
2121
*/
2222
final class CompiledClassMetadataCacheWarmer implements CacheWarmerInterface
2323
{
24-
private $classesToCompile;
25-
26-
private $classMetadataFactory;
27-
28-
private $classMetadataFactoryCompiler;
29-
30-
private $filesystem;
31-
32-
public function __construct(array $classesToCompile, ClassMetadataFactoryInterface $classMetadataFactory, ClassMetadataFactoryCompiler $classMetadataFactoryCompiler, Filesystem $filesystem)
33-
{
34-
$this->classesToCompile = $classesToCompile;
35-
$this->classMetadataFactory = $classMetadataFactory;
36-
$this->classMetadataFactoryCompiler = $classMetadataFactoryCompiler;
37-
$this->filesystem = $filesystem;
24+
public function __construct(
25+
private readonly array $classesToCompile,
26+
private readonly ClassMetadataFactoryInterface $classMetadataFactory,
27+
private readonly ClassMetadataFactoryCompiler $classMetadataFactoryCompiler,
28+
private readonly Filesystem $filesystem,
29+
) {
3830
}
3931

4032
public function warmUp(string $cacheDir): array

src/Symfony/Component/Serializer/Encoder/ChainDecoder.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,17 @@
2424
*/
2525
class ChainDecoder implements ContextAwareDecoderInterface
2626
{
27-
private array $decoders = [];
27+
/**
28+
* @var array<string, array-key>
29+
*/
2830
private array $decoderByFormat = [];
2931

30-
public function __construct(array $decoders = [])
31-
{
32-
$this->decoders = $decoders;
32+
/**
33+
* @param array<array-key, DecoderInterface> $decoders
34+
*/
35+
public function __construct(
36+
private readonly array $decoders = []
37+
) {
3338
}
3439

3540
final public function decode(string $data, string $format, array $context = []): mixed

src/Symfony/Component/Serializer/Encoder/ChainEncoder.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,17 @@
2525
*/
2626
class ChainEncoder implements ContextAwareEncoderInterface
2727
{
28-
private array $encoders = [];
28+
/**
29+
* @var array<string, array-key>
30+
*/
2931
private array $encoderByFormat = [];
3032

31-
public function __construct(array $encoders = [])
32-
{
33-
$this->encoders = $encoders;
33+
/**
34+
* @param array<array-key, EncoderInterface> $encoders
35+
*/
36+
public function __construct(
37+
private readonly array $encoders = []
38+
) {
3439
}
3540

3641
final public function encode(mixed $data, string $format, array $context = []): string

src/Symfony/Component/Serializer/Encoder/CsvEncoder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class CsvEncoder implements EncoderInterface, DecoderInterface
3838

3939
private const FORMULAS_START_CHARACTERS = ['=', '-', '+', '@', "\t", "\r"];
4040

41-
private $defaultContext = [
41+
private array $defaultContext = [
4242
self::DELIMITER_KEY => ',',
4343
self::ENCLOSURE_KEY => '"',
4444
self::ESCAPE_CHAR_KEY => '',

src/Symfony/Component/Serializer/Encoder/JsonDecode.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class JsonDecode implements DecoderInterface
3434
*/
3535
public const RECURSION_DEPTH = 'json_decode_recursion_depth';
3636

37-
private $defaultContext = [
37+
private array $defaultContext = [
3838
self::ASSOCIATIVE => false,
3939
self::OPTIONS => 0,
4040
self::RECURSION_DEPTH => 512,

0 commit comments

Comments
 (0)