Skip to content

Add return types - batch 4/n #42508

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 20 additions & 58 deletions src/Symfony/Component/BrowserKit/AbstractBrowser.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,8 @@ public function followMetaRefresh(bool $followMetaRefresh = true)

/**
* Returns whether client automatically follows redirects or not.
*
* @return bool
*/
public function isFollowingRedirects()
public function isFollowingRedirects(): bool
{
return $this->followRedirects;
}
Expand All @@ -94,10 +92,8 @@ public function setMaxRedirects(int $maxRedirects)

/**
* Returns the maximum number of redirects that crawler can follow.
*
* @return int
*/
public function getMaxRedirects()
public function getMaxRedirects(): int
{
return $this->maxRedirects;
}
Expand Down Expand Up @@ -136,10 +132,8 @@ public function setServerParameter(string $key, string $value)

/**
* Gets single server parameter for specified key.
*
* @return mixed
*/
public function getServerParameter(string $key, mixed $default = '')
public function getServerParameter(string $key, mixed $default = ''): mixed
{
return $this->server[$key] ?? $default;
}
Expand Down Expand Up @@ -175,30 +169,24 @@ public function jsonRequest(string $method, string $uri, array $parameters = [],

/**
* Returns the History instance.
*
* @return History
*/
public function getHistory()
public function getHistory(): History
{
return $this->history;
}

/**
* Returns the CookieJar instance.
*
* @return CookieJar
*/
public function getCookieJar()
public function getCookieJar(): CookieJar
{
return $this->cookieJar;
}

/**
* Returns the current Crawler instance.
*
* @return Crawler
*/
public function getCrawler()
public function getCrawler(): Crawler
{
if (null === $this->crawler) {
throw new BadMethodCallException(sprintf('The "request()" method must be called before "%s()".', __METHOD__));
Expand All @@ -209,10 +197,8 @@ public function getCrawler()

/**
* Returns the current BrowserKit Response instance.
*
* @return Response
*/
public function getInternalResponse()
public function getInternalResponse(): Response
{
if (null === $this->internalResponse) {
throw new BadMethodCallException(sprintf('The "request()" method must be called before "%s()".', __METHOD__));
Expand All @@ -227,11 +213,9 @@ public function getInternalResponse()
* The origin response is the response instance that is returned
* by the code that handles requests.
*
* @return object
*
* @see doRequest()
*/
public function getResponse()
public function getResponse(): object
{
if (null === $this->response) {
throw new BadMethodCallException(sprintf('The "request()" method must be called before "%s()".', __METHOD__));
Expand All @@ -242,10 +226,8 @@ public function getResponse()

/**
* Returns the current BrowserKit Request instance.
*
* @return Request
*/
public function getInternalRequest()
public function getInternalRequest(): Request
{
if (null === $this->internalRequest) {
throw new BadMethodCallException(sprintf('The "request()" method must be called before "%s()".', __METHOD__));
Expand All @@ -260,11 +242,9 @@ public function getInternalRequest()
* The origin request is the request instance that is sent
* to the code that handles requests.
*
* @return object
*
* @see doRequest()
*/
public function getRequest()
public function getRequest(): object
{
if (null === $this->request) {
throw new BadMethodCallException(sprintf('The "request()" method must be called before "%s()".', __METHOD__));
Expand All @@ -275,10 +255,8 @@ public function getRequest()

/**
* Clicks on a given link.
*
* @return Crawler
*/
public function click(Link $link)
public function click(Link $link): Crawler
{
if ($link instanceof Form) {
return $this->submit($link);
Expand Down Expand Up @@ -306,10 +284,8 @@ public function clickLink(string $linkText): Crawler
*
* @param array $values An array of form field values
* @param array $serverParameters An array of server parameters
*
* @return Crawler
*/
public function submit(Form $form, array $values = [], array $serverParameters = [])
public function submit(Form $form, array $values = [], array $serverParameters = []): Crawler
{
$form->setValues($values);

Expand Down Expand Up @@ -347,10 +323,8 @@ public function submitForm(string $button, array $fieldValues = [], string $meth
* @param array $server The server parameters (HTTP headers are referenced with an HTTP_ prefix as PHP does)
* @param string $content The raw body data
* @param bool $changeHistory Whether to update the history or not (only used internally for back(), forward(), and reload())
*
* @return Crawler
*/
public function request(string $method, string $uri, array $parameters = [], array $files = [], array $server = [], string $content = null, bool $changeHistory = true)
public function request(string $method, string $uri, array $parameters = [], array $files = [], array $server = [], string $content = null, bool $changeHistory = true): Crawler
{
if ($this->isMainRequest) {
$this->redirectCount = 0;
Expand Down Expand Up @@ -504,10 +478,8 @@ protected function filterResponse(object $response)
* Creates a crawler.
*
* This method returns null if the DomCrawler component is not available.
*
* @return Crawler|null
*/
protected function createCrawlerFromContent(string $uri, string $content, string $type)
protected function createCrawlerFromContent(string $uri, string $content, string $type): ?Crawler
{
if (!class_exists(Crawler::class)) {
return null;
Expand All @@ -521,10 +493,8 @@ protected function createCrawlerFromContent(string $uri, string $content, string

/**
* Goes back in the browser history.
*
* @return Crawler
*/
public function back()
public function back(): Crawler
{
do {
$request = $this->history->back();
Expand All @@ -535,10 +505,8 @@ public function back()

/**
* Goes forward in the browser history.
*
* @return Crawler
*/
public function forward()
public function forward(): Crawler
{
do {
$request = $this->history->forward();
Expand All @@ -549,22 +517,18 @@ public function forward()

/**
* Reloads the current browser.
*
* @return Crawler
*/
public function reload()
public function reload(): Crawler
{
return $this->requestFromRequest($this->history->current(), false);
}

/**
* Follow redirects?
*
* @return Crawler
*
* @throws \LogicException If request was not a redirect
*/
public function followRedirect()
public function followRedirect(): Crawler
{
if (empty($this->redirect)) {
throw new \LogicException('The request was not redirected.');
Expand Down Expand Up @@ -639,7 +603,7 @@ public function restart()
*
* @return string An absolute URI
*/
protected function getAbsoluteUri(string $uri)
protected function getAbsoluteUri(string $uri): string
{
// already absolute?
if (0 === strpos($uri, 'http://') || 0 === strpos($uri, 'https://')) {
Expand Down Expand Up @@ -682,10 +646,8 @@ protected function getAbsoluteUri(string $uri)
* Makes a request from a Request object directly.
*
* @param bool $changeHistory Whether to update the history or not (only used internally for back(), forward(), and reload())
*
* @return Crawler
*/
protected function requestFromRequest(Request $request, bool $changeHistory = true)
protected function requestFromRequest(Request $request, bool $changeHistory = true): Crawler
{
return $this->request($request->getMethod(), $request->getUri(), $request->getParameters(), $request->getFiles(), $request->getServer(), $request->getContent(), $changeHistory);
}
Expand Down
22 changes: 10 additions & 12 deletions src/Symfony/Component/BrowserKit/Cookie.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,9 @@ public function __toString(): string
/**
* Creates a Cookie instance from a Set-Cookie header value.
*
* @return static
*
* @throws \InvalidArgumentException
*/
public static function fromString(string $cookie, string $url = null)
public static function fromString(string $cookie, string $url = null): static
{
$parts = explode(';', $cookie);

Expand Down Expand Up @@ -222,7 +220,7 @@ private static function parseDate(string $dateValue): ?string
*
* @return string The cookie name
*/
public function getName()
public function getName(): string
{
return $this->name;
}
Expand All @@ -232,7 +230,7 @@ public function getName()
*
* @return string The cookie value
*/
public function getValue()
public function getValue(): string
{
return $this->value;
}
Expand All @@ -242,7 +240,7 @@ public function getValue()
*
* @return string The cookie value
*/
public function getRawValue()
public function getRawValue(): string
{
return $this->rawValue;
}
Expand All @@ -252,7 +250,7 @@ public function getRawValue()
*
* @return string|null The cookie expires time
*/
public function getExpiresTime()
public function getExpiresTime(): ?string
{
return $this->expires;
}
Expand All @@ -262,7 +260,7 @@ public function getExpiresTime()
*
* @return string The cookie path
*/
public function getPath()
public function getPath(): string
{
return $this->path;
}
Expand All @@ -272,7 +270,7 @@ public function getPath()
*
* @return string The cookie domain
*/
public function getDomain()
public function getDomain(): string
{
return $this->domain;
}
Expand All @@ -282,7 +280,7 @@ public function getDomain()
*
* @return bool The cookie secure flag
*/
public function isSecure()
public function isSecure(): bool
{
return $this->secure;
}
Expand All @@ -292,7 +290,7 @@ public function isSecure()
*
* @return bool The cookie httponly flag
*/
public function isHttpOnly()
public function isHttpOnly(): bool
{
return $this->httponly;
}
Expand All @@ -302,7 +300,7 @@ public function isHttpOnly()
*
* @return bool true if the cookie has expired, false otherwise
*/
public function isExpired()
public function isExpired(): bool
{
return null !== $this->expires && 0 != $this->expires && $this->expires <= time();
}
Expand Down
10 changes: 4 additions & 6 deletions src/Symfony/Component/BrowserKit/CookieJar.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,8 @@ public function set(Cookie $cookie)
* this method returns the first cookie for the given name/path
* (this behavior ensures a BC behavior with previous versions of
* Symfony).
*
* @return Cookie|null
*/
public function get(string $name, string $path = '/', string $domain = null)
public function get(string $name, string $path = '/', string $domain = null): ?Cookie
{
$this->flushExpiredCookies();

Expand Down Expand Up @@ -143,7 +141,7 @@ public function updateFromResponse(Response $response, string $uri = null)
*
* @return Cookie[] An array of cookies
*/
public function all()
public function all(): array
{
$this->flushExpiredCookies();

Expand All @@ -164,7 +162,7 @@ public function all()
*
* @return array An array of cookie values
*/
public function allValues(string $uri, bool $returnsRawValue = false)
public function allValues(string $uri, bool $returnsRawValue = false): array
{
$this->flushExpiredCookies();

Expand Down Expand Up @@ -201,7 +199,7 @@ public function allValues(string $uri, bool $returnsRawValue = false)
*
* @return array An array of cookie values
*/
public function allRawValues(string $uri)
public function allRawValues(string $uri): array
{
return $this->allValues($uri, true);
}
Expand Down
Loading