Skip to content

Commit

Permalink
phpstan
Browse files Browse the repository at this point in the history
  • Loading branch information
idbentley committed Jul 4, 2024
1 parent b92dd32 commit e6b1a49
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 10 deletions.
16 changes: 8 additions & 8 deletions src/Handler/UnionHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

final class UnionHandler implements SubscribingHandlerInterface
{
static $aliases = ['boolean' => 'bool', 'integer' => 'int', 'double' => 'float'];
private static $aliases = ['boolean' => 'bool', 'integer' => 'int', 'double' => 'float'];

/**
* {@inheritdoc}
Expand Down Expand Up @@ -51,10 +51,6 @@ public function serializeUnion(
return $this->matchSimpleType($data, $type, $context);
}

/**
* @param mixed $data
* @param array $type
*/
public function deserializeUnion(DeserializationVisitorInterface $visitor, mixed $data, array $type, DeserializationContext $context)
{
if ($data instanceof \SimpleXMLElement) {
Expand All @@ -69,8 +65,8 @@ private function matchSimpleType(mixed $data, array $type, Context $context)
$dataType = $this->determineType($data, $type, $context->getFormat());
$alternativeName = null;

if (isset($aliases[$dataType])) {
$alternativeName = $aliases[$dataType];
if (isset(static::$aliases[$dataType])) {
$alternativeName = static::$aliases[$dataType];
}

foreach ($type['params'] as $possibleType) {
Expand Down Expand Up @@ -103,13 +99,15 @@ private function reorderTypes(array $type): array
return $type;
}

private function determineType(mixed $data, array $type, string $format): string
private function determineType(mixed $data, array $type, string $format): string|null

Check failure on line 102 in src/Handler/UnionHandler.php

View workflow job for this annotation

GitHub Actions / Static Analysis with PHPStan (7.4)

Method JMS\Serializer\Handler\UnionHandler::determineType() uses native union types but they're supported only on PHP 8.0 and later.
{
foreach ($this->reorderTypes($type)['params'] as $possibleType) {
if ($this->testPrimitive($data, $possibleType['name'], $format)) {
return $possibleType['name'];
}
}

return null;
}

private function testPrimitive(mixed $data, string $type, string $format): bool
Expand All @@ -130,5 +128,7 @@ private function testPrimitive(mixed $data, string $type, string $format): bool
case 'string':
return (string) $data === (string) $data;
}

return false;
}
}
2 changes: 1 addition & 1 deletion tests/Metadata/Driver/UnionTypedPropertiesDriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function testInferUnionTypesShouldResultInManyTypes()
],
],
],
$m->propertyMetadata['data']->type
$m->propertyMetadata['data']->type,
);
}

Expand Down
1 change: 0 additions & 1 deletion tests/Serializer/BaseSerializationTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -1987,7 +1987,6 @@ public function testSerializingUnionDocBlockTypesProperties()
$object = new UnionTypedDocBlockProperty(1.236);

self::assertEquals(static::getContent('data_float'), $this->serialize($object));

}

public function testThrowingExceptionWhenDeserializingUnionDocBlockTypes()
Expand Down

0 comments on commit e6b1a49

Please sign in to comment.