Skip to content

Commit

Permalink
allowing more values to be set as non-fhir objects
Browse files Browse the repository at this point in the history
  • Loading branch information
dcarbone committed Jan 31, 2025
1 parent 6ed5f39 commit 8686546
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
6 changes: 3 additions & 3 deletions src/Utilities/ImportUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,12 +183,12 @@ public static function buildVersionTypeImports(Version $version, Type $type): vo
$imports->addVersionCoreFileImportsByName($type->getVersion(), PHPFHIR_VERSION_CLASSNAME_VERSION_TYPE_MAP);
$imports->addVersionCoreFileImportsByName($type->getVersion(), PHPFHIR_VERSION_CLASSNAME_VERSION);
} else {
if ($ptk === TypeKindEnum::PRIMITIVE_CONTAINER) {
$primType = $propertyType
if ($propertyType->isValueContainer() || $propertyType->hasValueContainerParent()) {
$valType = $propertyType
->getProperties()
->getProperty(PHPFHIR_VALUE_PROPERTY_NAME)->getValueFHIRType();
$imports->addImport(
$primType->getFullyQualifiedNamespace(false), $primType->getClassName()
$valType->getFullyQualifiedNamespace(false), $valType->getClassName()
);
}

Expand Down
19 changes: 11 additions & 8 deletions src/Utilities/TypeHintUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public static function typeSetterTypeHint(Version $version, Type $type, bool $nu

if ($tk->isResourceContainer($version)) {
$types[] = PHPFHIR_VERSION_INTERFACE_VERSION_CONTAINED_TYPE;
} else if ($tk === TypeKindEnum::PRIMITIVE_CONTAINER) {
} else if ($type->isPrimitiveContainer() || $type->hasPrimitiveContainerParent()) {
$pt = $type->getProperties()->getProperty('value')->getValueFHIRType();
$types = array_merge($types, $pt->getPrimitiveType()->getPHPReceiveValueTypeHints());
array_push(
Expand Down Expand Up @@ -124,11 +124,14 @@ public static function buildBaseHintParts(Version $version, Type $type, bool $fu
// fetch type's kind
$tk = $type->getKind();

if ($type->isPrimitiveOrListType()) {
if ($type->isPrimitiveOrListType() || $type->hasPrimitiveOrListParent()) {
$hintTypes = $type->getPrimitiveType()->getPHPReceiveValueTypeHints();
} else if ($type->isPrimitiveContainer()) {
} else if ($type->isValueContainer() || $type->hasValueContainerParent()) {
$ptp = $type->getProperties()->getProperty(PHPFHIR_VALUE_PROPERTY_NAME)->getValueFHIRType();
$hintTypes = $ptp->getPrimitiveType()->getPHPReceiveValueTypeHints();
$hintTypes = [];
if ($ptp->isPrimitiveOrListType() || $ptp->hasPrimitiveOrListParent()) {
$hintTypes = $ptp->getPrimitiveType()->getPHPReceiveValueTypeHints();
}
array_merge($hintTypes, self::buildBaseHintParts($version, $ptp, $fullyQualified));
} else if ($tk->isResourceContainer($version)) {
$containerType = $version->getDefinition()->getTypes()->getContainerType();
Expand Down Expand Up @@ -261,14 +264,14 @@ public static function buildSetterParameterDocHint(Version $version,
$hintTypes = self::buildBaseHintParts($version, $pt, true);


if ($pt->isPrimitiveContainer()) {
if ($pt->isValueContainer() || $pt->hasValueContainerParent()) {
$vp = $pt->getProperties()->getProperty(PHPFHIR_VALUE_PROPERTY_NAME);
array_push(
$hintTypes,
$vp->getValueFHIRType()->getFullyQualifiedClassName(true),
$pt->getFullyQualifiedClassName(true),
);
} else if ($property->isValueProperty() || $pt->isPrimitiveOrListType()) {
} else if ($property->isValueProperty() || ($pt->isPrimitiveOrListType() || $pt->hasPrimitiveOrListParent())) {
$hintTypes[] = $pt->getFullyQualifiedClassName(true);
}

Expand Down Expand Up @@ -307,14 +310,14 @@ public static function buildSetterParameterHint(Version $version,
} else {
$hintTypes = self::buildBaseHintParts($version, $pt, false);

if ($pt->isPrimitiveContainer()) {
if ($pt->isValueContainer() || $pt->hasValueContainerParent()) {
$vp = $pt->getProperties()->getProperty(PHPFHIR_VALUE_PROPERTY_NAME);
array_push(
$hintTypes,
$vp->getValueFHIRType()->getClassName(),
$pt->getClassName(),
);
} else if ($property->isValueProperty() || $pt->isPrimitiveOrListType()) {
} else if ($property->isValueProperty() || ($pt->isPrimitiveOrListType() || $pt->hasPrimitiveOrListParent())) {
$hintTypes[] = $pt->getClassName();
}
}
Expand Down
2 changes: 1 addition & 1 deletion template/versions/types/properties/methods/default.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public function <?php echo $property->getSetterName(); ?>(<?php echo TypeHintUti
}
<?php
endif;
if ($propType->isPrimitiveContainer() || $propType->isPrimitiveOrListType()) : ?>
if ($propType->isValueContainer() || $propType->hasValueContainerParent() || $propType->isPrimitiveOrListType() || $propType->hasPrimitiveOrListParent()) : ?>
if (!($<?php echo $propertyName; ?> instanceof <?php echo $propTypeClassname; ?>)) {
$<?php echo $propertyName; ?> = new <?php echo $propTypeClassname; ?>(value: $<?php echo $propertyName; ?>);
}
Expand Down

0 comments on commit 8686546

Please sign in to comment.