PHPLIB-494: Fix validation of options with default values

parent fca04ae1
......@@ -95,7 +95,7 @@ class Client
{
$driverOptions += ['typeMap' => self::$defaultTypeMap];
if (isset($driverOptions['typeMap']) && ! is_array($driverOptions['typeMap'])) {
if (! is_array($driverOptions['typeMap'])) {
throw InvalidArgumentException::invalidType('"typeMap" driver option', $driverOptions['typeMap'], 'array');
}
......
......@@ -143,19 +143,19 @@ class Bucket
'disableMD5' => false,
];
if (isset($options['bucketName']) && ! is_string($options['bucketName'])) {
if (! is_string($options['bucketName'])) {
throw InvalidArgumentException::invalidType('"bucketName" option', $options['bucketName'], 'string');
}
if (isset($options['chunkSizeBytes']) && ! is_integer($options['chunkSizeBytes'])) {
if (! is_integer($options['chunkSizeBytes'])) {
throw InvalidArgumentException::invalidType('"chunkSizeBytes" option', $options['chunkSizeBytes'], 'integer');
}
if (isset($options['chunkSizeBytes']) && $options['chunkSizeBytes'] < 1) {
if ($options['chunkSizeBytes'] < 1) {
throw new InvalidArgumentException(sprintf('Expected "chunkSizeBytes" option to be >= 1, %d given', $options['chunkSizeBytes']));
}
if (isset($options['disableMD5']) && ! is_bool($options['disableMD5'])) {
if (! is_bool($options['disableMD5'])) {
throw InvalidArgumentException::invalidType('"disableMD5" option', $options['disableMD5'], 'boolean');
}
......
......@@ -114,15 +114,15 @@ class WritableStream
throw InvalidArgumentException::invalidType('"aliases" option', $options['aliases'], 'array of strings');
}
if (isset($options['chunkSizeBytes']) && ! is_integer($options['chunkSizeBytes'])) {
if (! is_integer($options['chunkSizeBytes'])) {
throw InvalidArgumentException::invalidType('"chunkSizeBytes" option', $options['chunkSizeBytes'], 'integer');
}
if (isset($options['chunkSizeBytes']) && $options['chunkSizeBytes'] < 1) {
if ($options['chunkSizeBytes'] < 1) {
throw new InvalidArgumentException(sprintf('Expected "chunkSizeBytes" option to be >= 1, %d given', $options['chunkSizeBytes']));
}
if (isset($options['disableMD5']) && ! is_bool($options['disableMD5'])) {
if (! is_bool($options['disableMD5'])) {
throw InvalidArgumentException::invalidType('"disableMD5" option', $options['disableMD5'], 'boolean');
}
......
......@@ -178,10 +178,14 @@ class Watch implements Executable, /* @internal */ CommandSubscriber
'readPreference' => new ReadPreference(ReadPreference::RP_PRIMARY),
];
if (isset($options['fullDocument']) && ! is_string($options['fullDocument'])) {
if (! is_string($options['fullDocument'])) {
throw InvalidArgumentException::invalidType('"fullDocument" option', $options['fullDocument'], 'string');
}
if (! $options['readPreference'] instanceof ReadPreference) {
throw InvalidArgumentException::invalidType('"readPreference" option', $options['readPreference'], ReadPreference::class);
}
if (isset($options['resumeAfter']) && ! is_array($options['resumeAfter']) && ! is_object($options['resumeAfter'])) {
throw InvalidArgumentException::invalidType('"resumeAfter" option', $options['resumeAfter'], 'array or object');
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment