Skip to content

Commit 03760ba

Browse files
committed
Mark classes as readonly where appropriate
1 parent ef787c0 commit 03760ba

13 files changed

+31
-35
lines changed

phpstan-baseline.neon

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,6 @@ parameters:
6666
count: 3
6767
path: src/Metadata/AttributeMetadataFactory.php
6868

69-
-
70-
message: '#^Property Patchlevel\\Hydrator\\Metadata\\AttributeMetadataFactory\:\:\$guesser \(Patchlevel\\Hydrator\\Guesser\\Guesser\|null\) is never assigned null so it can be removed from the property type\.$#'
71-
identifier: property.unusedType
72-
count: 1
73-
path: src/Metadata/AttributeMetadataFactory.php
74-
7569
-
7670
message: '#^Property Patchlevel\\Hydrator\\Metadata\\ClassMetadata\<T of object \= object\>\:\:\$reflection \(ReflectionClass\<T of object \= object\>\) does not accept ReflectionClass\<object\>\.$#'
7771
identifier: assign.propertyType

src/Guesser/BuiltInGuesser.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@
1616
use Symfony\Component\TypeInfo\Type\BackedEnumType;
1717
use Symfony\Component\TypeInfo\Type\ObjectType;
1818

19-
final class BuiltInGuesser implements Guesser
19+
final readonly class BuiltInGuesser implements Guesser
2020
{
2121
public function __construct(
22-
private readonly bool $fallbackObjectNormalizer = true,
22+
private bool $fallbackObjectNormalizer = true,
2323
) {
2424
}
2525

src/Guesser/ChainGuesser.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
use Patchlevel\Hydrator\Normalizer\Normalizer;
88
use Symfony\Component\TypeInfo\Type\ObjectType;
99

10-
final class ChainGuesser implements Guesser
10+
final readonly class ChainGuesser implements Guesser
1111
{
1212
/** @param iterable<Guesser> $guessers */
1313
public function __construct(
14-
private readonly iterable $guessers,
14+
private iterable $guessers,
1515
) {
1616
}
1717

src/Metadata/AttributeMetadataFactory.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ final class AttributeMetadataFactory implements MetadataFactory
4242

4343
private readonly TypeResolver $typeResolver;
4444

45-
private readonly Guesser|null $guesser;
45+
private readonly Guesser $guesser;
4646

4747
public function __construct(
4848
TypeResolver|null $typeResolver = null,
@@ -375,6 +375,7 @@ private function getNormalizer(ReflectionProperty $reflectionProperty): Normaliz
375375

376376
private function findNormalizerOnProperty(ReflectionProperty $reflectionProperty): Normalizer|null
377377
{
378+
/** @var list<ReflectionAttribute<Normalizer>> $attributeReflectionList */
378379
$attributeReflectionList = $reflectionProperty->getAttributes(
379380
Normalizer::class,
380381
ReflectionAttribute::IS_INSTANCEOF,
@@ -479,6 +480,7 @@ private function findNormalizerOnClass(string $class): Normalizer|null
479480
{
480481
$reflectionClass = new ReflectionClass($class);
481482

483+
/** @var list<ReflectionAttribute<Normalizer>> $attributes */
482484
$attributes = $reflectionClass->getAttributes(
483485
Normalizer::class,
484486
ReflectionAttribute::IS_INSTANCEOF,

src/Metadata/CallbackMetadata.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
* method: string,
1313
* }
1414
*/
15-
final class CallbackMetadata
15+
final readonly class CallbackMetadata
1616
{
1717
public function __construct(
18-
private readonly ReflectionMethod $reflection,
18+
private ReflectionMethod $reflection,
1919
) {
2020
}
2121

src/Metadata/ClassMetadata.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
* }
1818
* @template T of object = object
1919
*/
20-
final class ClassMetadata
20+
final readonly class ClassMetadata
2121
{
2222
/**
2323
* @param ReflectionClass<T> $reflection
@@ -26,12 +26,12 @@ final class ClassMetadata
2626
* @param list<CallbackMetadata> $preExtractCallbacks
2727
*/
2828
public function __construct(
29-
private readonly ReflectionClass $reflection,
30-
private readonly array $properties = [],
31-
private readonly string|null $dataSubjectIdField = null,
32-
private readonly array $postHydrateCallbacks = [],
33-
private readonly array $preExtractCallbacks = [],
34-
private readonly bool|null $lazy = null,
29+
private ReflectionClass $reflection,
30+
private array $properties = [],
31+
private string|null $dataSubjectIdField = null,
32+
private array $postHydrateCallbacks = [],
33+
private array $preExtractCallbacks = [],
34+
private bool|null $lazy = null,
3535
) {
3636
}
3737

src/Metadata/Psr16MetadataFactory.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66

77
use Psr\SimpleCache\CacheInterface;
88

9-
final class Psr16MetadataFactory implements MetadataFactory
9+
final readonly class Psr16MetadataFactory implements MetadataFactory
1010
{
1111
public function __construct(
12-
private readonly MetadataFactory $metadataFactory,
13-
private readonly CacheInterface $cache,
12+
private MetadataFactory $metadataFactory,
13+
private CacheInterface $cache,
1414
) {
1515
}
1616

src/Metadata/Psr6MetadataFactory.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66

77
use Psr\Cache\CacheItemPoolInterface;
88

9-
final class Psr6MetadataFactory implements MetadataFactory
9+
final readonly class Psr6MetadataFactory implements MetadataFactory
1010
{
1111
public function __construct(
12-
private readonly MetadataFactory $metadataFactory,
13-
private readonly CacheItemPoolInterface $cache,
12+
private MetadataFactory $metadataFactory,
13+
private CacheItemPoolInterface $cache,
1414
) {
1515
}
1616

src/Normalizer/ArrayNormalizer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@
1313
use function is_array;
1414

1515
#[Attribute(Attribute::TARGET_PROPERTY)]
16-
final class ArrayNormalizer implements Normalizer, TypeAwareNormalizer, HydratorAwareNormalizer
16+
final readonly class ArrayNormalizer implements Normalizer, TypeAwareNormalizer, HydratorAwareNormalizer
1717
{
1818
public function __construct(
19-
private readonly Normalizer $normalizer,
19+
private Normalizer $normalizer,
2020
) {
2121
}
2222

src/Normalizer/ArrayShapeNormalizer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@
1313
use function is_array;
1414

1515
#[Attribute(Attribute::TARGET_PROPERTY)]
16-
final class ArrayShapeNormalizer implements Normalizer, TypeAwareNormalizer, HydratorAwareNormalizer
16+
final readonly class ArrayShapeNormalizer implements Normalizer, TypeAwareNormalizer, HydratorAwareNormalizer
1717
{
1818
/** @param array<array-key, Normalizer> $normalizerMap */
1919
public function __construct(
20-
private readonly array $normalizerMap,
20+
private array $normalizerMap,
2121
) {
2222
}
2323

0 commit comments

Comments
 (0)