From 86865466ac71b003e7742c04aa367c3fa5829627 Mon Sep 17 00:00:00 2001 From: Daniel Carbone Date: Thu, 30 Jan 2025 20:55:16 -0600 Subject: [PATCH] allowing more values to be set as non-fhir objects --- src/Utilities/ImportUtils.php | 6 +++--- src/Utilities/TypeHintUtils.php | 19 +++++++++++-------- .../types/properties/methods/default.php | 2 +- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/Utilities/ImportUtils.php b/src/Utilities/ImportUtils.php index a41135f4..c7cc3d61 100644 --- a/src/Utilities/ImportUtils.php +++ b/src/Utilities/ImportUtils.php @@ -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() ); } diff --git a/src/Utilities/TypeHintUtils.php b/src/Utilities/TypeHintUtils.php index 05d65fce..ec2bd25b 100644 --- a/src/Utilities/TypeHintUtils.php +++ b/src/Utilities/TypeHintUtils.php @@ -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( @@ -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(); @@ -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); } @@ -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(); } } diff --git a/template/versions/types/properties/methods/default.php b/template/versions/types/properties/methods/default.php index 0bd9a1f4..76bca50d 100644 --- a/template/versions/types/properties/methods/default.php +++ b/template/versions/types/properties/methods/default.php @@ -120,7 +120,7 @@ public function getSetterName(); ?>(isPrimitiveContainer() || $propType->isPrimitiveOrListType()) : ?> + if ($propType->isValueContainer() || $propType->hasValueContainerParent() || $propType->isPrimitiveOrListType() || $propType->hasPrimitiveOrListParent()) : ?> if (!($ instanceof )) { $ = new (value: $); }