$maxValue || $defaultValue > $maxValue || $defaultValue < $minValue){ throw new \InvalidArgumentException("Invalid ranges: min value: $minValue, max value: $maxValue, $defaultValue: $defaultValue"); } $this->currentValue = $this->defaultValue; } public function getMinValue() : float{ return $this->minValue; } /** * @return $this */ public function setMinValue(float $minValue){ if($minValue > ($max = $this->getMaxValue())){ throw new \InvalidArgumentException("Minimum $minValue is greater than the maximum $max"); } if($this->minValue != $minValue){ $this->desynchronized = true; $this->minValue = $minValue; } return $this; } public function getMaxValue() : float{ return $this->maxValue; } /** * @return $this */ public function setMaxValue(float $maxValue){ if($maxValue < ($min = $this->getMinValue())){ throw new \InvalidArgumentException("Maximum $maxValue is less than the minimum $min"); } if($this->maxValue != $maxValue){ $this->desynchronized = true; $this->maxValue = $maxValue; } return $this; } public function getDefaultValue() : float{ return $this->defaultValue; } /** * @return $this */ public function setDefaultValue(float $defaultValue){ if($defaultValue > $this->getMaxValue() || $defaultValue < $this->getMinValue()){ throw new \InvalidArgumentException("Default $defaultValue is outside the range " . $this->getMinValue() . " - " . $this->getMaxValue()); } if($this->defaultValue !== $defaultValue){ $this->desynchronized = true; $this->defaultValue = $defaultValue; } return $this; } public function resetToDefault() : void{ $this->setValue($this->getDefaultValue(), true); } public function getValue() : float{ return $this->currentValue; } /** * @return $this */ public function setValue(float $value, bool $fit = false, bool $forceSend = false){ if($value > $this->getMaxValue() || $value < $this->getMinValue()){ if(!$fit){ throw new \InvalidArgumentException("Value $value is outside the range " . $this->getMinValue() . " - " . $this->getMaxValue()); } $value = min(max($value, $this->getMinValue()), $this->getMaxValue()); } if($this->currentValue != $value){ $this->desynchronized = true; $this->currentValue = $value; }elseif($forceSend){ $this->desynchronized = true; } return $this; } public function getId() : string{ return $this->id; } public function isSyncable() : bool{ return $this->shouldSend; } public function isDesynchronized() : bool{ return $this->shouldSend && $this->desynchronized; } public function markSynchronized(bool $synced = true) : void{ $this->desynchronized = !$synced; } }