Skip to content

Commit 083b725

Browse files
committed
correcting nonsense with value container
1 parent 5d61658 commit 083b725

File tree

2 files changed

+12
-18
lines changed

2 files changed

+12
-18
lines changed

template/types/methods/constructors/default.php

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,37 +25,35 @@
2525
/** @var \DCarbone\PHPFHIR\Definition\Type|null $parentType */
2626

2727
$typeClassName = $type->getClassName();
28-
$constructorParamName = 'data';
2928
$valueProperty = null;
3029
if ($type->isValueContainer()) {
31-
$constructorParamName = 'value';
3230
$valueProperty = $type->getLocalProperties()->getProperty(PHPFHIR_VALUE_PROPERTY_NAME);
3331
}
3432

3533
ob_start(); ?>
3634
/**
3735
* <?php echo $typeClassName; ?> Constructor
38-
* @param null|array<?php if ($type->isValueContainer()) : ?>|<?php echo TypeHintUtils::propertySetterTypeHint($config, $valueProperty, false); endif; ?> $<?php echo $constructorParamName; ?>
36+
* @param null|array<?php if ($type->isValueContainer()) : ?>|<?php echo TypeHintUtils::propertySetterTypeHint($config, $valueProperty, false); endif; ?> $data
3937

4038
*/
41-
public function __construct(null|array<?php if ($type->isValueContainer()) : ?>|<?php echo TypeHintUtils::propertySetterTypeHint($config, $valueProperty, false); endif; ?> $<?php echo $constructorParamName; ?> = null)
39+
public function __construct(null|array<?php if ($type->isValueContainer()) : ?>|<?php echo TypeHintUtils::propertySetterTypeHint($config, $valueProperty, false); endif; ?> $data = null)
4240
{
43-
if (null === $<?php echo $constructorParamName; ?> || [] === $<?php echo $constructorParamName; ?>) {
41+
if (null === $data|| [] === $data) {
4442
return;
4543
}
4644
<?php if ($type->isValueContainer()) : ?>
47-
if (!is_array($<?php echo $constructorParamName; ?>)) {
48-
$this->setValue($<?php echo $constructorParamName; ?>);
45+
if (!is_array($data)) {
46+
$this->setValue($data);
4947
return;
5048
}
5149
<?php endif; if ($type->hasParentWithLocalProperties()) : // add parent constructor call ?>
52-
parent::__construct($<?php echo $constructorParamName; ?>);<?php endif; ?><?php if ($type->isCommentContainer() && !$type->hasCommentContainerParent()) : // only parse comments if parent isn't already doing it. ?>
50+
parent::__construct($data);<?php endif; ?><?php if ($type->isCommentContainer() && !$type->hasCommentContainerParent()) : // only parse comments if parent isn't already doing it. ?>
5351

54-
if (isset($<?php echo $constructorParamName; ?>[PHPFHIRConstants::JSON_FIELD_FHIR_COMMENTS])) {
55-
if (is_array($<?php echo $constructorParamName; ?>[PHPFHIRConstants::JSON_FIELD_FHIR_COMMENTS])) {
56-
$this->_setFHIRComments($<?php echo $constructorParamName; ?>[PHPFHIRConstants::JSON_FIELD_FHIR_COMMENTS]);
57-
} elseif (is_string($<?php echo $constructorParamName; ?>[PHPFHIRConstants::JSON_FIELD_FHIR_COMMENTS])) {
58-
$this->_addFHIRComment($<?php echo $constructorParamName; ?>[PHPFHIRConstants::JSON_FIELD_FHIR_COMMENTS]);
52+
if (isset($data[PHPFHIRConstants::JSON_FIELD_FHIR_COMMENTS])) {
53+
if (is_array($data[PHPFHIRConstants::JSON_FIELD_FHIR_COMMENTS])) {
54+
$this->_setFHIRComments($data[PHPFHIRConstants::JSON_FIELD_FHIR_COMMENTS]);
55+
} elseif (is_string($data[PHPFHIRConstants::JSON_FIELD_FHIR_COMMENTS])) {
56+
$this->_addFHIRComment($data[PHPFHIRConstants::JSON_FIELD_FHIR_COMMENTS]);
5957
}
6058
}<?php endif; ?>
6159

template/types/methods/constructors/primitive_container.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,9 @@ public function __construct(<?php echo TypeHintUtils::propertySetterTypeHint($co
4444
if (null === $data) {
4545
return;
4646
}
47-
if ($data instanceof <?php echo $typeImports->getImportByType($valuePropertyType); ?>) {
47+
if (is_scalar($data) || $data instanceof <?php echo $typeImports->getImportByType($valuePropertyType); ?>) {
4848
$this->setValue($data);
4949
return;
50-
}
51-
if (is_scalar($data)) {
52-
$this->setValue(new <?php echo $typeImports->getImportByType($valuePropertyType); ?>($data));
53-
return;
5450
}<?php if ($parentType) : ?>
5551

5652
parent::__construct($data);

0 commit comments

Comments
 (0)