Skip to content

Commit

Permalink
minor #33410 [HttpFoundation] Add types to private/final/internal met…
Browse files Browse the repository at this point in the history
…hods and constructors (derrabus)

This PR was merged into the 4.4 branch.

Discussion
----------

[HttpFoundation] Add types to private/final/internal methods and constructors

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #32179, #33228
| License       | MIT
| Doc PR        | N/A

Commits
-------

1978d88 [HttpFoundation] Add types to private/final/internal methods and constructors.
  • Loading branch information
nicolas-grekas committed Sep 8, 2019
2 parents c79b45d + 1978d88 commit 26954bc
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 17 deletions.
16 changes: 7 additions & 9 deletions src/Symfony/Component/HttpFoundation/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -1817,12 +1817,12 @@ protected function prepareBaseUrl()
$requestUri = '/'.$requestUri;
}

if ($baseUrl && false !== $prefix = $this->getUrlencodedPrefix($requestUri, $baseUrl)) {
if ($baseUrl && null !== $prefix = $this->getUrlencodedPrefix($requestUri, $baseUrl)) {
// full $baseUrl matches
return $prefix;
}

if ($baseUrl && false !== $prefix = $this->getUrlencodedPrefix($requestUri, rtrim(\dirname($baseUrl), '/'.\DIRECTORY_SEPARATOR).'/')) {
if ($baseUrl && null !== $prefix = $this->getUrlencodedPrefix($requestUri, rtrim(\dirname($baseUrl), '/'.\DIRECTORY_SEPARATOR).'/')) {
// directory portion of $baseUrl matches
return rtrim($prefix, '/'.\DIRECTORY_SEPARATOR);
}
Expand Down Expand Up @@ -1941,14 +1941,12 @@ private function setPhpDefaultLocale(string $locale): void

/**
* Returns the prefix as encoded in the string when the string starts with
* the given prefix, false otherwise.
*
* @return string|false The prefix as it is encoded in $string, or false
* the given prefix, null otherwise.
*/
private function getUrlencodedPrefix(string $string, string $prefix)
private function getUrlencodedPrefix(string $string, string $prefix): ?string
{
if (0 !== strpos(rawurldecode($string), $prefix)) {
return false;
return null;
}

$len = \strlen($prefix);
Expand All @@ -1957,10 +1955,10 @@ private function getUrlencodedPrefix(string $string, string $prefix)
return $match[0];
}

return false;
return null;
}

private static function createRequestFromFactory(array $query = [], array $request = [], array $attributes = [], array $cookies = [], array $files = [], array $server = [], $content = null)
private static function createRequestFromFactory(array $query = [], array $request = [], array $attributes = [], array $cookies = [], array $files = [], array $server = [], $content = null): self
{
if (self::$requestFactory) {
$request = (self::$requestFactory)($query, $request, $attributes, $cookies, $files, $server, $content);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ final class SessionBagProxy implements SessionBagInterface
private $data;
private $usageIndex;

public function __construct(SessionBagInterface $bag, array &$data, &$usageIndex)
public function __construct(SessionBagInterface $bag, array &$data, ?int &$usageIndex)
{
$this->bag = $bag;
$this->data = &$data;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace Symfony\Component\HttpFoundation\Test\Constraint;

use PHPUnit\Framework\Constraint\Constraint;
use Symfony\Component\HttpFoundation\Request;

final class RequestAttributeValueSame extends Constraint
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ protected function failureDescription($response): string
return 'the Response '.$this->toString();
}

protected function getCookie(Response $response): ?Cookie
private function getCookie(Response $response): ?Cookie
{
$cookies = $response->headers->getCookies();

Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/HttpFoundation/Tests/RequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1803,7 +1803,7 @@ private function disableHttpMethodParameterOverride()
$property->setValue(false);
}

private function getRequestInstanceForClientIpTests($remoteAddr, $httpForwardedFor, $trustedProxies)
private function getRequestInstanceForClientIpTests(string $remoteAddr, ?string $httpForwardedFor, ?array $trustedProxies): Request
{
$request = new Request();

Expand All @@ -1821,7 +1821,7 @@ private function getRequestInstanceForClientIpTests($remoteAddr, $httpForwardedF
return $request;
}

private function getRequestInstanceForClientIpsForwardedTests($remoteAddr, $httpForwarded, $trustedProxies)
private function getRequestInstanceForClientIpsForwardedTests(string $remoteAddr, ?string $httpForwarded, ?array $trustedProxies): Request
{
$request = new Request();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ public function testDateHeaderWillBeRecreatedWhenHeadersAreReplaced()
$this->assertTrue($bag->has('Date'));
}

private function assertSetCookieHeader($expected, ResponseHeaderBag $actual)
private function assertSetCookieHeader(string $expected, ResponseHeaderBag $actual)
{
$this->assertRegExp('#^Set-Cookie:\s+'.preg_quote($expected, '#').'$#m', str_replace("\r\n", "\n", (string) $actual));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ public function testGetConnection()
$this->assertInstanceOf(\MongoDB\Client::class, $method->invoke($this->storage));
}

private function createMongoCollectionMock()
private function createMongoCollectionMock(): \MongoDB\Collection
{
$collection = $this->getMockBuilder(\MongoDB\Collection::class)
->disableOriginalConstructor()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,9 @@ public function provideUrlDsnPairs()
yield ['mssql://localhost:56/test', 'sqlsrv:server=localhost,56;Database=test'];
}

/**
* @return resource
*/
private function createStream($content)
{
$stream = tmpfile();
Expand All @@ -362,7 +365,7 @@ class MockPdo extends \PDO
private $driverName;
private $errorMode;

public function __construct($driverName = null, $errorMode = null)
public function __construct(string $driverName = null, int $errorMode = null)
{
$this->driverName = $driverName;
$this->errorMode = null !== $errorMode ?: \PDO::ERRMODE_EXCEPTION;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public function testSaveWithoutStart()
$storage1->save();
}

private function getStorage()
private function getStorage(): MockFileSessionStorage
{
$storage = new MockFileSessionStorage($this->sessionDir);
$storage->registerBag(new FlashBag());
Expand Down

0 comments on commit 26954bc

Please sign in to comment.