Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[HttpFoundation] Fix type of properties in Request class #51812

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,14 @@
*/
class TreeBuilder implements NodeParentInterface
{
/**
* @var NodeInterface|null
*/
protected $tree;

/**
* @var NodeDefinition
*/
protected $root;

public function __construct(string $name, string $type = 'array', NodeBuilder $builder = null)
Expand Down Expand Up @@ -53,7 +60,7 @@ public function buildTree(): NodeInterface
public function setPathSeparator(string $separator)
{
// unset last built as changing path separator changes all nodes
unset($this->tree);
$this->tree = null;

$this->root->setPathSeparator($separator);
}
Expand Down
6 changes: 3 additions & 3 deletions src/Symfony/Component/HttpClient/Response/MockResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class MockResponse implements ResponseInterface, StreamableInterface
use CommonResponseTrait;
use TransportResponseTrait;

private string|iterable $body;
private string|iterable|null $body;
private array $requestOptions = [];
private string $requestUrl;
private string $requestMethod;
Expand Down Expand Up @@ -98,7 +98,7 @@ public function cancel(): void
$this->info['canceled'] = true;
$this->info['error'] = 'Response has been canceled.';
try {
unset($this->body);
$this->body = null;
} catch (TransportException $e) {
// ignore errors when canceling
}
Expand Down Expand Up @@ -172,7 +172,7 @@ protected static function perform(ClientState $multi, array &$responses): void
foreach ($responses as $response) {
$id = $response->id;

if (!isset($response->body)) {
if (null === $response->body) {
// Canceled response
$response->body = [];
} elseif ([] === $response->body) {
Expand Down
84 changes: 42 additions & 42 deletions src/Symfony/Component/HttpFoundation/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,57 +136,57 @@ class Request
protected $content;

/**
* @var string[]
* @var string[]|null
*/
protected $languages;

/**
* @var string[]
* @var string[]|null
*/
protected $charsets;

/**
* @var string[]
* @var string[]|null
*/
protected $encodings;

/**
* @var string[]
* @var string[]|null
*/
protected $acceptableContentTypes;

/**
* @var string
* @var string|null
*/
protected $pathInfo;

/**
* @var string
* @var string|null
*/
protected $requestUri;

/**
* @var string
* @var string|null
*/
protected $baseUrl;

/**
* @var string
* @var string|null
*/
protected $basePath;

/**
* @var string
* @var string|null
*/
protected $method;

/**
* @var string
* @var string|null
*/
protected $format;

/**
* @var SessionInterface|callable(): SessionInterface
* @var SessionInterface|callable():SessionInterface|null
*/
protected $session;

Expand Down Expand Up @@ -282,16 +282,16 @@ public function initialize(array $query = [], array $request = [], array $attrib
$this->headers = new HeaderBag($this->server->getHeaders());

$this->content = $content;
unset($this->languages);
unset($this->charsets);
unset($this->encodings);
unset($this->acceptableContentTypes);
unset($this->pathInfo);
unset($this->requestUri);
unset($this->baseUrl);
unset($this->basePath);
unset($this->method);
unset($this->format);
$this->languages = null;
$this->charsets = null;
$this->encodings = null;
$this->acceptableContentTypes = null;
$this->pathInfo = null;
$this->requestUri = null;
$this->baseUrl = null;
$this->basePath = null;
$this->method = null;
$this->format = null;
}

/**
Expand Down Expand Up @@ -468,16 +468,16 @@ public function duplicate(array $query = null, array $request = null, array $att
$dup->server = new ServerBag($server);
$dup->headers = new HeaderBag($dup->server->getHeaders());
}
unset($dup->languages);
unset($dup->charsets);
unset($dup->encodings);
unset($dup->acceptableContentTypes);
unset($dup->pathInfo);
unset($dup->requestUri);
unset($dup->baseUrl);
unset($dup->basePath);
unset($dup->method);
unset($dup->format);
$dup->languages = null;
$dup->charsets = null;
$dup->encodings = null;
$dup->acceptableContentTypes = null;
$dup->pathInfo = null;
$dup->requestUri = null;
$dup->baseUrl = null;
$dup->basePath = null;
$dup->method = null;
$dup->format = null;

if (!$dup->get('_format') && $this->get('_format')) {
$dup->attributes->set('_format', $this->get('_format'));
Expand Down Expand Up @@ -1182,7 +1182,7 @@ public function getHost(): string
*/
public function setMethod(string $method)
{
unset($this->method);
$this->method = null;
$this->server->set('REQUEST_METHOD', $method);
}

Expand All @@ -1201,7 +1201,7 @@ public function setMethod(string $method)
*/
public function getMethod(): string
{
if (isset($this->method)) {
if (null !== $this->method) {
return $this->method;
}

Expand Down Expand Up @@ -1249,7 +1249,7 @@ public function getRealMethod(): string
*/
public function getMimeType(string $format): ?string
{
if (!isset(static::$formats)) {
if (null === static::$formats) {
static::initializeFormats();
}

Expand All @@ -1263,7 +1263,7 @@ public function getMimeType(string $format): ?string
*/
public static function getMimeTypes(string $format): array
{
if (!isset(static::$formats)) {
if (null === static::$formats) {
static::initializeFormats();
}

Expand All @@ -1280,7 +1280,7 @@ public function getFormat(?string $mimeType): ?string
$canonicalMimeType = trim(substr($mimeType, 0, $pos));
}

if (!isset(static::$formats)) {
if (null === static::$formats) {
static::initializeFormats();
}

Expand All @@ -1305,7 +1305,7 @@ public function getFormat(?string $mimeType): ?string
*/
public function setFormat(?string $format, string|array $mimeTypes)
{
if (!isset(static::$formats)) {
if (null === static::$formats) {
static::initializeFormats();
}

Expand Down Expand Up @@ -1586,13 +1586,13 @@ public function isNoCache(): bool
*/
public function getPreferredFormat(?string $default = 'html'): ?string
{
if (isset($this->preferredFormat) || null !== $preferredFormat = $this->getRequestFormat(null)) {
return $this->preferredFormat ??= $preferredFormat;
if ($this->preferredFormat ??= $this->getRequestFormat(null)) {
return $this->preferredFormat;
}

foreach ($this->getAcceptableContentTypes() as $mimeType) {
if ($preferredFormat = $this->getFormat($mimeType)) {
return $this->preferredFormat = $preferredFormat;
if ($this->preferredFormat = $this->getFormat($mimeType)) {
return $this->preferredFormat;
}
}

Expand Down Expand Up @@ -1639,7 +1639,7 @@ public function getPreferredLanguage(array $locales = null): ?string
*/
public function getLanguages(): array
{
if (isset($this->languages)) {
if (null !== $this->languages) {
return $this->languages;
}

Expand Down