From 6b4b74896fc010380cc59ca082e8e44539b2a2a8 Mon Sep 17 00:00:00 2001 From: Daniel Carbone Date: Thu, 16 Jan 2025 18:30:27 -0600 Subject: [PATCH] couple fixes, need to finish json unserialize for primitives --- src/Utilities/TypeHintUtils.php | 79 +++++-------------- template/core/client/class_client.php | 3 +- .../versions/types/methods/constructor.php | 2 +- .../serialization/json/unserialize/header.php | 2 +- 4 files changed, 25 insertions(+), 61 deletions(-) diff --git a/src/Utilities/TypeHintUtils.php b/src/Utilities/TypeHintUtils.php index 7ab57948..888106c0 100644 --- a/src/Utilities/TypeHintUtils.php +++ b/src/Utilities/TypeHintUtils.php @@ -30,18 +30,13 @@ class TypeHintUtils * @param \DCarbone\PHPFHIR\Version $version * @param \DCarbone\PHPFHIR\Enum\PrimitiveTypeEnum $primitiveType * @param bool $nullable - * @param bool $stringable * @return string */ public static function primitivePHPValueTypeHint(Version $version, PrimitiveTypeEnum $primitiveType, - bool $nullable, - bool $stringable = false): string + bool $nullable): string { $base = $primitiveType->getPHPReturnValueTypeHint(); - if ($stringable && !str_contains($base, 'string')) { - $base = "string|{$base}"; - } return $nullable ? "null|{$base}" : $base; } @@ -85,33 +80,6 @@ public static function primitivePHPValueTypeSetterDoc(Version $version return implode('|', $hintTypes); } - /** - * @param \DCarbone\PHPFHIR\Version $version - * @param \DCarbone\PHPFHIR\Version\Definition\Type $type - * @param bool $nullable - * @return string - */ - public static function typeHint(Version $version, Type $type, bool $nullable): string - { - $tk = $type->getKind(); - - // if this is an inline resource - if ($tk->isOneOf(TypeKindEnum::RESOURCE_INLINE, TypeKindEnum::RESOURCE_CONTAINER)) { - return sprintf( - '%s%s', - $nullable ? 'null|' : '', - PHPFHIR_VERSION_INTERFACE_VERSION_CONTAINED_TYPE - ); - } - - // if we land here, use the value type's class - return sprintf( - '%s%s', - $nullable ? 'null|' : ':', - $type->getClassName() - ); - } - /** * @param \DCarbone\PHPFHIR\Version $version * @param \DCarbone\PHPFHIR\Version\Definition\Type $type @@ -273,11 +241,10 @@ public static function buildSetterParameterDocHint(Version $version, $pt = $property->getValueFHIRType(); if (null === $pt) { - return self::primitivePHPValueTypeHint( + return self::primitivePHPValueTypeSetterDoc( version: $version, primitiveType: $property->getMemberOf()->getPrimitiveType(), nullable: $nullable, - stringable: true, ); } @@ -315,42 +282,38 @@ public static function buildSetterParameterDocHint(Version $version, * @param bool $nullable * @param bool $ignoreCollection * @return string + * @throws \Exception */ public static function buildSetterParameterHint(Version $version, Property $property, bool $nullable, bool $ignoreCollection = false): string { - $pt = $property->getValueFHIRType(); - - if (null === $pt) { - return self::primitivePHPValueTypeHint( - version: $version, - primitiveType: $property->getMemberOf()->getPrimitiveType(), - nullable: $nullable, - stringable: true, - ); - } - if (!$ignoreCollection && $property->isCollection()) { return $nullable ? 'null|iterable' : 'iterable'; } - $hintTypes = self::buildBaseHintParts($version, $pt, false); + $pt = $property->getValueFHIRType(); - $ptk = $pt->getKind(); + if (null === $pt) { + $hintTypes = $property->getMemberOf()->getPrimitiveType()->getPHPReceiveValueTypeHints(); + } else { + $hintTypes = self::buildBaseHintParts($version, $pt, false); - if ($property->isValueProperty() || $ptk->isOneOf(TypeKindEnum::LIST, TypeKindEnum::PRIMITIVE)) { - $hintTypes[] = $pt->getClassName(); - } + $ptk = $pt->getKind(); - if ($ptk === TypeKindEnum::PRIMITIVE_CONTAINER) { - $vp = $pt->getProperties()->getProperty(PHPFHIR_VALUE_PROPERTY_NAME); - array_push( - $hintTypes, - $vp->getValueFHIRType()->getClassName(), - $pt->getClassName(), - ); + if ($property->isValueProperty() || $ptk->isOneOf(TypeKindEnum::LIST, TypeKindEnum::PRIMITIVE)) { + $hintTypes[] = $pt->getClassName(); + } + + if ($ptk === TypeKindEnum::PRIMITIVE_CONTAINER) { + $vp = $pt->getProperties()->getProperty(PHPFHIR_VALUE_PROPERTY_NAME); + array_push( + $hintTypes, + $vp->getValueFHIRType()->getClassName(), + $pt->getClassName(), + ); + } } if ($nullable) { diff --git a/template/core/client/class_client.php b/template/core/client/class_client.php index 96e7e782..cbca3f28 100644 --- a/template/core/client/class_client.php +++ b/template/core/client/class_client.php @@ -114,7 +114,8 @@ public function exec( $request): + [CURLOPT_CUSTOMREQUEST => $request->method] + array_merge($this->_config->getCurlOpts(), $request->options ?? []); - $parseResponseHeaders = ($this->_config->getParseResponseHeaders() && (!isset($req->parseResponseHeaders) || $req->parseResponseHeaders)) + $parseResponseHeaders = ($this->_config->getParseResponseHeaders() + && (!isset($req->parseResponseHeaders) || $req->parseResponseHeaders)) || (isset($req->parseResponseHeaders) && $req->parseResponseHeaders); if ($parseResponseHeaders) { diff --git a/template/versions/types/methods/constructor.php b/template/versions/types/methods/constructor.php index 1500d807..2061e2c4 100644 --- a/template/versions/types/methods/constructor.php +++ b/template/versions/types/methods/constructor.php @@ -49,7 +49,7 @@ /** * Constructor - * @param $value + * @param $value * @param getFullyQualifiedName(true); ?> $xmlLocation */ public function __construct( $value = null, diff --git a/template/versions/types/serialization/json/unserialize/header.php b/template/versions/types/serialization/json/unserialize/header.php index 5fd8c593..f207591a 100644 --- a/template/versions/types/serialization/json/unserialize/header.php +++ b/template/versions/types/serialization/json/unserialize/header.php @@ -64,7 +64,7 @@ public static function jsonUnserialize(string|array|\stdClass $json, hasConcreteParent()) : ?> parent::jsonUnserialize($json, $type, $config);hasCommentContainerParent() && $type->isCommentContainer()) : ?> if (isset($data[::JSON_FIELD_FHIR_COMMENTS])) { - $this->_setFHIRComments((array)$data[::JSON_FIELD_FHIR_COMMENTS]); + $type->_setFHIRComments((array)$data[::JSON_FIELD_FHIR_COMMENTS]); }