Files
trueskill/src/Guard.php

35 lines
858 B
PHP
Raw Normal View History

2022-07-05 15:55:47 +02:00
<?php
namespace DNW\Skills;
use Exception;
/**
* Verifies argument contracts.
*
* @see http://www.moserware.com/2008/01/borrowing-ideas-from-3-interesting.html
*/
class Guard
{
public static function argumentNotNull($value, $parameterName)
{
if ($value == null) {
2022-07-05 15:55:47 +02:00
throw new Exception($parameterName.' can not be null');
}
}
public static function argumentIsValidIndex($index, $count, $parameterName)
{
if (($index < 0) || ($index >= $count)) {
2022-07-05 15:55:47 +02:00
throw new Exception($parameterName.' is an invalid index');
}
}
public static function argumentInRangeInclusive($value, $min, $max, $parameterName)
{
if (($value < $min) || ($value > $max)) {
2022-07-05 15:55:47 +02:00
throw new Exception($parameterName.' is not in the valid range ['.$min.', '.$max.']');
}
}
2022-07-05 15:55:47 +02:00
}