Skip to content

Commit f709c6e

Browse files
minor #45721 [Serializer] Add types to private and internal properties (derrabus)
This PR was merged into the 6.3 branch. Discussion ---------- [Serializer] Add types to private and internal properties | Q | A | ------------- | --- | Branch? | 6.1 | Bug fix? | no | New feature? | no | Deprecations? | no | Tickets | N/A | License | MIT | Doc PR | N/A This PR adds types to private and ``@internal`` properties of the serializer component. This time, I've also applied CPP and `readonly` flags where possible. If this makes the review too hard or there are other reasons not to do that, please tell me and I'll skip it in future PRs. Commits ------- 7ff739a [Serializer] Add types to private and internal properties
2 parents bfd34b3 + 7ff739a commit f709c6e

Some content is hidden

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

43 files changed

+173
-206
lines changed

src/Symfony/Bundle/SecurityBundle/DependencyInjection/MainConfiguration.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class MainConfiguration implements ConfigurationInterface
4040
private array $userProviderFactories;
4141

4242
/**
43-
* @param array<array-key, AuthenticatorFactoryInterface> $factories
43+
* @param array<AuthenticatorFactoryInterface> $factories
4444
*/
4545
public function __construct(array $factories, array $userProviderFactories)
4646
{
@@ -173,7 +173,7 @@ private function addAccessControlSection(ArrayNodeDefinition $rootNode): void
173173
}
174174

175175
/**
176-
* @param array<array-key, AuthenticatorFactoryInterface> $factories
176+
* @param array<AuthenticatorFactoryInterface> $factories
177177
*/
178178
private function addFirewallsSection(ArrayNodeDefinition $rootNode, array $factories): void
179179
{

src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/AccessTokenFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ final class AccessTokenFactory extends AbstractFactory implements StatelessAuthe
3030
private const PRIORITY = -40;
3131

3232
/**
33-
* @param array<array-key, TokenHandlerFactoryInterface> $tokenHandlerFactories
33+
* @param array<TokenHandlerFactoryInterface> $tokenHandlerFactories
3434
*/
3535
public function __construct(private readonly array $tokenHandlerFactories)
3636
{

src/Symfony/Component/Form/ChoiceList/View/ChoiceGroupView.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class ChoiceGroupView implements \IteratorAggregate
2626
/**
2727
* Creates a new choice group view.
2828
*
29-
* @param array<array-key, ChoiceGroupView|ChoiceView> $choices the choice views in the group
29+
* @param array<ChoiceGroupView|ChoiceView> $choices the choice views in the group
3030
*/
3131
public function __construct(string $label, array $choices = [])
3232
{

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<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

0 commit comments

Comments
 (0)