mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-05 09:39:56 +00:00
Attribute: Fix exception messages, make them less useless
This commit is contained in:
parent
ff2e982f22
commit
d2d65ce6cc
@ -127,8 +127,8 @@ class Attribute{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function setMinValue(float $minValue){
|
public function setMinValue(float $minValue){
|
||||||
if($minValue > $this->getMaxValue()){
|
if($minValue > ($max = $this->getMaxValue())){
|
||||||
throw new \InvalidArgumentException("Value $minValue is bigger than the maxValue!");
|
throw new \InvalidArgumentException("Minimum $minValue is greater than the maximum $max");
|
||||||
}
|
}
|
||||||
|
|
||||||
if($this->minValue != $minValue){
|
if($this->minValue != $minValue){
|
||||||
@ -143,8 +143,8 @@ class Attribute{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function setMaxValue(float $maxValue){
|
public function setMaxValue(float $maxValue){
|
||||||
if($maxValue < $this->getMinValue()){
|
if($maxValue < ($min = $this->getMinValue())){
|
||||||
throw new \InvalidArgumentException("Value $maxValue is bigger than the minValue!");
|
throw new \InvalidArgumentException("Maximum $maxValue is less than the minimum $min");
|
||||||
}
|
}
|
||||||
|
|
||||||
if($this->maxValue != $maxValue){
|
if($this->maxValue != $maxValue){
|
||||||
@ -160,7 +160,7 @@ class Attribute{
|
|||||||
|
|
||||||
public function setDefaultValue(float $defaultValue){
|
public function setDefaultValue(float $defaultValue){
|
||||||
if($defaultValue > $this->getMaxValue() or $defaultValue < $this->getMinValue()){
|
if($defaultValue > $this->getMaxValue() or $defaultValue < $this->getMinValue()){
|
||||||
throw new \InvalidArgumentException("Value $defaultValue exceeds the range!");
|
throw new \InvalidArgumentException("Default $defaultValue is outside the range " . $this->getMinValue() . " - " . $this->getMaxValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
if($this->defaultValue !== $defaultValue){
|
if($this->defaultValue !== $defaultValue){
|
||||||
@ -188,7 +188,7 @@ class Attribute{
|
|||||||
public function setValue(float $value, bool $fit = false, bool $forceSend = false){
|
public function setValue(float $value, bool $fit = false, bool $forceSend = false){
|
||||||
if($value > $this->getMaxValue() or $value < $this->getMinValue()){
|
if($value > $this->getMaxValue() or $value < $this->getMinValue()){
|
||||||
if(!$fit){
|
if(!$fit){
|
||||||
throw new \InvalidArgumentException("Value $value exceeds the range!");
|
throw new \InvalidArgumentException("Value $value is outside the range " . $this->getMinValue() . " - " . $this->getMaxValue());
|
||||||
}
|
}
|
||||||
$value = min(max($value, $this->getMinValue()), $this->getMaxValue());
|
$value = min(max($value, $this->getMinValue()), $this->getMaxValue());
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user