Skip to content

Commit 4870f79

Browse files
committed
[BrowserKit] [5.0] Add type-hint to browserkit classes
1 parent 38b9b95 commit 4870f79

File tree

5 files changed

+18
-47
lines changed

5 files changed

+18
-47
lines changed

src/Symfony/Component/BrowserKit/AbstractBrowser.php

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,10 @@ public function __construct(array $server = [], History $history = null, CookieJ
6464

6565
/**
6666
* Sets whether to automatically follow redirects or not.
67-
*
68-
* @param bool $followRedirect Whether to follow redirects
6967
*/
70-
public function followRedirects($followRedirect = true)
68+
public function followRedirects(bool $followRedirect = true)
7169
{
72-
$this->followRedirects = (bool) $followRedirect;
70+
$this->followRedirects = $followRedirect;
7371
}
7472

7573
/**
@@ -92,10 +90,8 @@ public function isFollowingRedirects()
9290

9391
/**
9492
* Sets the maximum number of redirects that crawler can follow.
95-
*
96-
* @param int $maxRedirects
9793
*/
98-
public function setMaxRedirects($maxRedirects)
94+
public function setMaxRedirects(int $maxRedirects)
9995
{
10096
$this->maxRedirects = $maxRedirects < 0 ? -1 : $maxRedirects;
10197
$this->followRedirects = -1 != $this->maxRedirects;
@@ -118,13 +114,13 @@ public function getMaxRedirects()
118114
*
119115
* @throws \RuntimeException When Symfony Process Component is not installed
120116
*/
121-
public function insulate($insulated = true)
117+
public function insulate(bool $insulated = true)
122118
{
123119
if ($insulated && !class_exists('Symfony\\Component\\Process\\Process')) {
124120
throw new \LogicException('Unable to isolate requests as the Symfony Process Component is not installed.');
125121
}
126122

127-
$this->insulated = (bool) $insulated;
123+
$this->insulated = $insulated;
128124
}
129125

130126
/**
@@ -141,24 +137,18 @@ public function setServerParameters(array $server)
141137

142138
/**
143139
* Sets single server parameter.
144-
*
145-
* @param string $key A key of the parameter
146-
* @param string $value A value of the parameter
147140
*/
148-
public function setServerParameter($key, $value)
141+
public function setServerParameter(string $key, string $value)
149142
{
150143
$this->server[$key] = $value;
151144
}
152145

153146
/**
154147
* Gets single server parameter for specified key.
155148
*
156-
* @param string $key A key of the parameter to get
157-
* @param string $default A default value when key is undefined
158-
*
159149
* @return string A value of the parameter
160150
*/
161-
public function getServerParameter($key, $default = '')
151+
public function getServerParameter(string $key, string $default = '')
162152
{
163153
return isset($this->server[$key]) ? $this->server[$key] : $default;
164154
}
@@ -515,13 +505,9 @@ protected function filterResponse($response)
515505
*
516506
* This method returns null if the DomCrawler component is not available.
517507
*
518-
* @param string $uri A URI
519-
* @param string $content Content for the crawler to use
520-
* @param string $type Content type
521-
*
522508
* @return Crawler|null
523509
*/
524-
protected function createCrawlerFromContent($uri, $content, $type)
510+
protected function createCrawlerFromContent(string $uri, string $content, ?string $type)
525511
{
526512
if (!class_exists('Symfony\Component\DomCrawler\Crawler')) {
527513
return;
@@ -655,7 +641,7 @@ public function restart()
655641
*
656642
* @return string An absolute URI
657643
*/
658-
protected function getAbsoluteUri($uri)
644+
protected function getAbsoluteUri(string $uri)
659645
{
660646
// already absolute?
661647
if (0 === strpos($uri, 'http://') || 0 === strpos($uri, 'https://')) {

src/Symfony/Component/BrowserKit/Cookie.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ public function __toString()
126126
*
127127
* @throws \InvalidArgumentException
128128
*/
129-
public static function fromString($cookie, $url = null)
129+
public static function fromString(string $cookie, $url = null)
130130
{
131131
$parts = explode(';', $cookie);
132132

src/Symfony/Component/BrowserKit/CookieJar.php

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,9 @@ public function set(Cookie $cookie)
3333
* (this behavior ensures a BC behavior with previous versions of
3434
* Symfony).
3535
*
36-
* @param string $name The cookie name
37-
* @param string $path The cookie path
38-
* @param string $domain The cookie domain
39-
*
4036
* @return Cookie|null A Cookie instance or null if the cookie does not exist
4137
*/
42-
public function get($name, $path = '/', $domain = null)
38+
public function get(string $name, string $path = '/', string $domain = null)
4339
{
4440
$this->flushExpiredCookies();
4541

@@ -69,11 +65,8 @@ public function get($name, $path = '/', $domain = null)
6965
* all cookies for the given name/path expire (this behavior
7066
* ensures a BC behavior with previous versions of Symfony).
7167
*
72-
* @param string $name The cookie name
73-
* @param string $path The cookie path
74-
* @param string $domain The cookie domain
7568
*/
76-
public function expire($name, $path = '/', $domain = null)
69+
public function expire(string $name, ?string $path = '/', string $domain = null)
7770
{
7871
if (null === $path) {
7972
$path = '/';
@@ -143,7 +136,7 @@ public function updateFromSetCookie(array $setCookies, $uri = null)
143136
* @param Response $response A Response object
144137
* @param string $uri The base URL
145138
*/
146-
public function updateFromResponse(Response $response, $uri = null)
139+
public function updateFromResponse(Response $response, string $uri = null)
147140
{
148141
$this->updateFromSetCookie($response->getHeader('Set-Cookie', false), $uri);
149142
}
@@ -172,12 +165,9 @@ public function all()
172165
/**
173166
* Returns not yet expired cookie values for the given URI.
174167
*
175-
* @param string $uri A URI
176-
* @param bool $returnsRawValue Returns raw value or urldecoded value
177-
*
178168
* @return array An array of cookie values
179169
*/
180-
public function allValues($uri, $returnsRawValue = false)
170+
public function allValues(string $uri, bool $returnsRawValue = false)
181171
{
182172
$this->flushExpiredCookies();
183173

@@ -212,11 +202,9 @@ public function allValues($uri, $returnsRawValue = false)
212202
/**
213203
* Returns not yet expired raw cookie values for the given URI.
214204
*
215-
* @param string $uri A URI
216-
*
217205
* @return array An array of cookie values
218206
*/
219-
public function allRawValues($uri)
207+
public function allRawValues(string $uri)
220208
{
221209
return $this->allValues($uri, true);
222210
}

src/Symfony/Component/BrowserKit/Response.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,9 @@ public function getHeaders(): array
8484
/**
8585
* Gets a response header.
8686
*
87-
* @param string $header The header name
88-
* @param bool $first Whether to return the first value or all header values
89-
*
9087
* @return string|array The first header value if $first is true, an array of values otherwise
9188
*/
92-
public function getHeader($header, $first = true)
89+
public function getHeader(string $header, bool $first = true)
9390
{
9491
$normalizedHeader = str_replace('-', '_', strtolower($header));
9592
foreach ($this->headers as $key => $value) {

src/Symfony/Component/BrowserKit/Tests/AbstractBrowserTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,9 @@ public function testGetRequestNull()
105105
public function testXmlHttpRequest()
106106
{
107107
$client = $this->getBrowser();
108-
$client->xmlHttpRequest('GET', 'http://example.com/', [], [], [], null, true);
108+
$client->xmlHttpRequest('GET', 'http://example.com/', [], [], [], '', true);
109109
$this->assertEquals($client->getRequest()->getServer()['HTTP_X_REQUESTED_WITH'], 'XMLHttpRequest');
110-
$this->assertFalse($client->getServerParameter('HTTP_X_REQUESTED_WITH', false));
110+
$this->assertSame('', $client->getServerParameter('HTTP_X_REQUESTED_WITH', ''));
111111
}
112112

113113
public function testGetRequestWithIpAsHttpHost()

0 commit comments

Comments
 (0)