Skip to content

Commit

Permalink
Merge branch '6.4' into 7.0
Browse files Browse the repository at this point in the history
* 6.4:
  fix typo
  Add types to private and internal properties
  [Workflow] Cleaning code
  [Scheduler] Fix NPE in debug:scheduler command
  • Loading branch information
nicolas-grekas committed Jul 25, 2023
2 parents 0d77261 + f6397b7 commit f49be6a
Showing 1 changed file with 9 additions and 34 deletions.
43 changes: 9 additions & 34 deletions AbstractBrowser.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,7 @@ public function getCookieJar(): CookieJar
*/
public function getCrawler(): Crawler
{
if (null === $this->crawler) {
throw new BadMethodCallException(sprintf('The "request()" method must be called before "%s()".', __METHOD__));
}

return $this->crawler;
return $this->crawler ?? throw new BadMethodCallException(sprintf('The "request()" method must be called before "%s()".', __METHOD__));
}

/**
Expand All @@ -216,11 +212,7 @@ public function useHtml5Parser(bool $useHtml5Parser): static
*/
public function getInternalResponse(): Response
{
if (null === $this->internalResponse) {
throw new BadMethodCallException(sprintf('The "request()" method must be called before "%s()".', __METHOD__));
}

return $this->internalResponse;
return $this->internalResponse ?? throw new BadMethodCallException(sprintf('The "request()" method must be called before "%s()".', __METHOD__));
}

/**
Expand All @@ -233,23 +225,15 @@ public function getInternalResponse(): Response
*/
public function getResponse(): object
{
if (null === $this->response) {
throw new BadMethodCallException(sprintf('The "request()" method must be called before "%s()".', __METHOD__));
}

return $this->response;
return $this->response ?? throw new BadMethodCallException(sprintf('The "request()" method must be called before "%s()".', __METHOD__));
}

/**
* Returns the current BrowserKit Request instance.
*/
public function getInternalRequest(): Request
{
if (null === $this->internalRequest) {
throw new BadMethodCallException(sprintf('The "request()" method must be called before "%s()".', __METHOD__));
}

return $this->internalRequest;
return $this->internalRequest ?? throw new BadMethodCallException(sprintf('The "request()" method must be called before "%s()".', __METHOD__));
}

/**
Expand All @@ -262,11 +246,7 @@ public function getInternalRequest(): Request
*/
public function getRequest(): object
{
if (null === $this->request) {
throw new BadMethodCallException(sprintf('The "request()" method must be called before "%s()".', __METHOD__));
}

return $this->request;
return $this->request ?? throw new BadMethodCallException(sprintf('The "request()" method must be called before "%s()".', __METHOD__));
}

/**
Expand All @@ -288,11 +268,9 @@ public function click(Link $link): Crawler
*/
public function clickLink(string $linkText): Crawler
{
if (null === $this->crawler) {
throw new BadMethodCallException(sprintf('The "request()" method must be called before "%s()".', __METHOD__));
}
$crawler = $this->crawler ?? throw new BadMethodCallException(sprintf('The "request()" method must be called before "%s()".', __METHOD__));

return $this->click($this->crawler->selectLink($linkText)->link());
return $this->click($crawler->selectLink($linkText)->link());
}

/**
Expand All @@ -319,11 +297,8 @@ public function submit(Form $form, array $values = [], array $serverParameters =
*/
public function submitForm(string $button, array $fieldValues = [], string $method = 'POST', array $serverParameters = []): Crawler
{
if (null === $this->crawler) {
throw new BadMethodCallException(sprintf('The "request()" method must be called before "%s()".', __METHOD__));
}

$buttonNode = $this->crawler->selectButton($button);
$crawler = $this->crawler ?? throw new BadMethodCallException(sprintf('The "request()" method must be called before "%s()".', __METHOD__));
$buttonNode = $crawler->selectButton($button);

if (0 === $buttonNode->count()) {
throw new InvalidArgumentException(sprintf('There is no button with "%s" as its content, id, value or name.', $button));
Expand Down

0 comments on commit f49be6a

Please sign in to comment.