Added INT32_MIN and INT32_MAX constants and an exception throw for out-of-range effect amplifiers

This commit is contained in:
Dylan K. Taylor 2017-06-14 19:34:32 +01:00
parent 1bf18ba8d2
commit 313fdb9e87
2 changed files with 8 additions and 2 deletions

View File

@ -22,6 +22,9 @@
declare(strict_types=1);
namespace {
const INT32_MIN = -0x80000000;
const INT32_MAX = 0x7fffffff;
function safe_var_dump(){
static $cnt = 0;
foreach(func_get_args() as $var){

View File

@ -174,7 +174,10 @@ class Effect{
*
* @return $this
*/
public function setDuration($ticks){
public function setDuration(int $ticks){
if($ticks < 0 or $ticks > INT32_MAX){
throw new \InvalidArgumentException("Effect duration must be in range of 0 - " . INT32_MAX);
}
$this->duration = $ticks;
return $this;
}
@ -248,7 +251,7 @@ class Effect{
* @return $this
*/
public function setAmplifier(int $amplifier){
$this->amplifier = $amplifier & 0xff;
$this->amplifier = ($amplifier & 0xff);
return $this;
}