Skip to content

Commit

Permalink
Merge pull request #1555 from scyzoryck/cleanup-union-discriminators
Browse files Browse the repository at this point in the history
Remove unused properties
  • Loading branch information
scyzoryck authored Aug 23, 2024
2 parents 9299b56 + 225f052 commit 3c18cb8
Show file tree
Hide file tree
Showing 5 changed files with 2 additions and 25 deletions.
1 change: 0 additions & 1 deletion src/Metadata/Driver/AnnotationOrAttributeDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,6 @@ public function loadMetadataForClass(\ReflectionClass $class): ?BaseClassMetadat
} elseif ($annot instanceof MaxDepth) {
$propertyMetadata->maxDepth = $annot->depth;
} elseif ($annot instanceof UnionDiscriminator) {
$propertyMetadata->setUnionDiscriminator($annot->field, $annot->map);
$propertyMetadata->setType([
'name' => 'union',
'params' => [null, $annot->field, $annot->map],
Expand Down
1 change: 0 additions & 1 deletion src/Metadata/Driver/XmlDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,6 @@ protected function loadMetadataFromFile(\ReflectionClass $class, string $path):
$map[(string) $entry->attributes()->key] = (string) $entry;
}

$pMetadata->setUnionDiscriminator((string) $colConfig->attributes()->field, $map);
$pMetadata->setType([
'name' => 'union',
'params' => [null, (string) $colConfig->attributes()->field, $map],
Expand Down
1 change: 0 additions & 1 deletion src/Metadata/Driver/YamlDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,6 @@ protected function loadMetadataFromFile(ReflectionClass $class, string $file): ?
}

if (isset($pConfig['union_discriminator'])) {
$pMetadata->setUnionDiscriminator($pConfig['union_discriminator']['field'], $pConfig['union_discriminator']['map']);
$pMetadata->setType([
'name' => 'union',
'params' => [null, $pConfig['union_discriminator']['field'], $pConfig['union_discriminator']['map']],
Expand Down
20 changes: 0 additions & 20 deletions src/Metadata/PropertyMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,6 @@ class PropertyMetadata extends BasePropertyMetadata
*/
public $serializedName;

/**
* @var string|null
*/
public $unionDiscriminatorField;

/**
* @var array<string, string>|null
*/
public $unionDiscriminatorMap;

/**
* @var array|null
*/
Expand Down Expand Up @@ -206,12 +196,6 @@ public function setAccessor(string $type, ?string $getter = null, ?string $sette
$this->setter = $setter;
}

public function setUnionDiscriminator(string $field, array $map): void
{
$this->unionDiscriminatorField = $field;
$this->unionDiscriminatorMap = $map;
}

public function setType(array $type): void
{
$this->type = $type;
Expand Down Expand Up @@ -240,8 +224,6 @@ protected function serializeToArray(): array
$this->untilVersion,
$this->groups,
$this->serializedName,
$this->unionDiscriminatorField,
$this->unionDiscriminatorMap,
$this->type,
$this->xmlCollection,
$this->xmlCollectionInline,
Expand Down Expand Up @@ -276,8 +258,6 @@ protected function unserializeFromArray(array $data): void
$this->untilVersion,
$this->groups,
$this->serializedName,
$this->unionDiscriminatorField,
$this->unionDiscriminatorMap,
$this->type,
$this->xmlCollection,
$this->xmlCollectionInline,
Expand Down
4 changes: 2 additions & 2 deletions tests/Metadata/Driver/BaseDriverTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,8 @@ public function testUnionDiscriminator()

$p = $m->propertyMetadata['data'];
assert($p instanceof PropertyMetadata);
self::assertEquals('objectType', $p->unionDiscriminatorField);
self::assertEquals(['author' => 'JMS\Serializer\Tests\Fixtures\DiscriminatedAuthor', 'comment' => 'JMS\Serializer\Tests\Fixtures\DiscriminatedComment'], $p->unionDiscriminatorMap);
self::assertEquals('objectType', $p->type['params'][1]);
self::assertEquals(['author' => 'JMS\Serializer\Tests\Fixtures\DiscriminatedAuthor', 'comment' => 'JMS\Serializer\Tests\Fixtures\DiscriminatedComment'], $p->type['params'][2]);
}

public function testVirtualProperty()
Expand Down

0 comments on commit 3c18cb8

Please sign in to comment.