@@ -204,11 +204,7 @@ public function getCookieJar(): CookieJar
204204 */
205205 public function getCrawler (): Crawler
206206 {
207- if (null === $ this ->crawler ) {
208- throw new BadMethodCallException (sprintf ('The "request()" method must be called before "%s()". ' , __METHOD__ ));
209- }
210-
211- return $ this ->crawler ;
207+ return $ this ->crawler ?? throw new BadMethodCallException (sprintf ('The "request()" method must be called before "%s()". ' , __METHOD__ ));
212208 }
213209
214210 /**
@@ -228,11 +224,7 @@ public function useHtml5Parser(bool $useHtml5Parser): static
228224 */
229225 public function getInternalResponse (): Response
230226 {
231- if (null === $ this ->internalResponse ) {
232- throw new BadMethodCallException (sprintf ('The "request()" method must be called before "%s()". ' , __METHOD__ ));
233- }
234-
235- return $ this ->internalResponse ;
227+ return $ this ->internalResponse ?? throw new BadMethodCallException (sprintf ('The "request()" method must be called before "%s()". ' , __METHOD__ ));
236228 }
237229
238230 /**
@@ -245,23 +237,15 @@ public function getInternalResponse(): Response
245237 */
246238 public function getResponse (): object
247239 {
248- if (null === $ this ->response ) {
249- throw new BadMethodCallException (sprintf ('The "request()" method must be called before "%s()". ' , __METHOD__ ));
250- }
251-
252- return $ this ->response ;
240+ return $ this ->response ?? throw new BadMethodCallException (sprintf ('The "request()" method must be called before "%s()". ' , __METHOD__ ));
253241 }
254242
255243 /**
256244 * Returns the current BrowserKit Request instance.
257245 */
258246 public function getInternalRequest (): Request
259247 {
260- if (null === $ this ->internalRequest ) {
261- throw new BadMethodCallException (sprintf ('The "request()" method must be called before "%s()". ' , __METHOD__ ));
262- }
263-
264- return $ this ->internalRequest ;
248+ return $ this ->internalRequest ?? throw new BadMethodCallException (sprintf ('The "request()" method must be called before "%s()". ' , __METHOD__ ));
265249 }
266250
267251 /**
@@ -274,11 +258,7 @@ public function getInternalRequest(): Request
274258 */
275259 public function getRequest (): object
276260 {
277- if (null === $ this ->request ) {
278- throw new BadMethodCallException (sprintf ('The "request()" method must be called before "%s()". ' , __METHOD__ ));
279- }
280-
281- return $ this ->request ;
261+ return $ this ->request ?? throw new BadMethodCallException (sprintf ('The "request()" method must be called before "%s()". ' , __METHOD__ ));
282262 }
283263
284264 /**
@@ -300,11 +280,9 @@ public function click(Link $link): Crawler
300280 */
301281 public function clickLink (string $ linkText ): Crawler
302282 {
303- if (null === $ this ->crawler ) {
304- throw new BadMethodCallException (sprintf ('The "request()" method must be called before "%s()". ' , __METHOD__ ));
305- }
283+ $ crawler = $ this ->crawler ?? throw new BadMethodCallException (sprintf ('The "request()" method must be called before "%s()". ' , __METHOD__ ));
306284
307- return $ this ->click ($ this -> crawler ->selectLink ($ linkText )->link ());
285+ return $ this ->click ($ crawler ->selectLink ($ linkText )->link ());
308286 }
309287
310288 /**
@@ -331,11 +309,8 @@ public function submit(Form $form, array $values = [], array $serverParameters =
331309 */
332310 public function submitForm (string $ button , array $ fieldValues = [], string $ method = 'POST ' , array $ serverParameters = []): Crawler
333311 {
334- if (null === $ this ->crawler ) {
335- throw new BadMethodCallException (sprintf ('The "request()" method must be called before "%s()". ' , __METHOD__ ));
336- }
337-
338- $ buttonNode = $ this ->crawler ->selectButton ($ button );
312+ $ crawler = $ this ->crawler ?? throw new BadMethodCallException (sprintf ('The "request()" method must be called before "%s()". ' , __METHOD__ ));
313+ $ buttonNode = $ crawler ->selectButton ($ button );
339314
340315 if (0 === $ buttonNode ->count ()) {
341316 throw new InvalidArgumentException (sprintf ('There is no button with "%s" as its content, id, value or name. ' , $ button ));
0 commit comments