Skip to content

Commit

Permalink
Merge pull request #135 from Aravind-MJ/aravind/set-for-collections
Browse files Browse the repository at this point in the history
FEAT: Set option for collection type fields as well
  • Loading branch information
dcarbone authored Aug 21, 2024
2 parents 19a4222 + ad7e182 commit 9112e10
Showing 1 changed file with 40 additions and 1 deletion.
41 changes: 40 additions & 1 deletion template/types/properties/methods/default.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,46 @@ public function <?php echo $property->getSetterName(); ?>(<?php echo TypeHintUti
$this-><?php echo $propertyName; ?><?php echo $isCollection ? '[]' : ''; ?> = $<?php echo $propertyName; ?>;
return $this;
}
<?php
<?php if ($isCollection) : ?>

/**<?php if ('' !== $documentation) : ?>

<?php echo $documentation; ?>
*<?php endif; ?>

* @param <?php echo $property->getValueFHIRType()->getFullyQualifiedClassName(true); ?>[] $<?php echo $propertyName; ?>

* @return static
*/
public function set<?php echo ucfirst($propertyName); ?>(array $<?php echo $propertyName; ?> = []): self
{
if ([] !== $this-><?php echo $propertyName; ?>) {
$this->_trackValuesRemoved(count($this-><?php echo $propertyName; ?>));
$this-><?php echo $propertyName; ?> = [];
}
if ([] === $<?php echo $propertyName; ?>) {
return $this;
}
foreach($<?php echo $propertyName; ?> as $v) {
if (is_object($v)) {
if ($v instanceof <?php echo $property->getValueFHIRType()->getClassName(); ?>) {
$this-><?php echo $property->getSetterName(); ?>($v);
} else {
throw new \InvalidArgumentException(sprintf(
'<?php echo $type->getClassName(); ?> - Field "<?php echo $propertyName; ?>" must be an array of objects implementing <?php echo $property->getValueFHIRType()->getClassName(); ?>, object of type %s seen',
get_class($v)
));
}
} else {
throw new \InvalidArgumentException(sprintf(
'<?php echo $type->getClassName(); ?> - Unable to set value for field "<?php echo $propertyName; ?>" from value: %s',
json_encode($v)
));
}
}
return $this;
}
<?php endif;
endif;
endforeach;

Expand Down

0 comments on commit 9112e10

Please sign in to comment.