Skip to content

Commit 89e5965

Browse files
Get rid of unused event classes.
1 parent be38acd commit 89e5965

File tree

7 files changed

+31
-36
lines changed

7 files changed

+31
-36
lines changed

webapp/src/DataTransferObject/Shadowing/Account.php

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

webapp/src/DataTransferObject/Shadowing/Award.php

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

webapp/src/DataTransferObject/Shadowing/EventType.php

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,11 @@ public static function fromString(string $value): EventType
3030
}
3131

3232
/**
33-
* @return class-string<EventData>
33+
* @return class-string<EventData>|null
3434
*/
35-
public function getEventClass(): string
35+
public function getEventClass(): ?string
3636
{
3737
switch ($this) {
38-
case self::ACCOUNTS:
39-
return Account::class;
40-
case self::AWARDS:
41-
return Award::class;
4238
case self::CLARIFICATIONS:
4339
return ClarificationEvent::class;
4440
case self::CONTESTS:
@@ -63,8 +59,7 @@ public function getEventClass(): string
6359
return SubmissionEvent::class;
6460
case self::TEAMS:
6561
return TeamEvent::class;
66-
case self::TEAM_MEMBERS:
67-
return TeamMember::class;
6862
}
63+
return null;
6964
}
7065
}

webapp/src/DataTransferObject/Shadowing/TeamMember.php

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

webapp/src/Serializer/Shadowing/EventDataDenormalizer.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ public function denormalize(
3939

4040
$eventType = $context['event_type'];
4141
$eventClass = $eventType->getEventClass();
42+
if ($eventClass === null) {
43+
return null;
44+
}
4245

4346
// Unset the event type, so we are not calling ourselves recursively
4447
unset($context['event_type']);

webapp/src/Serializer/Shadowing/EventDenormalizer.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,17 +62,24 @@ public function denormalize(
6262
} else {
6363
$id = null;
6464
}
65+
if ($eventType->getEventClass() === null) {
66+
$eventData = [];
67+
} else {
68+
$eventData = isset($data['data']) ? $this->serializer->denormalize($data['data'], EventData::class . '[]', $format, $context + ['event_type' => $eventType]) : [];
69+
}
6570
return new Event(
6671
$data['token'] ?? null,
6772
$eventType,
6873
$operation,
6974
$id,
70-
isset($data['data']) ? $this->serializer->denormalize($data['data'], EventData::class . '[]', $format, $context + ['event_type' => $eventType]) : [],
75+
$eventData,
7176
);
7277
} else {
7378
$operation = Operation::from($data['op']);
7479
if ($operation === Operation::DELETE) {
7580
$eventData = [];
81+
} elseif ($eventType->getEventClass() === null) {
82+
$eventData = [];
7683
} else {
7784
$eventData = [$this->serializer->denormalize($data['data'], EventData::class, $format, $context + ['event_type' => $eventType])];
7885
}

webapp/tests/Unit/Serializer/Shadowing/EventDenormalizerTest.php

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public function testDenormalizeUseContext(
2424
Operation $expectedOperation,
2525
?string $expectedObjectId,
2626
array $expectedData
27-
) {
27+
): void {
2828
$serializer = $this->getcontainer()->get(SerializerInterface::class);
2929
$event = $serializer->denormalize($data, Event::class, 'json', $context);
3030
self::assertEquals($expectedId, $event->id);
@@ -45,7 +45,7 @@ public function testDenormalizeDoNotUseContext(
4545
Operation $expectedOperation,
4646
?string $expectedObjectId,
4747
array $expectedData
48-
) {
48+
): void {
4949
$serializer = $this->getcontainer()->get(SerializerInterface::class);
5050
$event = $serializer->denormalize($data, Event::class, 'json', ['api_version' => null]);
5151
self::assertEquals($expectedId, $event->id);
@@ -87,6 +87,21 @@ public function provideDenormalize(): Generator
8787
),
8888
],
8989
];
90+
yield '2022-07 format, create/update unknown class' => [
91+
[
92+
'type' => 'team-members',
93+
'token' => 'sometoken',
94+
'data' => [
95+
['id' => '123'],
96+
],
97+
],
98+
['api_version' => '2022-07'],
99+
'sometoken',
100+
EventType::TEAM_MEMBERS,
101+
Operation::CREATE,
102+
'123',
103+
[],
104+
];
90105
yield '2022-07 format, create/update multiple' => [
91106
[
92107
'type' => 'languages',

0 commit comments

Comments
 (0)