Skip to content

Commit 10e152f

Browse files
committed
minor #32280 [BrowserKit] [5.0] Add type-hint to all classes (Simperfit)
This PR was merged into the 5.0-dev branch. Discussion ---------- [BrowserKit] [5.0] Add type-hint to all classes | Q | A | ------------- | --- | Branch? | 5.0 | Bug fix? | no | New feature? | no <!-- please update src/**/CHANGELOG.md files --> | BC breaks? | no <!-- see https://symfony.com/bc --> | Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tests pass? | yes <!-- please add some, will be required by reviewers --> | Fixed tickets | Contribute to #32179 <!-- #-prefixed issue number(s), if any --> | License | MIT | Doc PR | none <!-- required for new features --> <!-- Replace this notice by a short README for your feature/bugfix. This will help people understand your PR and can be used as a start for the documentation. Additionally (see https://symfony.com/roadmap): - Bug fixes must be submitted against the lowest maintained branch where they apply (lowest branches are regularly merged to upper ones so they get the fixes too). - Features and deprecations must be submitted against branch 4.4. - Legacy code removals go to the master branch. --> We are adding the type-hint to all BrowserKit classes ;). Commits ------- be0e4bd [BrowserKit] [5.0] Add type-hint to browserkit classes
2 parents faf5e8b + be0e4bd commit 10e152f

File tree

4 files changed

+17
-50
lines changed

4 files changed

+17
-50
lines changed

src/Symfony/Component/BrowserKit/AbstractBrowser.php

Lines changed: 10 additions & 24 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 $followRedirects = true)
7169
{
72-
$this->followRedirects = (bool) $followRedirect;
70+
$this->followRedirects = $followRedirects;
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, $default = '')
162152
{
163153
return isset($this->server[$key]) ? $this->server[$key] : $default;
164154
}
@@ -416,7 +406,7 @@ public function request(string $method, string $uri, array $parameters = [], arr
416406
return $this->crawler = $this->followRedirect();
417407
}
418408

419-
$this->crawler = $this->createCrawlerFromContent($this->internalRequest->getUri(), $this->internalResponse->getContent(), $this->internalResponse->getHeader('Content-Type'));
409+
$this->crawler = $this->createCrawlerFromContent($this->internalRequest->getUri(), $this->internalResponse->getContent(), $this->internalResponse->getHeader('Content-Type') ?? '');
420410

421411
// Check for meta refresh redirect
422412
if ($this->followMetaRefresh && null !== $redirect = $this->getMetaRefreshUrl()) {
@@ -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 & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,14 +119,11 @@ public function __toString()
119119
/**
120120
* Creates a Cookie instance from a Set-Cookie header value.
121121
*
122-
* @param string $cookie A Set-Cookie header value
123-
* @param string|null $url The base URL
124-
*
125122
* @return static
126123
*
127124
* @throws \InvalidArgumentException
128125
*/
129-
public static function fromString($cookie, $url = null)
126+
public static function fromString(string $cookie, string $url = null)
130127
{
131128
$parts = explode(';', $cookie);
132129

src/Symfony/Component/BrowserKit/CookieJar.php

Lines changed: 5 additions & 18 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

@@ -68,12 +64,8 @@ public function get($name, $path = '/', $domain = null)
6864
* You should never use an empty domain, but if you do so,
6965
* all cookies for the given name/path expire (this behavior
7066
* ensures a BC behavior with previous versions of Symfony).
71-
*
72-
* @param string $name The cookie name
73-
* @param string $path The cookie path
74-
* @param string $domain The cookie domain
7567
*/
76-
public function expire($name, $path = '/', $domain = null)
68+
public function expire(string $name, ?string $path = '/', string $domain = null)
7769
{
7870
if (null === $path) {
7971
$path = '/';
@@ -143,7 +135,7 @@ public function updateFromSetCookie(array $setCookies, $uri = null)
143135
* @param Response $response A Response object
144136
* @param string $uri The base URL
145137
*/
146-
public function updateFromResponse(Response $response, $uri = null)
138+
public function updateFromResponse(Response $response, string $uri = null)
147139
{
148140
$this->updateFromSetCookie($response->getHeader('Set-Cookie', false), $uri);
149141
}
@@ -172,12 +164,9 @@ public function all()
172164
/**
173165
* Returns not yet expired cookie values for the given URI.
174166
*
175-
* @param string $uri A URI
176-
* @param bool $returnsRawValue Returns raw value or urldecoded value
177-
*
178167
* @return array An array of cookie values
179168
*/
180-
public function allValues($uri, $returnsRawValue = false)
169+
public function allValues(string $uri, bool $returnsRawValue = false)
181170
{
182171
$this->flushExpiredCookies();
183172

@@ -212,11 +201,9 @@ public function allValues($uri, $returnsRawValue = false)
212201
/**
213202
* Returns not yet expired raw cookie values for the given URI.
214203
*
215-
* @param string $uri A URI
216-
*
217204
* @return array An array of cookie values
218205
*/
219-
public function allRawValues($uri)
206+
public function allRawValues(string $uri)
220207
{
221208
return $this->allValues($uri, true);
222209
}

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) {

0 commit comments

Comments
 (0)