From be0e4bd7810a332fa7c3402c5bd4aaf283d8b335 Mon Sep 17 00:00:00 2001 From: Amrouche Hamza Date: Sat, 29 Jun 2019 17:39:31 +0200 Subject: [PATCH] =?UTF-8?q?[BrowserKit]=C2=A0[5.0]=20Add=20type-hint=20to?= =?UTF-8?q?=20browserkit=20classes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Component/BrowserKit/AbstractBrowser.php | 34 ++++++------------- src/Symfony/Component/BrowserKit/Cookie.php | 5 +-- .../Component/BrowserKit/CookieJar.php | 23 +++---------- src/Symfony/Component/BrowserKit/Response.php | 5 +-- 4 files changed, 17 insertions(+), 50 deletions(-) diff --git a/src/Symfony/Component/BrowserKit/AbstractBrowser.php b/src/Symfony/Component/BrowserKit/AbstractBrowser.php index 5604fce6d2..8cf0770347 100644 --- a/src/Symfony/Component/BrowserKit/AbstractBrowser.php +++ b/src/Symfony/Component/BrowserKit/AbstractBrowser.php @@ -64,12 +64,10 @@ abstract class AbstractBrowser /** * Sets whether to automatically follow redirects or not. - * - * @param bool $followRedirect Whether to follow redirects */ - public function followRedirects($followRedirect = true) + public function followRedirects(bool $followRedirects = true) { - $this->followRedirects = (bool) $followRedirect; + $this->followRedirects = $followRedirects; } /** @@ -92,10 +90,8 @@ abstract class AbstractBrowser /** * Sets the maximum number of redirects that crawler can follow. - * - * @param int $maxRedirects */ - public function setMaxRedirects($maxRedirects) + public function setMaxRedirects(int $maxRedirects) { $this->maxRedirects = $maxRedirects < 0 ? -1 : $maxRedirects; $this->followRedirects = -1 != $this->maxRedirects; @@ -118,13 +114,13 @@ abstract class AbstractBrowser * * @throws \RuntimeException When Symfony Process Component is not installed */ - public function insulate($insulated = true) + public function insulate(bool $insulated = true) { if ($insulated && !class_exists('Symfony\\Component\\Process\\Process')) { throw new \LogicException('Unable to isolate requests as the Symfony Process Component is not installed.'); } - $this->insulated = (bool) $insulated; + $this->insulated = $insulated; } /** @@ -141,11 +137,8 @@ abstract class AbstractBrowser /** * Sets single server parameter. - * - * @param string $key A key of the parameter - * @param string $value A value of the parameter */ - public function setServerParameter($key, $value) + public function setServerParameter(string $key, string $value) { $this->server[$key] = $value; } @@ -153,12 +146,9 @@ abstract class AbstractBrowser /** * Gets single server parameter for specified key. * - * @param string $key A key of the parameter to get - * @param string $default A default value when key is undefined - * * @return string A value of the parameter */ - public function getServerParameter($key, $default = '') + public function getServerParameter(string $key, $default = '') { return isset($this->server[$key]) ? $this->server[$key] : $default; } @@ -416,7 +406,7 @@ abstract class AbstractBrowser return $this->crawler = $this->followRedirect(); } - $this->crawler = $this->createCrawlerFromContent($this->internalRequest->getUri(), $this->internalResponse->getContent(), $this->internalResponse->getHeader('Content-Type')); + $this->crawler = $this->createCrawlerFromContent($this->internalRequest->getUri(), $this->internalResponse->getContent(), $this->internalResponse->getHeader('Content-Type') ?? ''); // Check for meta refresh redirect if ($this->followMetaRefresh && null !== $redirect = $this->getMetaRefreshUrl()) { @@ -515,13 +505,9 @@ abstract class AbstractBrowser * * This method returns null if the DomCrawler component is not available. * - * @param string $uri A URI - * @param string $content Content for the crawler to use - * @param string $type Content type - * * @return Crawler|null */ - protected function createCrawlerFromContent($uri, $content, $type) + protected function createCrawlerFromContent(string $uri, string $content, string $type) { if (!class_exists('Symfony\Component\DomCrawler\Crawler')) { return; @@ -655,7 +641,7 @@ abstract class AbstractBrowser * * @return string An absolute URI */ - protected function getAbsoluteUri($uri) + protected function getAbsoluteUri(string $uri) { // already absolute? if (0 === strpos($uri, 'http://') || 0 === strpos($uri, 'https://')) { diff --git a/src/Symfony/Component/BrowserKit/Cookie.php b/src/Symfony/Component/BrowserKit/Cookie.php index ee786e69c2..a6c5abe8e2 100644 --- a/src/Symfony/Component/BrowserKit/Cookie.php +++ b/src/Symfony/Component/BrowserKit/Cookie.php @@ -119,14 +119,11 @@ class Cookie /** * Creates a Cookie instance from a Set-Cookie header value. * - * @param string $cookie A Set-Cookie header value - * @param string|null $url The base URL - * * @return static * * @throws \InvalidArgumentException */ - public static function fromString($cookie, $url = null) + public static function fromString(string $cookie, string $url = null) { $parts = explode(';', $cookie); diff --git a/src/Symfony/Component/BrowserKit/CookieJar.php b/src/Symfony/Component/BrowserKit/CookieJar.php index bce66197d3..2da42af38c 100644 --- a/src/Symfony/Component/BrowserKit/CookieJar.php +++ b/src/Symfony/Component/BrowserKit/CookieJar.php @@ -33,13 +33,9 @@ class CookieJar * (this behavior ensures a BC behavior with previous versions of * Symfony). * - * @param string $name The cookie name - * @param string $path The cookie path - * @param string $domain The cookie domain - * * @return Cookie|null A Cookie instance or null if the cookie does not exist */ - public function get($name, $path = '/', $domain = null) + public function get(string $name, string $path = '/', string $domain = null) { $this->flushExpiredCookies(); @@ -68,12 +64,8 @@ class CookieJar * You should never use an empty domain, but if you do so, * all cookies for the given name/path expire (this behavior * ensures a BC behavior with previous versions of Symfony). - * - * @param string $name The cookie name - * @param string $path The cookie path - * @param string $domain The cookie domain */ - public function expire($name, $path = '/', $domain = null) + public function expire(string $name, ?string $path = '/', string $domain = null) { if (null === $path) { $path = '/'; @@ -143,7 +135,7 @@ class CookieJar * @param Response $response A Response object * @param string $uri The base URL */ - public function updateFromResponse(Response $response, $uri = null) + public function updateFromResponse(Response $response, string $uri = null) { $this->updateFromSetCookie($response->getHeader('Set-Cookie', false), $uri); } @@ -172,12 +164,9 @@ class CookieJar /** * Returns not yet expired cookie values for the given URI. * - * @param string $uri A URI - * @param bool $returnsRawValue Returns raw value or urldecoded value - * * @return array An array of cookie values */ - public function allValues($uri, $returnsRawValue = false) + public function allValues(string $uri, bool $returnsRawValue = false) { $this->flushExpiredCookies(); @@ -212,11 +201,9 @@ class CookieJar /** * Returns not yet expired raw cookie values for the given URI. * - * @param string $uri A URI - * * @return array An array of cookie values */ - public function allRawValues($uri) + public function allRawValues(string $uri) { return $this->allValues($uri, true); } diff --git a/src/Symfony/Component/BrowserKit/Response.php b/src/Symfony/Component/BrowserKit/Response.php index 376bd78df4..f4c04c93ea 100644 --- a/src/Symfony/Component/BrowserKit/Response.php +++ b/src/Symfony/Component/BrowserKit/Response.php @@ -84,12 +84,9 @@ final class Response /** * Gets a response header. * - * @param string $header The header name - * @param bool $first Whether to return the first value or all header values - * * @return string|array The first header value if $first is true, an array of values otherwise */ - public function getHeader($header, $first = true) + public function getHeader(string $header, bool $first = true) { $normalizedHeader = str_replace('-', '_', strtolower($header)); foreach ($this->headers as $key => $value) {