AccompanyingPeriodResource: fix deserialization + code style

This commit is contained in:
2022-01-10 23:08:23 +01:00
parent 8e012982f5
commit 2c4d06371c
8 changed files with 143 additions and 22 deletions

View File

@@ -38,15 +38,6 @@ class AccompanyingPeriodResourceNormalizer implements DenormalizerAwareInterface
$this->repository = $repository;
}
public function normalize($resource, $format = null, array $context = [])
{
return [
'type' => 'accompanying_period_resource',
'id' => $resource->getId(),
'comment' => $resource->getComment()
];
}
public function denormalize($data, $type, $format = null, array $context = [])
{
$resource = $this->extractObjectToPopulate($type, $context);
@@ -93,9 +84,22 @@ class AccompanyingPeriodResourceNormalizer implements DenormalizerAwareInterface
$resource->setResource($res);
}
if (array_key_exists('comment', $data)) {
$resource->setComment($data['comment']);
}
return $resource;
}
public function normalize($resource, $format = null, array $context = [])
{
return [
'type' => 'accompanying_period_resource',
'id' => $resource->getId(),
'comment' => $resource->getComment(),
];
}
public function supportsDenormalization($data, $type, $format = null)
{
return Resource::class === $type;