Skip to content

Commit 43a54cd

Browse files
committed
Always access promoted options property in constructor
1 parent 2a77dfb commit 43a54cd

19 files changed

+303
-303
lines changed

psalm-baseline.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@
331331
</file>
332332
<file src="src/Operation/CreateEncryptedCollection.php">
333333
<MixedArgument>
334-
<code><![CDATA[$options['encryptedFields']]]></code>
334+
<code><![CDATA[$this->options['encryptedFields']]]></code>
335335
<code><![CDATA[$this->options['encryptedFields']]]></code>
336336
</MixedArgument>
337337
</file>

src/Operation/Aggregate.php

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -124,83 +124,83 @@ public function __construct(private string $databaseName, private ?string $colle
124124
throw new InvalidArgumentException('$pipeline is not a valid aggregation pipeline');
125125
}
126126

127-
if (isset($options['allowDiskUse']) && ! is_bool($options['allowDiskUse'])) {
128-
throw InvalidArgumentException::invalidType('"allowDiskUse" option', $options['allowDiskUse'], 'boolean');
127+
if (isset($this->options['allowDiskUse']) && ! is_bool($this->options['allowDiskUse'])) {
128+
throw InvalidArgumentException::invalidType('"allowDiskUse" option', $this->options['allowDiskUse'], 'boolean');
129129
}
130130

131-
if (isset($options['batchSize']) && ! is_integer($options['batchSize'])) {
132-
throw InvalidArgumentException::invalidType('"batchSize" option', $options['batchSize'], 'integer');
131+
if (isset($this->options['batchSize']) && ! is_integer($this->options['batchSize'])) {
132+
throw InvalidArgumentException::invalidType('"batchSize" option', $this->options['batchSize'], 'integer');
133133
}
134134

135-
if (isset($options['bypassDocumentValidation']) && ! is_bool($options['bypassDocumentValidation'])) {
136-
throw InvalidArgumentException::invalidType('"bypassDocumentValidation" option', $options['bypassDocumentValidation'], 'boolean');
135+
if (isset($this->options['bypassDocumentValidation']) && ! is_bool($this->options['bypassDocumentValidation'])) {
136+
throw InvalidArgumentException::invalidType('"bypassDocumentValidation" option', $this->options['bypassDocumentValidation'], 'boolean');
137137
}
138138

139-
if (isset($options['codec']) && ! $options['codec'] instanceof DocumentCodec) {
140-
throw InvalidArgumentException::invalidType('"codec" option', $options['codec'], DocumentCodec::class);
139+
if (isset($this->options['codec']) && ! $this->options['codec'] instanceof DocumentCodec) {
140+
throw InvalidArgumentException::invalidType('"codec" option', $this->options['codec'], DocumentCodec::class);
141141
}
142142

143-
if (isset($options['collation']) && ! is_document($options['collation'])) {
144-
throw InvalidArgumentException::expectedDocumentType('"collation" option', $options['collation']);
143+
if (isset($this->options['collation']) && ! is_document($this->options['collation'])) {
144+
throw InvalidArgumentException::expectedDocumentType('"collation" option', $this->options['collation']);
145145
}
146146

147-
if (isset($options['explain']) && ! is_bool($options['explain'])) {
148-
throw InvalidArgumentException::invalidType('"explain" option', $options['explain'], 'boolean');
147+
if (isset($this->options['explain']) && ! is_bool($this->options['explain'])) {
148+
throw InvalidArgumentException::invalidType('"explain" option', $this->options['explain'], 'boolean');
149149
}
150150

151-
if (isset($options['hint']) && ! is_string($options['hint']) && ! is_array($options['hint']) && ! is_object($options['hint'])) {
152-
throw InvalidArgumentException::invalidType('"hint" option', $options['hint'], 'string or array or object');
151+
if (isset($this->options['hint']) && ! is_string($this->options['hint']) && ! is_array($this->options['hint']) && ! is_object($this->options['hint'])) {
152+
throw InvalidArgumentException::invalidType('"hint" option', $this->options['hint'], 'string or array or object');
153153
}
154154

155-
if (isset($options['let']) && ! is_document($options['let'])) {
156-
throw InvalidArgumentException::expectedDocumentType('"let" option', $options['let']);
155+
if (isset($this->options['let']) && ! is_document($this->options['let'])) {
156+
throw InvalidArgumentException::expectedDocumentType('"let" option', $this->options['let']);
157157
}
158158

159-
if (isset($options['maxAwaitTimeMS']) && ! is_integer($options['maxAwaitTimeMS'])) {
160-
throw InvalidArgumentException::invalidType('"maxAwaitTimeMS" option', $options['maxAwaitTimeMS'], 'integer');
159+
if (isset($this->options['maxAwaitTimeMS']) && ! is_integer($this->options['maxAwaitTimeMS'])) {
160+
throw InvalidArgumentException::invalidType('"maxAwaitTimeMS" option', $this->options['maxAwaitTimeMS'], 'integer');
161161
}
162162

163-
if (isset($options['maxTimeMS']) && ! is_integer($options['maxTimeMS'])) {
164-
throw InvalidArgumentException::invalidType('"maxTimeMS" option', $options['maxTimeMS'], 'integer');
163+
if (isset($this->options['maxTimeMS']) && ! is_integer($this->options['maxTimeMS'])) {
164+
throw InvalidArgumentException::invalidType('"maxTimeMS" option', $this->options['maxTimeMS'], 'integer');
165165
}
166166

167-
if (isset($options['readConcern']) && ! $options['readConcern'] instanceof ReadConcern) {
168-
throw InvalidArgumentException::invalidType('"readConcern" option', $options['readConcern'], ReadConcern::class);
167+
if (isset($this->options['readConcern']) && ! $this->options['readConcern'] instanceof ReadConcern) {
168+
throw InvalidArgumentException::invalidType('"readConcern" option', $this->options['readConcern'], ReadConcern::class);
169169
}
170170

171-
if (isset($options['readPreference']) && ! $options['readPreference'] instanceof ReadPreference) {
172-
throw InvalidArgumentException::invalidType('"readPreference" option', $options['readPreference'], ReadPreference::class);
171+
if (isset($this->options['readPreference']) && ! $this->options['readPreference'] instanceof ReadPreference) {
172+
throw InvalidArgumentException::invalidType('"readPreference" option', $this->options['readPreference'], ReadPreference::class);
173173
}
174174

175-
if (isset($options['session']) && ! $options['session'] instanceof Session) {
176-
throw InvalidArgumentException::invalidType('"session" option', $options['session'], Session::class);
175+
if (isset($this->options['session']) && ! $this->options['session'] instanceof Session) {
176+
throw InvalidArgumentException::invalidType('"session" option', $this->options['session'], Session::class);
177177
}
178178

179-
if (isset($options['typeMap']) && ! is_array($options['typeMap'])) {
180-
throw InvalidArgumentException::invalidType('"typeMap" option', $options['typeMap'], 'array');
179+
if (isset($this->options['typeMap']) && ! is_array($this->options['typeMap'])) {
180+
throw InvalidArgumentException::invalidType('"typeMap" option', $this->options['typeMap'], 'array');
181181
}
182182

183-
if (isset($options['writeConcern']) && ! $options['writeConcern'] instanceof WriteConcern) {
184-
throw InvalidArgumentException::invalidType('"writeConcern" option', $options['writeConcern'], WriteConcern::class);
183+
if (isset($this->options['writeConcern']) && ! $this->options['writeConcern'] instanceof WriteConcern) {
184+
throw InvalidArgumentException::invalidType('"writeConcern" option', $this->options['writeConcern'], WriteConcern::class);
185185
}
186186

187-
if (isset($options['bypassDocumentValidation']) && ! $options['bypassDocumentValidation']) {
187+
if (isset($this->options['bypassDocumentValidation']) && ! $this->options['bypassDocumentValidation']) {
188188
unset($this->options['bypassDocumentValidation']);
189189
}
190190

191-
if (isset($options['readConcern']) && $options['readConcern']->isDefault()) {
191+
if (isset($this->options['readConcern']) && $this->options['readConcern']->isDefault()) {
192192
unset($this->options['readConcern']);
193193
}
194194

195-
if (isset($options['writeConcern']) && $options['writeConcern']->isDefault()) {
195+
if (isset($this->options['writeConcern']) && $this->options['writeConcern']->isDefault()) {
196196
unset($this->options['writeConcern']);
197197
}
198198

199-
if (isset($options['codec']) && isset($options['typeMap'])) {
199+
if (isset($this->options['codec']) && isset($this->options['typeMap'])) {
200200
throw InvalidArgumentException::cannotCombineCodecAndTypeMap();
201201
}
202202

203-
$this->isWrite = is_last_pipeline_operator_write($pipeline) && ! ($options['explain'] ?? false);
203+
$this->isWrite = is_last_pipeline_operator_write($pipeline) && ! ($this->options['explain'] ?? false);
204204

205205
if ($this->isWrite) {
206206
/* Ignore batchSize for writes, since no documents are returned and

src/Operation/Count.php

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -84,39 +84,39 @@ public function __construct(private string $databaseName, private string $collec
8484
throw InvalidArgumentException::expectedDocumentType('$filter', $filter);
8585
}
8686

87-
if (isset($options['collation']) && ! is_document($options['collation'])) {
88-
throw InvalidArgumentException::expectedDocumentType('"collation" option', $options['collation']);
87+
if (isset($this->options['collation']) && ! is_document($this->options['collation'])) {
88+
throw InvalidArgumentException::expectedDocumentType('"collation" option', $this->options['collation']);
8989
}
9090

91-
if (isset($options['hint']) && ! is_string($options['hint']) && ! is_array($options['hint']) && ! is_object($options['hint'])) {
92-
throw InvalidArgumentException::invalidType('"hint" option', $options['hint'], 'string or array or object');
91+
if (isset($this->options['hint']) && ! is_string($this->options['hint']) && ! is_array($this->options['hint']) && ! is_object($this->options['hint'])) {
92+
throw InvalidArgumentException::invalidType('"hint" option', $this->options['hint'], 'string or array or object');
9393
}
9494

95-
if (isset($options['limit']) && ! is_integer($options['limit'])) {
96-
throw InvalidArgumentException::invalidType('"limit" option', $options['limit'], 'integer');
95+
if (isset($this->options['limit']) && ! is_integer($this->options['limit'])) {
96+
throw InvalidArgumentException::invalidType('"limit" option', $this->options['limit'], 'integer');
9797
}
9898

99-
if (isset($options['maxTimeMS']) && ! is_integer($options['maxTimeMS'])) {
100-
throw InvalidArgumentException::invalidType('"maxTimeMS" option', $options['maxTimeMS'], 'integer');
99+
if (isset($this->options['maxTimeMS']) && ! is_integer($this->options['maxTimeMS'])) {
100+
throw InvalidArgumentException::invalidType('"maxTimeMS" option', $this->options['maxTimeMS'], 'integer');
101101
}
102102

103-
if (isset($options['readConcern']) && ! $options['readConcern'] instanceof ReadConcern) {
104-
throw InvalidArgumentException::invalidType('"readConcern" option', $options['readConcern'], ReadConcern::class);
103+
if (isset($this->options['readConcern']) && ! $this->options['readConcern'] instanceof ReadConcern) {
104+
throw InvalidArgumentException::invalidType('"readConcern" option', $this->options['readConcern'], ReadConcern::class);
105105
}
106106

107-
if (isset($options['readPreference']) && ! $options['readPreference'] instanceof ReadPreference) {
108-
throw InvalidArgumentException::invalidType('"readPreference" option', $options['readPreference'], ReadPreference::class);
107+
if (isset($this->options['readPreference']) && ! $this->options['readPreference'] instanceof ReadPreference) {
108+
throw InvalidArgumentException::invalidType('"readPreference" option', $this->options['readPreference'], ReadPreference::class);
109109
}
110110

111-
if (isset($options['session']) && ! $options['session'] instanceof Session) {
112-
throw InvalidArgumentException::invalidType('"session" option', $options['session'], Session::class);
111+
if (isset($this->options['session']) && ! $this->options['session'] instanceof Session) {
112+
throw InvalidArgumentException::invalidType('"session" option', $this->options['session'], Session::class);
113113
}
114114

115-
if (isset($options['skip']) && ! is_integer($options['skip'])) {
116-
throw InvalidArgumentException::invalidType('"skip" option', $options['skip'], 'integer');
115+
if (isset($this->options['skip']) && ! is_integer($this->options['skip'])) {
116+
throw InvalidArgumentException::invalidType('"skip" option', $this->options['skip'], 'integer');
117117
}
118118

119-
if (isset($options['readConcern']) && $options['readConcern']->isDefault()) {
119+
if (isset($this->options['readConcern']) && $this->options['readConcern']->isDefault()) {
120120
unset($this->options['readConcern']);
121121
}
122122
}

0 commit comments

Comments
 (0)