Skip to content

Commit

Permalink
better handling of list values
Browse files Browse the repository at this point in the history
  • Loading branch information
dcarbone committed Apr 15, 2024
1 parent 26aa118 commit 6b93793
Show file tree
Hide file tree
Showing 13 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/Definition/TypeDecorationValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public static function validateDecoration(VersionConfig $config, Types $types):
}
}

if ($typeKind === TypeKind::_LIST) {
if ($typeKind === TypeKind::LIST) {
$rbType = $type->getRestrictionBaseFHIRType();
if (null === $rbType) {
throw ExceptionUtils::createUndefinedListRestrictionBaseException($type);
Expand Down
4 changes: 2 additions & 2 deletions src/Definition/TypeDecorator.php
Original file line number Diff line number Diff line change
Expand Up @@ -307,8 +307,8 @@ private static function determineParsedTypeKind(VersionConfig $config, Types $ty
// check if type is list...
if (str_contains($fhirName, PHPFHIR_LIST_SUFFIX)) {
// for all intents and purposes, a List type is a multiple choice primitive type
$logger->debug(sprintf('Type "%s" has list suffix, setting kind to "%s"', $type->getFHIRName(), TypeKind::_LIST->value));
self::setTypeKind($config, $types, $type, TypeKind::_LIST);
$logger->debug(sprintf('Type "%s" has list suffix, setting kind to "%s"', $type->getFHIRName(), TypeKind::LIST->value));
self::setTypeKind($config, $types, $type, TypeKind::LIST);
return;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Definition/TypePropertyDecorator.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public static function findPropertyType(VersionConfig $config, Types $types, Typ
return;
}

if ($typeKind === TypeKind::_LIST) {
if ($typeKind === TypeKind::LIST) {
$parentPHPValueType = $type->getParentType()->getPrimitiveType()->getPHPValueType();
$log->debug(sprintf('Type "%s" is list, setting property "%s" raw PHP value type to "%s"', $type->getFHIRName(), $property->getName(), $parentPHPValueType));
$property->setRawPHPValue($parentPHPValueType);
Expand Down
2 changes: 1 addition & 1 deletion src/Definition/Types.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class Types implements Countable
private const _CONTAINED_IGNORED_TYPES = [
TypeKind::RESOURCE_INLINE,
TypeKind::RESOURCE_CONTAINER,
TypeKind::_LIST,
TypeKind::LIST,
TypeKind::PRIMITIVE,
TypeKind::PRIMITIVE_CONTAINER,
];
Expand Down
2 changes: 1 addition & 1 deletion src/Enum/TypeKind.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ enum TypeKind: string
case PRIMITIVE_CONTAINER = 'primitive_container';

// primitive type with limited possible value set
case _LIST = 'list';
case LIST = 'list';

// complex types
case EXTENSION = 'Extension';
Expand Down
4 changes: 2 additions & 2 deletions src/Utilities/TypeHintUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public static function typeSetterTypeHint(VersionConfig $config, Type $type): st
$pt->getClassName(),
$type->getClassName(),
);
} else if ($tk === TypeKind::PRIMITIVE) {
} else if ($tk->isOneOf(TypeKind::PRIMITIVE, TypeKind::LIST)) {
array_push(
$types,
$type->getprimitiveType()->getPHPValueTypeHint(),
Expand Down Expand Up @@ -258,7 +258,7 @@ public static function propertySetterTypeDoc(VersionConfig $config, Property $pr
self::typeTypeDoc($config, $ptp, false, $asCollection),
self::typeTypeDoc($config, $pt, false, $asCollection),
);
} else if ($tk === TypeKind::PRIMITIVE) {
} else if ($tk->isOneOf(TypeKind::PRIMITIVE, TypeKind::LIST)) {
array_push(
$types,
$pt->getPrimitiveType()->getPHPValueTypeHint(),
Expand Down
2 changes: 1 addition & 1 deletion template/types/class.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ public function __toString(): string
return '';
<?php else : ?>
return (string)$this->getValue();
<?php endif; elseif ($typeKind->isOneOf(TypeKind::_LIST, TypeKind::PRIMITIVE_CONTAINER)) : ?>
<?php endif; elseif ($typeKind->isOneOf(TypeKind::LIST, TypeKind::PRIMITIVE_CONTAINER)) : ?>
return (string)$this->getValue();
<?php else : ?>
return self::FHIR_TYPE_NAME;
Expand Down
2 changes: 1 addition & 1 deletion template/types/methods/constructor.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
ob_start();

echo match ($typeKind) {
TypeKind::PRIMITIVE, TypeKind::_LIST => require_with(PHPFHIR_TEMPLATE_TYPES_CONSTRUCTORS_DIR . DIRECTORY_SEPARATOR . 'primitive.php', $requireArgs),
TypeKind::PRIMITIVE, TypeKind::LIST => require_with(PHPFHIR_TEMPLATE_TYPES_CONSTRUCTORS_DIR . DIRECTORY_SEPARATOR . 'primitive.php', $requireArgs),
TypeKind::PRIMITIVE_CONTAINER => require_with(PHPFHIR_TEMPLATE_TYPES_CONSTRUCTORS_DIR . DIRECTORY_SEPARATOR . 'primitive_container.php', $requireArgs),
default => require_with(PHPFHIR_TEMPLATE_TYPES_CONSTRUCTORS_DIR . DIRECTORY_SEPARATOR . 'default.php', $requireArgs),
};
Expand Down
2 changes: 1 addition & 1 deletion template/types/properties/methods.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

ob_start();

if ($type->getKind()->isOneOf(TypeKind::PRIMITIVE, TypeKind::_LIST)) :
if ($type->getKind()->isOneOf(TypeKind::PRIMITIVE, TypeKind::LIST)) :
echo require_with(
PHPFHIR_TEMPLATE_TYPES_PROPERTIES_DIR . DIRECTORY_SEPARATOR . 'methods' . DIRECTORY_SEPARATOR . 'primitive.php',
[
Expand Down
4 changes: 2 additions & 2 deletions template/types/properties/methods/default.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
/** @var \DCarbone\PHPFHIR\Config\VersionConfig $config */
/** @var \DCarbone\PHPFHIR\Definition\Property[] $properties */

$isPrimitiveType = $type->getKind()->isOneOf(TypeKind::PRIMITIVE, TypeKind::_LIST);
$isPrimitiveType = $type->getKind()->isOneOf(TypeKind::PRIMITIVE, TypeKind::LIST);

ob_start();
foreach ($properties as $property) {
Expand Down Expand Up @@ -67,7 +67,7 @@

echo "\n";

if ($propertyTypeKind->isOneOf(TypeKind::PRIMITIVE, TypeKind::_LIST, TypeKind::PRIMITIVE_CONTAINER)) {
if ($propertyTypeKind->isOneOf(TypeKind::PRIMITIVE, TypeKind::LIST, TypeKind::PRIMITIVE_CONTAINER)) {
echo require_with(
__DIR__ . DIRECTORY_SEPARATOR . 'default' . DIRECTORY_SEPARATOR . 'setter_primitive.php',
$requireArgs
Expand Down
2 changes: 1 addition & 1 deletion template/types/serialization/json.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
$typeKind = $type->getKind();

ob_start();
if ($typeKind->isOneOf(TypeKind::PRIMITIVE, TypeKind::_LIST)) :
if ($typeKind->isOneOf(TypeKind::PRIMITIVE, TypeKind::LIST)) :
echo require_with(
PHPFHIR_TEMPLATE_TYPES_SERIALIZATION_DIR . DIRECTORY_SEPARATOR . 'json' . DIRECTORY_SEPARATOR . 'primitive.php',
[
Expand Down
2 changes: 1 addition & 1 deletion template/types/serialization/json/default.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function jsonSerialize(): \stdClass
continue;
endif;
$propertyType = $property->getValueFHIRType();
if ($propertyType->getKind()->isOneOf(TypeKind::PRIMITIVE, TypeKind::_LIST)) :
if ($propertyType->getKind()->isOneOf(TypeKind::PRIMITIVE, TypeKind::LIST)) :
echo require_with(
__DIR__ . DIRECTORY_SEPARATOR . 'default_property_primitive_list.php',
[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
$setter = $property->getSetterName();

ob_start();
if ($propertyType->getKind()->isOneOf(TypeKind::PRIMITIVE, TypeKind::_LIST, TypeKind::PRIMITIVE_CONTAINER)) : ?>
if ($propertyType->getKind()->isOneOf(TypeKind::PRIMITIVE, TypeKind::LIST, TypeKind::PRIMITIVE_CONTAINER)) : ?>
$n = $element->attributes->getNamedItem(self::<?php echo $propertyConst; ?>);
if (null !== $n) {
$pt = $type-><?php echo $property->getGetterName(); ?>();
Expand Down

0 comments on commit 6b93793

Please sign in to comment.