"php": ">=5.3.3",
"psr/log": "1.0.0",
"wikimedia/cdb": "1.0.1",
+ "wikimedia/assert": "0.2.2",
"wikimedia/composer-merge-plugin": "1.0.0",
"wikimedia/utfnormal": "1.0.2",
"zordius/lightncandy": "0.18"
* @file
* @ingroup Cache
*/
+use Wikimedia\Assert\Assert;
/**
* Handles a simple LRU key/value map with a maximum number of entries
* @throws Exception When $maxCacheKeys is not an int or =< 0.
*/
public function __construct( $maxKeys ) {
- if ( !is_int( $maxKeys ) || $maxKeys < 1 ) {
- throw new Exception( __METHOD__ . " must be given an integer and >= 1" );
- }
+ Assert::parameterType( 'integer', $maxKeys, '$maxKeys' );
+ Assert::parameter( $maxKeys >= 1, '$maxKeys', 'must be >= 1' );
+
$this->maxCacheKeys = $maxKeys;
}
* @file
* @ingroup Cache
*/
+use Wikimedia\Assert\Assert;
/**
* Handles per process caching of items
* @throws UnexpectedValueException
*/
public function resize( $maxKeys ) {
- if ( !is_int( $maxKeys ) || $maxKeys < 1 ) {
- throw new UnexpectedValueException( __METHOD__ . " must be given an integer >= 1" );
- }
+ Assert::parameterType( 'integer', $maxKeys, '$maxKeys' );
+ Assert::parameter( $maxKeys >= 1, '$maxKeys', 'must be >= 1' );
+
$this->maxCacheKeys = $maxKeys;
while ( count( $this->cache ) > $this->maxCacheKeys ) {
reset( $this->cache );
* @license GPL 2+
* @author Daniel Kinzler
*/
+use Wikimedia\Assert\Assert;
/**
* Represents a page (or page fragment) title within %MediaWiki.
* @throws InvalidArgumentException
*/
public function __construct( $namespace, $dbkey, $fragment = '' ) {
- if ( !is_int( $namespace ) ) {
- throw new InvalidArgumentException( '$namespace must be an integer' );
- }
-
- if ( !is_string( $dbkey ) ) {
- throw new InvalidArgumentException( '$dbkey must be a string' );
- }
+ Assert::parameterType( 'integer', $namespace, '$namespace' );
+ Assert::parameterType( 'string', $dbkey, '$dbkey' );
+ Assert::parameterType( 'string', $fragment, '$fragment' );
// Sanity check, no full validation or normalization applied here!
- if ( preg_match( '/^_|[ \r\n\t]|_$/', $dbkey ) ) {
- throw new InvalidArgumentException( '$dbkey must be a valid DB key: ' . $dbkey );
- }
-
- if ( !is_string( $fragment ) ) {
- throw new InvalidArgumentException( '$fragment must be a string' );
- }
-
- if ( $dbkey === '' ) {
- throw new InvalidArgumentException( '$dbkey must not be empty' );
- }
+ Assert::parameter( !preg_match( '/^_|[ \r\n\t]|_$/', $dbkey ), '$dbkey', 'invalid DB key' );
+ Assert::parameter( $dbkey !== '', '$dbkey', 'should not be empty' );
$this->namespace = $namespace;
$this->dbkey = $dbkey;
* @file
* @author Aaron Schulz
*/
+use Wikimedia\Assert\Assert;
/**
* Class for getting statistically unique IDs
* @throws MWException
*/
public static function newTimestampedUID88( $base = 10 ) {
- if ( !is_integer( $base ) || $base > 36 || $base < 2 ) {
- throw new MWException( "Base must an integer be between 2 and 36" );
- }
+ Assert::parameterType( 'integer', $base, '$base' );
+ Assert::parameter( $base <= 36, '$base', 'must be <= 36' );
+ Assert::parameter( $base >= 2, '$base', 'must be >= 2' );
+
$gen = self::singleton();
$time = $gen->getTimestampAndDelay( 'lockFile88', 1, 1024 );
* @throws MWException
*/
public static function newTimestampedUID128( $base = 10 ) {
- if ( !is_integer( $base ) || $base > 36 || $base < 2 ) {
- throw new MWException( "Base must be an integer between 2 and 36" );
- }
+ Assert::parameterType( 'integer', $base, '$base' );
+ Assert::parameter( $base <= 36, '$base', 'must be <= 36' );
+ Assert::parameter( $base >= 2, '$base', 'must be >= 2' );
+
$gen = self::singleton();
$time = $gen->getTimestampAndDelay( 'lockFile128', 16384, 1048576 );
/**
* @dataProvider provideInvalidConstructorArg
- * @expectedException UnexpectedValueException
+ * @expectedException Wikimedia\Assert\ParameterAssertionException
* @covers ProcessCacheLRU::__construct
*/
public function testConstructorGivenInvalidValue( $maxSize ) {