Skip to content

Commit 1bc6f27

Browse files
authored
chore: Reflection 2x (#11)
BREAKING CHANGE: updated Reflection to 2.x, which breaks some interactions with it * docs: Separate docs * feat: Polymorphic type adapter and less required dependencies * fix: Don't allow int in UnexpectedPolymorphicTypeException * refactor: Upgrade to reflection 2.x * fix: Failing tests * refactor: Code style * fix: Failing PHPStan * fix: Failing tests * refactor: Code style BREAKING CHANGE: updated Reflection to 2.x, which breaks some interactions with it
1 parent 8ad5db6 commit 1bc6f27

33 files changed

+152
-146
lines changed

.github/workflows/tests.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99
strategy:
1010
fail-fast: true
1111
matrix:
12-
php: [ 8.2 ]
12+
php: [ 8.2, 8.3, 8.4 ]
1313

1414
steps:
1515
- name: Checkout code
@@ -50,7 +50,7 @@ jobs:
5050
- name: Setup PHP
5151
uses: shivammathur/setup-php@v2
5252
with:
53-
php-version: 8.2
53+
php-version: 8.4
5454
extensions: dom, curl, libxml, mbstring, zip
5555
tools: composer:v2
5656
coverage: none
@@ -76,7 +76,7 @@ jobs:
7676
strategy:
7777
fail-fast: true
7878
matrix:
79-
php: [ 8.2 ]
79+
php: [ 8.2, 8.3, 8.4 ]
8080
steps:
8181
- name: Checkout code
8282
uses: actions/checkout@v3

composer.json

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,17 @@
1010
],
1111
"require": {
1212
"php": ">=8.2",
13-
"good-php/reflection": "^1.0",
14-
"illuminate/support": "^10.0 || ^11.0"
13+
"good-php/reflection": "^2.0",
14+
"illuminate/support": "^10.0 || ^11.0 || ^12.0"
1515
},
1616
"require-dev": {
17-
"pestphp/pest": "^2.8",
18-
"php-cs-fixer/shim": "~3.19.2",
19-
"tenantcloud/php-cs-fixer-rule-sets": "~3.0.0",
20-
"phpstan/phpstan": "~1.10.21",
21-
"phpstan/phpstan-phpunit": "^1.3",
22-
"phpstan/phpstan-webmozart-assert": "^1.2",
23-
"phpstan/phpstan-mockery": "^1.1",
17+
"pestphp/pest": "^3.8",
18+
"php-cs-fixer/shim": "~3.80.0",
19+
"tenantcloud/php-cs-fixer-rule-sets": "~3.4.1",
20+
"phpstan/phpstan": "~2.1.17",
21+
"phpstan/phpstan-phpunit": "^2.0",
22+
"phpstan/phpstan-webmozart-assert": "^2.0",
23+
"phpstan/phpstan-mockery": "^2.0",
2424
"phake/phake": "^4.2",
2525
"tenantcloud/php-standard": "^2.2"
2626
},

phpstan.neon

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,4 @@ parameters:
1010
- src
1111

1212
ignoreErrors:
13-
# There's no extension for that :(
14-
# - '#Call to an undefined method Pest\\Expectations\\Expectation|Pest\\Expectations\\Support\\Extendable::#i'
13+
- '#Parameter (\#|\$).* expects list<(.*)>, array<int, \2> given.#i'

src/Serializer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,5 @@ public function reflector(): Reflector;
2626
*
2727
* @return A
2828
*/
29-
public function adapter(string $typeAdapterType, Type|string $type, Attributes $attributes = new ArrayAttributes(), TypeAdapterFactory $skipPast = null): TypeAdapter;
29+
public function adapter(string $typeAdapterType, Type|string $type, Attributes $attributes = new ArrayAttributes(), ?TypeAdapterFactory $skipPast = null): TypeAdapter;
3030
}

src/Serializer/Registry/Cache/MemoizingTypeAdapterRegistry.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public function __construct(
2929
*
3030
* @return TypeAdapterType
3131
*/
32-
public function forType(string $typeAdapterType, Serializer $serializer, Type $type, Attributes $attributes = new ArrayAttributes(), TypeAdapterFactory $skipPast = null): TypeAdapter
32+
public function forType(string $typeAdapterType, Serializer $serializer, Type $type, Attributes $attributes = new ArrayAttributes(), ?TypeAdapterFactory $skipPast = null): TypeAdapter
3333
{
3434
$this->resolved[$typeAdapterType][(string) $type] ??= new WeakMap();
3535

src/Serializer/Registry/Factory/FactoryTypeAdapterRegistry.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function __construct(
3030
*
3131
* @return TypeAdapterType
3232
*/
33-
public function forType(string $typeAdapterType, Serializer $serializer, Type $type, Attributes $attributes = new ArrayAttributes(), TypeAdapterFactory $skipPast = null): TypeAdapter
33+
public function forType(string $typeAdapterType, Serializer $serializer, Type $type, Attributes $attributes = new ArrayAttributes(), ?TypeAdapterFactory $skipPast = null): TypeAdapter
3434
{
3535
if ($skipPast) {
3636
$skipPastIndex = array_search($skipPast, $this->factories, true);

src/Serializer/Registry/TypeAdapterNotFoundException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ final class TypeAdapterNotFoundException extends RuntimeException
1414
/**
1515
* @param TypeAdapterFactory<TypeAdapter<mixed, mixed>>|null $skipPast
1616
*/
17-
public function __construct(string $typeAdapterType, Type $type, Attributes $attributes, ?TypeAdapterFactory $skipPast, Throwable $previous = null)
17+
public function __construct(string $typeAdapterType, Type $type, Attributes $attributes, ?TypeAdapterFactory $skipPast, ?Throwable $previous = null)
1818
{
1919
$message = "A matching type adapter of type '{$typeAdapterType}' for type '{$type}' " .
2020
($attributes->has() ? 'with attributes ' . $attributes : '') .

src/Serializer/Registry/TypeAdapterRegistry.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@ interface TypeAdapterRegistry
1919
*
2020
* @return TypeAdapterType
2121
*/
22-
public function forType(string $typeAdapterType, Serializer $serializer, Type $type, Attributes $attributes = new ArrayAttributes(), TypeAdapterFactory $skipPast = null): TypeAdapter;
22+
public function forType(string $typeAdapterType, Serializer $serializer, Type $type, Attributes $attributes = new ArrayAttributes(), ?TypeAdapterFactory $skipPast = null): TypeAdapter;
2323
}

src/Serializer/TypeAdapterRegistrySerializer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public function __construct(
1919
private readonly Reflector $reflector,
2020
) {}
2121

22-
public function adapter(string $typeAdapterType, Type|string $type, Attributes $attributes = new ArrayAttributes(), TypeAdapterFactory $skipPast = null): TypeAdapter
22+
public function adapter(string $typeAdapterType, Type|string $type, Attributes $attributes = new ArrayAttributes(), ?TypeAdapterFactory $skipPast = null): TypeAdapter
2323
{
2424
if (is_string($type)) {
2525
$type = new NamedType($type);

src/TypeAdapter/Exception/UnexpectedEnumValueException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class UnexpectedEnumValueException extends RuntimeException implements Unexpecte
1313
public function __construct(
1414
public readonly string|int $value,
1515
public readonly array $expectedValues,
16-
Throwable $previous = null
16+
?Throwable $previous = null
1717
) {
1818
parent::__construct(
1919
'Expected one of [' .

0 commit comments

Comments
 (0)