Skip to content

Commit d171580

Browse files
committed
Readonly classes/props
1 parent 73a7064 commit d171580

File tree

17 files changed

+72
-72
lines changed

17 files changed

+72
-72
lines changed

src/JsonMapper.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@
3333
/**
3434
* @psalm-suppress MixedAssignment
3535
*/
36-
final class JsonMapper
36+
final readonly class JsonMapper
3737
{
38-
private readonly Reflector $reflector;
38+
private Reflector $reflector;
3939

4040
public function __construct(
4141
/**
@@ -61,26 +61,26 @@ public function __construct(
6161
* Extra properties are properties of the JSON object that do not have a corresponding constructor parameter in
6262
* the PHP class.
6363
*/
64-
private readonly OnExtraProperties $onExtraProperties = OnExtraProperties::THROW_EXCEPTION,
64+
private OnExtraProperties $onExtraProperties = OnExtraProperties::THROW_EXCEPTION,
6565

6666
/**
6767
* Controls how missing properties in the JSON object are handled.
6868
* Missing properties are constructor parameters in the PHP class that do not have a corresponding property in
6969
* the JSON object.
7070
*/
71-
private readonly OnMissingProperties $onMissingProperties = OnMissingProperties::THROW_EXCEPTION,
71+
private OnMissingProperties $onMissingProperties = OnMissingProperties::THROW_EXCEPTION,
7272

7373
/**
7474
* Mapper to convert JSON property names to PHP property names.
7575
* By default, no conversion is performed.
7676
*/
77-
private readonly NameMapper $jsonToPhpNameMapper = new NullMapper(),
77+
private NameMapper $jsonToPhpNameMapper = new NullMapper(),
7878

7979
/**
8080
* Mapper to convert PHP property names to JSON property names.
8181
* By default, no conversion is performed.
8282
*/
83-
private readonly NameMapper $phpToJsonNameMapper = new NullMapper(),
83+
private NameMapper $phpToJsonNameMapper = new NullMapper(),
8484
) {
8585
$this->reflector = new Reflector(
8686
$allowUntypedArrays,

src/Reflection/Type/ArrayType.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
/**
1313
* @internal This class is not part of the public API, and may change without notice.
1414
*/
15-
final class ArrayType implements Stringable
15+
final readonly class ArrayType implements Stringable
1616
{
1717
public function __construct(
18-
public readonly UnionType $type,
18+
public UnionType $type,
1919
) {
2020
}
2121

src/Reflection/Type/ClassType.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@
1010
/**
1111
* @internal This class is not part of the public API, and may change without notice.
1212
*/
13-
final class ClassType implements Stringable
13+
final readonly class ClassType implements Stringable
1414
{
1515
/**
1616
* @param class-string $name
1717
*/
1818
public function __construct(
19-
public readonly string $name,
19+
public string $name,
2020
) {
2121
}
2222

src/Reflection/Type/EnumType.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@
1212
/**
1313
* @internal This class is not part of the public API, and may change without notice.
1414
*/
15-
final class EnumType implements Stringable
15+
final readonly class EnumType implements Stringable
1616
{
1717
/**
1818
* @param class-string<BackedEnum> $name
1919
*/
2020
public function __construct(
21-
public readonly string $name,
22-
public readonly bool $isIntBacked = false,
23-
public readonly bool $isStringBacked = false,
21+
public string $name,
22+
public bool $isIntBacked = false,
23+
public bool $isStringBacked = false,
2424
) {
2525
if (! ($this->isIntBacked xor $this->isStringBacked)) {
2626
throw new InvalidArgumentException('EnumType must be either int or string backed.');

src/Reflection/Type/SimpleType.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010
/**
1111
* @internal This class is not part of the public API, and may change without notice.
1212
*/
13-
final class SimpleType implements Stringable
13+
final readonly class SimpleType implements Stringable
1414
{
1515
public function __construct(
16-
public readonly string $name,
16+
public string $name,
1717
) {
1818
}
1919

src/Reflection/Type/UnionType.php

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,50 +24,50 @@
2424
*
2525
* @internal This class is not part of the public API, and may change without notice.
2626
*/
27-
final class UnionType implements Stringable
27+
final readonly class UnionType implements Stringable
2828
{
29-
public readonly bool $allowsInt;
29+
public bool $allowsInt;
3030

31-
public readonly bool $allowsFloat;
31+
public bool $allowsFloat;
3232

33-
public readonly bool $allowsString;
33+
public bool $allowsString;
3434

35-
public readonly bool $allowsTrue;
35+
public bool $allowsTrue;
3636

37-
public readonly bool $allowsFalse;
37+
public bool $allowsFalse;
3838

39-
public readonly bool $allowsNull;
39+
public bool $allowsNull;
4040

41-
public readonly bool $allowsRawArray;
41+
public bool $allowsRawArray;
4242

43-
public readonly bool $allowsRawObject;
43+
public bool $allowsRawObject;
4444

45-
public readonly bool $allowsMixed;
45+
public bool $allowsMixed;
4646

4747
/**
4848
* @var ClassType[]
4949
*/
50-
public readonly array $classTypes;
50+
public array $classTypes;
5151

5252
/**
5353
* At most one enum type per backed type (int, string) is allowed in a union.
5454
*
5555
* @var EnumType[]
5656
*/
57-
public readonly array $enumTypes;
57+
public array $enumTypes;
5858

5959
/**
6060
* At most one ArrayType is allowed in a union.
6161
*/
62-
public readonly ?ArrayType $arrayType;
62+
public ?ArrayType $arrayType;
6363

6464
/**
6565
* @param (SimpleType|ClassType|EnumType|ArrayType)[] $types
6666
*
6767
* @throws JsonMapperException
6868
*/
6969
public function __construct(
70-
public readonly array $types,
70+
public array $types,
7171
) {
7272
$this->ensureNotEmpty();
7373
$this->ensureNoDuplicateTypes();

src/Reflection/TypeParser.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ final class TypeParser
4444
private int $pointer = 0;
4545

4646
public function __construct(
47-
private string $type,
47+
private readonly string $type,
4848
) {
4949
}
5050

src/Reflection/TypeToken.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
/**
88
* @internal This class is not part of the public API, and may change without notice.
99
*/
10-
final class TypeToken
10+
final readonly class TypeToken
1111
{
1212
public function __construct(
13-
public readonly string $value,
14-
public readonly int $offset,
15-
public readonly bool $isNamedType,
13+
public string $value,
14+
public int $offset,
15+
public bool $isNamedType,
1616
) {
1717
}
1818
}

tests/Attributes/ExpectException.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use Attribute;
88

99
#[Attribute(Attribute::TARGET_PARAMETER)]
10-
final class ExpectException
10+
final readonly class ExpectException
1111
{
1212
/**
1313
* @param array{
@@ -17,9 +17,9 @@ final class ExpectException
1717
* } $config
1818
*/
1919
public function __construct(
20-
public readonly string $message,
21-
public readonly array $config = [],
22-
public readonly ?int $maxPhpVersionId = null,
20+
public string $message,
21+
public array $config = [],
22+
public ?int $maxPhpVersionId = null,
2323
) {
2424
}
2525
}

tests/Attributes/ExpectParameterType.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use Attribute;
88

99
#[Attribute(Attribute::TARGET_PARAMETER)]
10-
final class ExpectParameterType
10+
final readonly class ExpectParameterType
1111
{
1212
/**
1313
* @param array{
@@ -17,8 +17,8 @@ final class ExpectParameterType
1717
* } $config
1818
*/
1919
public function __construct(
20-
public readonly string $type,
21-
public readonly array $config = [],
20+
public string $type,
21+
public array $config = [],
2222
) {
2323
}
2424
}

0 commit comments

Comments
 (0)