Skip to content

Commit

Permalink
Providing status codes (fixes #161)
Browse files Browse the repository at this point in the history
  • Loading branch information
spekulatius committed Dec 8, 2022
1 parent 3ca3445 commit 71ca998
Showing 1 changed file with 100 additions and 0 deletions.
100 changes: 100 additions & 0 deletions src/UsesGoutte.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,4 +133,104 @@ public function clickLink($titleOrUrl): self

return $this;
}

public function statusCode(): ?int
{
return $this->client?->getResponse()?->getStatusCode();
}

public function is2xx(): bool
{
return $this->statusCode() >= 200 && $this->statusCode() <= 299;
}

public function is3xx(): bool
{
return $this->statusCode() >= 300 && $this->statusCode() <= 399;
}

public function is4xx(): bool
{
return $this->statusCode() >= 400 && $this->statusCode() <= 499;
}

public function is5xx(): bool
{
return $this->statusCode() >= 500 && $this->statusCode() <= 599;
}

public function is200(): bool
{
return $this->statusCode() === 200;
}

public function is301(): bool
{
return $this->statusCode() === 301;
}

public function is302(): bool
{
return $this->statusCode() === 302;
}

public function is400(): bool
{
return $this->statusCode() === 400;
}

public function is401(): bool
{
return $this->statusCode() === 401;
}

public function is402(): bool
{
return $this->statusCode() === 402;
}

public function is403(): bool
{
return $this->statusCode() === 403;
}

public function is404(): bool
{
return $this->statusCode() === 404;
}

public function is500(): bool
{
return $this->statusCode() === 500;
}

public function isOk(): bool
{
return $this->is200();
}

public function isUnauthorized(): bool
{
return $this->is401();
}

public function isForbidden(): bool
{
return $this->is403();
}

public function isNotFound(): bool
{
return $this->is404();
}

public function isServerError(): bool
{
return $this->is500();
}

public function isInternalServerError(): bool
{
return $this->is500();
}
}

0 comments on commit 71ca998

Please sign in to comment.