Skip to content

Commit 28feb60

Browse files
committed
fix debug
1 parent 0f313df commit 28feb60

31 files changed

+134
-7047
lines changed

composer.lock

Lines changed: 0 additions & 6869 deletions
This file was deleted.

src/Annotations/Input/InputDateFormat.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44

55
namespace Astral\Serialize\Annotations\Input;
66

7-
use DateTimeZone;
8-
use DateInvalidTimeZoneException;
97
use Astral\Serialize\Contracts\Attribute\InputValueCastInterface;
108
use Astral\Serialize\Support\Collections\DataCollection;
119
use Astral\Serialize\Support\Context\InputValueContext;
1210
use Attribute;
11+
use DateInvalidTimeZoneException;
1312
use DateTime;
1413
use DateTimeInterface;
14+
use DateTimeZone;
1515

1616
#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_CLASS)]
1717
class InputDateFormat implements InputValueCastInterface

src/Annotations/Output/OutputDateFormat.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44

55
namespace Astral\Serialize\Annotations\Output;
66

7-
use DateMalformedStringException;
8-
use DateInvalidTimeZoneException;
97
use Astral\Serialize\Contracts\Attribute\OutValueCastInterface;
108
use Astral\Serialize\Support\Collections\DataCollection;
119
use Astral\Serialize\Support\Context\OutContext;
1210
use Attribute;
11+
use DateInvalidTimeZoneException;
12+
use DateMalformedStringException;
1313
use DateTime;
1414
use DateTimeInterface;
1515
use DateTimeZone;
@@ -50,9 +50,9 @@ private function formatValue(mixed $value): ?string
5050

5151
return match (true) {
5252
is_subclass_of($value, DateTimeInterface::class) => $this->formatDateTime($value, $timezone),
53-
is_numeric($value) => $this->formatTimestamp((int)$value, $timezone),
53+
is_numeric($value) => $this->formatTimestamp((int)$value, $timezone),
5454
is_string($value) && strtotime($value) !== false => $this->formatStringDate($value, $timezone),
55-
default => null,
55+
default => null,
5656
};
5757
}
5858

src/Casts/InputConstructCast.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,4 @@ public function getNotPromoted(array $constructorParameters, array $payload): ar
4040

4141
return $vols;
4242
}
43-
44-
public function getParams()
45-
{
46-
47-
}
4843
}

