@@ -192,11 +192,7 @@ public function getCookieJar(): CookieJar
192
192
*/
193
193
public function getCrawler (): Crawler
194
194
{
195
- if (null === $ this ->crawler ) {
196
- throw new BadMethodCallException (sprintf ('The "request()" method must be called before "%s()". ' , __METHOD__ ));
197
- }
198
-
199
- return $ this ->crawler ;
195
+ return $ this ->crawler ?? throw new BadMethodCallException (sprintf ('The "request()" method must be called before "%s()". ' , __METHOD__ ));
200
196
}
201
197
202
198
/**
@@ -216,11 +212,7 @@ public function useHtml5Parser(bool $useHtml5Parser): static
216
212
*/
217
213
public function getInternalResponse (): Response
218
214
{
219
- if (null === $ this ->internalResponse ) {
220
- throw new BadMethodCallException (sprintf ('The "request()" method must be called before "%s()". ' , __METHOD__ ));
221
- }
222
-
223
- return $ this ->internalResponse ;
215
+ return $ this ->internalResponse ?? throw new BadMethodCallException (sprintf ('The "request()" method must be called before "%s()". ' , __METHOD__ ));
224
216
}
225
217
226
218
/**
@@ -233,23 +225,15 @@ public function getInternalResponse(): Response
233
225
*/
234
226
public function getResponse (): object
235
227
{
236
- if (null === $ this ->response ) {
237
- throw new BadMethodCallException (sprintf ('The "request()" method must be called before "%s()". ' , __METHOD__ ));
238
- }
239
-
240
- return $ this ->response ;
228
+ return $ this ->response ?? throw new BadMethodCallException (sprintf ('The "request()" method must be called before "%s()". ' , __METHOD__ ));
241
229
}
242
230
243
231
/**
244
232
* Returns the current BrowserKit Request instance.
245
233
*/
246
234
public function getInternalRequest (): Request
247
235
{
248
- if (null === $ this ->internalRequest ) {
249
- throw new BadMethodCallException (sprintf ('The "request()" method must be called before "%s()". ' , __METHOD__ ));
250
- }
251
-
252
- return $ this ->internalRequest ;
236
+ return $ this ->internalRequest ?? throw new BadMethodCallException (sprintf ('The "request()" method must be called before "%s()". ' , __METHOD__ ));
253
237
}
254
238
255
239
/**
@@ -262,11 +246,7 @@ public function getInternalRequest(): Request
262
246
*/
263
247
public function getRequest (): object
264
248
{
265
- if (null === $ this ->request ) {
266
- throw new BadMethodCallException (sprintf ('The "request()" method must be called before "%s()". ' , __METHOD__ ));
267
- }
268
-
269
- return $ this ->request ;
249
+ return $ this ->request ?? throw new BadMethodCallException (sprintf ('The "request()" method must be called before "%s()". ' , __METHOD__ ));
270
250
}
271
251
272
252
/**
@@ -288,11 +268,9 @@ public function click(Link $link): Crawler
288
268
*/
289
269
public function clickLink (string $ linkText ): Crawler
290
270
{
291
- if (null === $ this ->crawler ) {
292
- throw new BadMethodCallException (sprintf ('The "request()" method must be called before "%s()". ' , __METHOD__ ));
293
- }
271
+ $ crawler = $ this ->crawler ?? throw new BadMethodCallException (sprintf ('The "request()" method must be called before "%s()". ' , __METHOD__ ));
294
272
295
- return $ this ->click ($ this -> crawler ->selectLink ($ linkText )->link ());
273
+ return $ this ->click ($ crawler ->selectLink ($ linkText )->link ());
296
274
}
297
275
298
276
/**
@@ -319,11 +297,8 @@ public function submit(Form $form, array $values = [], array $serverParameters =
319
297
*/
320
298
public function submitForm (string $ button , array $ fieldValues = [], string $ method = 'POST ' , array $ serverParameters = []): Crawler
321
299
{
322
- if (null === $ this ->crawler ) {
323
- throw new BadMethodCallException (sprintf ('The "request()" method must be called before "%s()". ' , __METHOD__ ));
324
- }
325
-
326
- $ buttonNode = $ this ->crawler ->selectButton ($ button );
300
+ $ crawler = $ this ->crawler ?? throw new BadMethodCallException (sprintf ('The "request()" method must be called before "%s()". ' , __METHOD__ ));
301
+ $ buttonNode = $ crawler ->selectButton ($ button );
327
302
328
303
if (0 === $ buttonNode ->count ()) {
329
304
throw new InvalidArgumentException (sprintf ('There is no button with "%s" as its content, id, value or name. ' , $ button ));
0 commit comments