Skip to content

Commit

Permalink
Merge pull request #139 from dcarbone/dcarbone/efficient-setters
Browse files Browse the repository at this point in the history
more efficient collection setter implementation
  • Loading branch information
dcarbone authored Aug 22, 2024
2 parents 4fdbd46 + 63edb3b commit 5cb389c
Showing 1 changed file with 3 additions and 17 deletions.
20 changes: 3 additions & 17 deletions template/types/properties/methods/default.php
Original file line number Diff line number Diff line change
Expand Up @@ -204,11 +204,11 @@ public function <?php echo $property->getSetterName(); ?>(<?php echo TypeHintUti
<?php echo $documentation; ?>
*<?php endif; ?>

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

* @return static
*/
public function set<?php echo ucfirst($propertyName); ?>(array $<?php echo $propertyName; ?> = []): self
public function set<?php echo ucfirst($propertyName); ?>(<?php echo $property->getValueFHIRType()->getClassName(); ?> ...$<?php echo $propertyName; ?>): self
{
if ([] !== $this-><?php echo $propertyName; ?>) {
$this->_trackValuesRemoved(count($this-><?php echo $propertyName; ?>));
Expand All @@ -218,21 +218,7 @@ public function set<?php echo ucfirst($propertyName); ?>(array $<?php echo $prop
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)
));
}
$this-><?php echo $property->getSetterName(); ?>($v);
}
return $this;
}
Expand Down

0 comments on commit 5cb389c

Please sign in to comment.