src/Casts/InputValue/InputArrayBestMatchChildCast.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,10 @@ public function match($value, DataCollection $collection, InputValueContext $con
2424
* @param $value
2525
* @param DataCollection $collection
2626
* @param InputValueContext $context
27-
* @return mixed
28-
* @throws NotFoundAttributePropertyResolver
27+
* @return array
2928
* @throws ReflectionException
3029
*/
31-
public function resolve($value, DataCollection $collection, InputValueContext $context): mixed
30+
public function resolve($value, DataCollection $collection, InputValueContext $context): array
3231
{
3332
$children = $collection->getChildren();
3433

src/Casts/InputValue/InputArraySingleChildCast.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,14 @@ public function match($value, DataCollection $collection, InputValueContext $con
2222

2323
/**
2424
* Resolve the input value for the given collection and context.
25-
* @throws NotFoundAttributePropertyResolver
2625
* @throws ReflectionException
2726
*/
2827
public function resolve(mixed $value, DataCollection $collection, InputValueContext $context): mixed
2928
{
3029
$child = current($collection->getChildren());
3130
$childType = $collection->getTypes()[0];
3231

33-
$context->chooseSerializeContext->getProperty($collection->getName())->setType($childType);
32+
$context->chooseSerializeContext->getProperty($collection->getName())?->setType($childType);
3433

3534
if ($childType->kind->isCollect()) {
3635
return $this->resolveArray($value, $child, $collection, $context);

src/Casts/InputValue/InputObjectBestMatchChildCast.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class InputObjectBestMatchChildCast implements InputValueCastInterface
1919
public function match($value, DataCollection $collection, InputValueContext $context): bool
2020
{
2121
return $value
22-
&& (is_object($value) || is_array($value) && $this->getDimension($value) === 1)
22+
&& (is_object($value) || (is_array($value) && $this->getDimension($value) === 1))
2323
&& count($collection->getChildren()) > 1 && $this->hasObjectType($collection);
2424
}
2525

@@ -28,7 +28,6 @@ public function match($value, DataCollection $collection, InputValueContext $con
2828
* @param DataCollection $collection
2929
* @param InputValueContext $context
3030
* @return mixed
31-
* @throws NotFoundAttributePropertyResolver
3231
* @throws ReflectionException
3332
*/
3433
public function resolve($value, DataCollection $collection, InputValueContext $context): mixed
@@ -65,7 +64,7 @@ private function getBestMatchClass(DataCollection $collection, array $children,
6564
$defaultGroup = $context->chooseSerializeContext->serializeClass;
6665

6766
foreach ($collection->getTypes() as $type) {
68-
if ($type->kind != TypeKindEnum::CLASS_OBJECT) {
67+
if ($type->kind !== TypeKindEnum::CLASS_OBJECT) {
6968
continue;
7069
}
7170

@@ -89,7 +88,7 @@ private function getBestMatchClass(DataCollection $collection, array $children,
8988
private function hasObjectType(DataCollection $collection): bool
9089
{
9190
foreach ($collection->getTypes() as $type) {
92-
if ($type->kind == TypeKindEnum::CLASS_OBJECT) {
91+
if ($type->kind === TypeKindEnum::CLASS_OBJECT) {
9392
return true;
9493
}
9594
}

src/Casts/InputValue/InputValueEnumCast.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function resolve(mixed $value, DataCollection $collection, InputValueCont
2727

2828
$types = $collection->getTypes();
2929
foreach ($types as $type) {
30-
if ($type->kind != TypeKindEnum::ENUM) {
30+
if ($type->kind !== TypeKindEnum::ENUM) {
3131
continue;
3232
}
3333
$enumInstance = $this->findEnumInstance($type->className, $value);
@@ -36,7 +36,7 @@ public function resolve(mixed $value, DataCollection $collection, InputValueCont
3636
}
3737
}
3838

39-
if (count($types) == 1) {
39+
if (count($types) === 1) {
4040
throw new ValueCastError(
4141
sprintf(
4242
'Enum value "%s" not found in EnumClass: %s',
@@ -73,7 +73,7 @@ private function findEnumInstance(string $className, string $value): ?UnitEnum
7373
private function hasEnumType(DataCollection $collection): bool
7474
{
7575
foreach ($collection->getTypes() as $type) {
76-
if ($type->kind == TypeKindEnum::ENUM) {
76+
if ($type->kind === TypeKindEnum::ENUM) {
7777
return true;
7878
}
7979
}

src/Casts/InputValue/Trait/InputArrayTrait.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ trait InputArrayTrait
1313
{
1414
/**
1515
* @throws ReflectionException
16-
* @throws NotFoundAttributePropertyResolver
1716
*/
1817
private function resolveArray(array $value, GroupDataCollection $child, DataCollection $collection, InputValueContext $context): array
1918
{
@@ -26,7 +25,6 @@ private function resolveArray(array $value, GroupDataCollection $child, DataColl
2625
}
2726

2827
/**
29-
* @throws NotFoundAttributePropertyResolver
3028
* @throws ReflectionException
3129
*/
3230
private function resolveSingle(mixed $value, GroupDataCollection $child, DataCollection $collection, InputValueContext $context): mixed
@@ -38,7 +36,6 @@ private function resolveSingle(mixed $value, GroupDataCollection $child, DataCol
3836
/**
3937
* Resolve a child collection.
4038
*
41-
* @throws NotFoundAttributePropertyResolver
4239
* @throws ReflectionException
4340
*/
4441
private function resolveChild(GroupDataCollection $child, mixed $value, InputValueContext $context, ChooseSerializeContext $chooseContext): mixed
@@ -57,11 +54,11 @@ private function createChooseContext(InputValueContext $context, DataCollection
5754
if ($key !== null) {
5855
$context->chooseSerializeContext
5956
->getProperty($collection->getName())
60-
->addChildren($chooseContext, $key);
57+
?->addChildren($chooseContext, $key);
6158
} else {
6259
$context->chooseSerializeContext
6360
->getProperty($collection->getName())
64-
->addChildren($chooseContext);
61+
?->addChildren($chooseContext);
6562
}
6663

6764
return $chooseContext;

src/Casts/OutValue/OutArrayChildCast.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class OutArrayChildCast implements OutValueCastInterface
1313
{
1414
public function match($value, DataCollection $collection, OutContext $context): bool
1515
{
16-
return in_array($context->chooseSerializeContext->getProperty($collection->getName())?->getType()?->kind, [TypeKindEnum::COLLECT_SINGLE_OBJECT,TypeKindEnum::OBJECT]);
16+
return in_array($context->chooseSerializeContext->getProperty($collection->getName())?->getType()?->kind, [TypeKindEnum::COLLECT_SINGLE_OBJECT, TypeKindEnum::OBJECT], true);
1717
}
1818

1919
/**
@@ -24,9 +24,9 @@ public function resolve(mixed $value, DataCollection $collection, OutContext $co
2424
$child = current($collection->getChildren());
2525
$childType = $collection->getTypes()[0];
2626

27-
$context->chooseSerializeContext->getProperty($collection->getName())->setType($childType);
27+
$context->chooseSerializeContext->getProperty($collection->getName())?->setType($childType);
2828

29-
$choose = $context->chooseSerializeContext->getProperty($collection->getName())->getChildren();
29+
$choose = $context->chooseSerializeContext->getProperty($collection->getName())?->getChildren();
3030

3131
if ($childType->kind === TypeKindEnum::COLLECT_SINGLE_OBJECT) {
3232
return $this->resolveArray($value, $child, $context, $choose);

0 commit comments

Comments
 (0)