Skip to content

Commit 5cb7c7b

Browse files
committed
minor symfony#57809 [BrowserKit][HttpKernel] make use of the @template annotation to improve type information (xabbuh)
This PR was merged into the 7.2 branch. Discussion ---------- [BrowserKit][HttpKernel] make use of the ``@template`` annotation to improve type information | Q | A | ------------- | --- | Branch? | 7.2 | Bug fix? | no | New feature? | no | Deprecations? | no | Issues | | License | MIT I was wondering why we had ``@method`` annotations in the `HttpKernelBrowser` class. It looks like they were introduced in symfony#21537 to satisfy static analysis tools and to improve auto-completion in IDEs. Given that we have more than one subclass of the `AbstractBrowser` class I thought it might be good to properly make use of the ``@template`` annotation to cover all methods of that class without having to list them all explicitly in all child classes. Commits ------- 44e4e43 make use of the `@template` annotation to improve type information
2 parents 0643014 + 44e4e43 commit 5cb7c7b

File tree

3 files changed

+24
-4
lines changed

3 files changed

+24
-4
lines changed

src/Symfony/Component/BrowserKit/AbstractBrowser.php

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,20 @@
2929
* you need to also implement the getScript() method.
3030
*
3131
* @author Fabien Potencier <[email protected]>
32+
*
33+
* @template TRequest of object
34+
* @template TResponse of object
3235
*/
3336
abstract class AbstractBrowser
3437
{
3538
protected History $history;
3639
protected CookieJar $cookieJar;
3740
protected array $server = [];
3841
protected Request $internalRequest;
42+
/** @psalm-var TRequest */
3943
protected object $request;
4044
protected Response $internalResponse;
45+
/** @psalm-var TResponse */
4146
protected object $response;
4247
protected Crawler $crawler;
4348
protected bool $useHtml5Parser = true;
@@ -221,6 +226,8 @@ public function getInternalResponse(): Response
221226
* The origin response is the response instance that is returned
222227
* by the code that handles requests.
223228
*
229+
* @psalm-return TResponse
230+
*
224231
* @see doRequest()
225232
*/
226233
public function getResponse(): object
@@ -242,6 +249,8 @@ public function getInternalRequest(): Request
242249
* The origin request is the request instance that is sent
243250
* to the code that handles requests.
244251
*
252+
* @psalm-return TRequest
253+
*
245254
* @see doRequest()
246255
*/
247256
public function getRequest(): object
@@ -402,7 +411,9 @@ public function request(string $method, string $uri, array $parameters = [], arr
402411
/**
403412
* Makes a request in another process.
404413
*
405-
* @return object
414+
* @psalm-param TRequest $request
415+
*
416+
* @psalm-return TResponse
406417
*
407418
* @throws \RuntimeException When processing returns exit code
408419
*/
@@ -437,13 +448,17 @@ protected function doRequestInProcess(object $request)
437448
/**
438449
* Makes a request.
439450
*
440-
* @return object
451+
* @psalm-param TRequest $request
452+
*
453+
* @psalm-return TResponse
441454
*/
442455
abstract protected function doRequest(object $request);
443456

444457
/**
445458
* Returns the script to execute when the request must be insulated.
446459
*
460+
* @psalm-param TRequest $request
461+
*
447462
* @param object $request An origin request instance
448463
*
449464
* @return string
@@ -459,6 +474,8 @@ protected function getScript(object $request)
459474
* Filters the BrowserKit request to the origin one.
460475
*
461476
* @return object
477+
*
478+
* @psalm-return TRequest
462479
*/
463480
protected function filterRequest(Request $request)
464481
{
@@ -468,6 +485,8 @@ protected function filterRequest(Request $request)
468485
/**
469486
* Filters the origin response to the BrowserKit one.
470487
*
488+
* @psalm-param TResponse $response
489+
*
471490
* @return Response
472491
*/
473492
protected function filterResponse(object $response)

src/Symfony/Component/BrowserKit/HttpBrowser.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
* to make real HTTP requests.
2525
*
2626
* @author Fabien Potencier <[email protected]>
27+
*
28+
* @template-extends AbstractBrowser<Request, Response>
2729
*/
2830
class HttpBrowser extends AbstractBrowser
2931
{

src/Symfony/Component/HttpKernel/HttpKernelBrowser.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@
2525
*
2626
* @author Fabien Potencier <[email protected]>
2727
*
28-
* @method Request getRequest()
29-
* @method Response getResponse()
28+
* @template-extends AbstractBrowser<Request, Response>
3029
*/
3130
class HttpKernelBrowser extends AbstractBrowser
3231
{

0 commit comments

Comments
 (0)