Skip to content

Commit

Permalink
Fix FiasSerializer
Browse files Browse the repository at this point in the history
  • Loading branch information
liquetsoft committed Sep 24, 2024
1 parent 7c2a28b commit 67d1b71
Showing 1 changed file with 28 additions and 54 deletions.
82 changes: 28 additions & 54 deletions src/Serializer/CompiledEntitesDenormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,40 +35,40 @@
/**
* Скомпилированный класс для денормализации сущностей ФИАС в модели eloquent.
*/
class CompiledEntitesDenormalizer implements DenormalizerInterface
final class CompiledEntitesDenormalizer implements DenormalizerInterface
{
private const ALLOWED_ENTITIES = [
Apartments::class,
AddrObjDivision::class,
NormativeDocsTypes::class,
RoomTypes::class,
ObjectLevels::class,
NormativeDocsKinds::class,
Rooms::class,
ApartmentTypes::class,
AddrObjTypes::class,
Steads::class,
NormativeDocs::class,
OperationTypes::class,
Houses::class,
AdmHierarchy::class,
Carplaces::class,
ChangeHistory::class,
AddrObj::class,
ParamTypes::class,
Param::class,
ReestrObjects::class,
HouseTypes::class,
MunHierarchy::class,
FiasVersion::class,
Apartments::class => true,
AddrObjDivision::class => true,
NormativeDocsTypes::class => true,
RoomTypes::class => true,
ObjectLevels::class => true,
NormativeDocsKinds::class => true,
Rooms::class => true,
ApartmentTypes::class => true,
AddrObjTypes::class => true,
Steads::class => true,
NormativeDocs::class => true,
OperationTypes::class => true,
Houses::class => true,
AdmHierarchy::class => true,
Carplaces::class => true,
ChangeHistory::class => true,
AddrObj::class => true,
ParamTypes::class => true,
Param::class => true,
ReestrObjects::class => true,
HouseTypes::class => true,
MunHierarchy::class => true,
FiasVersion::class => true,
];

/**
* {@inheritDoc}
*/
public function supportsDenormalization($data, string $type, ?string $format = null)
{
return \in_array(trim($type, " \t\n\r\0\x0B\\/"), self::ALLOWED_ENTITIES);
return \array_key_exists(trim($type, " \t\n\r\0\x0B\\/"), self::ALLOWED_ENTITIES);
}

/**
Expand All @@ -84,8 +84,7 @@ public function denormalize($data, string $type, ?string $format = null, array $
$entity = $context[AbstractNormalizer::OBJECT_TO_POPULATE] ?? new $type();

if (!($entity instanceof Model)) {
$message = \sprintf("Bad class for populating entity, need '%s' instance.", Model::class);
throw new InvalidArgumentException($message);
throw new InvalidArgumentException("Bad class for populating entity, '" . Model::class . "' is required");
}

switch ($type) {
Expand Down Expand Up @@ -159,8 +158,7 @@ public function denormalize($data, string $type, ?string $format = null, array $
$extractedData = $this->modelFiasVersionDataExtractor($data);
break;
default:
$message = \sprintf("Can't find data extractor for '%s' type.", $type);
throw new InvalidArgumentException($message);
throw new InvalidArgumentException("Can't find data extractor for '{$type}' type");
break;
}

Expand All @@ -174,31 +172,7 @@ public function denormalize($data, string $type, ?string $format = null, array $
*/
public function getSupportedTypes(?string $format): array
{
return [
Apartments::class => true,
AddrObjDivision::class => true,
NormativeDocsTypes::class => true,
RoomTypes::class => true,
ObjectLevels::class => true,
NormativeDocsKinds::class => true,
Rooms::class => true,
ApartmentTypes::class => true,
AddrObjTypes::class => true,
Steads::class => true,
NormativeDocs::class => true,
OperationTypes::class => true,
Houses::class => true,
AdmHierarchy::class => true,
Carplaces::class => true,
ChangeHistory::class => true,
AddrObj::class => true,
ParamTypes::class => true,
Param::class => true,
ReestrObjects::class => true,
HouseTypes::class => true,
MunHierarchy::class => true,
FiasVersion::class => true,
];
return self::ALLOWED_ENTITIES;
}

/**
Expand Down

0 comments on commit 67d1b71

Please sign in to comment.