Skip to content

Commit 86ff731

Browse files
committed
PHPLIB-494: Fix validation of options with default values
1 parent fca04ae commit 86ff731

File tree

4 files changed

+13
-9
lines changed

4 files changed

+13
-9
lines changed

src/Client.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public function __construct($uri = 'mongodb://127.0.0.1/', array $uriOptions = [
9595
{
9696
$driverOptions += ['typeMap' => self::$defaultTypeMap];
9797

98-
if (isset($driverOptions['typeMap']) && ! is_array($driverOptions['typeMap'])) {
98+
if (! is_array($driverOptions['typeMap'])) {
9999
throw InvalidArgumentException::invalidType('"typeMap" driver option', $driverOptions['typeMap'], 'array');
100100
}
101101

src/GridFS/Bucket.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,19 +143,19 @@ public function __construct(Manager $manager, $databaseName, array $options = []
143143
'disableMD5' => false,
144144
];
145145

146-
if (isset($options['bucketName']) && ! is_string($options['bucketName'])) {
146+
if (! is_string($options['bucketName'])) {
147147
throw InvalidArgumentException::invalidType('"bucketName" option', $options['bucketName'], 'string');
148148
}
149149

150-
if (isset($options['chunkSizeBytes']) && ! is_integer($options['chunkSizeBytes'])) {
150+
if (! is_integer($options['chunkSizeBytes'])) {
151151
throw InvalidArgumentException::invalidType('"chunkSizeBytes" option', $options['chunkSizeBytes'], 'integer');
152152
}
153153

154-
if (isset($options['chunkSizeBytes']) && $options['chunkSizeBytes'] < 1) {
154+
if ($options['chunkSizeBytes'] < 1) {
155155
throw new InvalidArgumentException(sprintf('Expected "chunkSizeBytes" option to be >= 1, %d given', $options['chunkSizeBytes']));
156156
}
157157

158-
if (isset($options['disableMD5']) && ! is_bool($options['disableMD5'])) {
158+
if (! is_bool($options['disableMD5'])) {
159159
throw InvalidArgumentException::invalidType('"disableMD5" option', $options['disableMD5'], 'boolean');
160160
}
161161

src/GridFS/WritableStream.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,15 +114,15 @@ public function __construct(CollectionWrapper $collectionWrapper, $filename, arr
114114
throw InvalidArgumentException::invalidType('"aliases" option', $options['aliases'], 'array of strings');
115115
}
116116

117-
if (isset($options['chunkSizeBytes']) && ! is_integer($options['chunkSizeBytes'])) {
117+
if (! is_integer($options['chunkSizeBytes'])) {
118118
throw InvalidArgumentException::invalidType('"chunkSizeBytes" option', $options['chunkSizeBytes'], 'integer');
119119
}
120120

121-
if (isset($options['chunkSizeBytes']) && $options['chunkSizeBytes'] < 1) {
121+
if ($options['chunkSizeBytes'] < 1) {
122122
throw new InvalidArgumentException(sprintf('Expected "chunkSizeBytes" option to be >= 1, %d given', $options['chunkSizeBytes']));
123123
}
124124

125-
if (isset($options['disableMD5']) && ! is_bool($options['disableMD5'])) {
125+
if (! is_bool($options['disableMD5'])) {
126126
throw InvalidArgumentException::invalidType('"disableMD5" option', $options['disableMD5'], 'boolean');
127127
}
128128

src/Operation/Watch.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,10 +178,14 @@ public function __construct(Manager $manager, $databaseName, $collectionName, ar
178178
'readPreference' => new ReadPreference(ReadPreference::RP_PRIMARY),
179179
];
180180

181-
if (isset($options['fullDocument']) && ! is_string($options['fullDocument'])) {
181+
if (! is_string($options['fullDocument'])) {
182182
throw InvalidArgumentException::invalidType('"fullDocument" option', $options['fullDocument'], 'string');
183183
}
184184

185+
if (! $options['readPreference'] instanceof ReadPreference) {
186+
throw InvalidArgumentException::invalidType('"readPreference" option', $options['readPreference'], ReadPreference::class);
187+
}
188+
185189
if (isset($options['resumeAfter']) && ! is_array($options['resumeAfter']) && ! is_object($options['resumeAfter'])) {
186190
throw InvalidArgumentException::invalidType('"resumeAfter" option', $options['resumeAfter'], 'array or object');
187191
}

0 commit comments

Comments
 (0)