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

Skip to content

Add return types - batch 3/n #42507

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
Aug 13, 2021
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
24 changes: 7 additions & 17 deletions src/Symfony/Component/HttpFoundation/AcceptHeader.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,8 @@ public function __construct(array $items)

/**
* Builds an AcceptHeader instance from a string.
*
* @return self
*/
public static function fromString(?string $headerValue)
public static function fromString(?string $headerValue): self
{
$index = 0;

Expand All @@ -76,20 +74,16 @@ public function __toString(): string

/**
* Tests if header has given value.
*
* @return bool
*/
public function has(string $value)
public function has(string $value): bool
{
return isset($this->items[$value]);
}

/**
* Returns given value's item, if exists.
*
* @return AcceptHeaderItem|null
*/
public function get(string $value)
public function get(string $value): ?AcceptHeaderItem
{
return $this->items[$value] ?? $this->items[explode('/', $value)[0].'/*'] ?? $this->items['*/*'] ?? $this->items['*'] ?? null;
}
Expand All @@ -99,7 +93,7 @@ public function get(string $value)
*
* @return $this
*/
public function add(AcceptHeaderItem $item)
public function add(AcceptHeaderItem $item): static
{
$this->items[$item->getValue()] = $item;
$this->sorted = false;
Expand All @@ -112,7 +106,7 @@ public function add(AcceptHeaderItem $item)
*
* @return AcceptHeaderItem[]
*/
public function all()
public function all(): array
{
$this->sort();

Expand All @@ -121,10 +115,8 @@ public function all()

/**
* Filters items on their value using given regex.
*
* @return self
*/
public function filter(string $pattern)
public function filter(string $pattern): self
{
return new self(array_filter($this->items, function (AcceptHeaderItem $item) use ($pattern) {
return preg_match($pattern, $item->getValue());
Expand All @@ -133,10 +125,8 @@ public function filter(string $pattern)

/**
* Returns first item.
*
* @return AcceptHeaderItem|null
*/
public function first()
public function first(): ?AcceptHeaderItem
{
$this->sort();

Expand Down
36 changes: 11 additions & 25 deletions src/Symfony/Component/HttpFoundation/AcceptHeaderItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,8 @@ public function __construct(string $value, array $attributes = [])

/**
* Builds an AcceptHeaderInstance instance from a string.
*
* @return self
*/
public static function fromString(?string $itemValue)
public static function fromString(?string $itemValue): self
{
$parts = HeaderUtils::split($itemValue ?? '', ';=');

Expand Down Expand Up @@ -64,7 +62,7 @@ public function __toString(): string
*
* @return $this
*/
public function setValue(string $value)
public function setValue(string $value): static
{
$this->value = $value;

Expand All @@ -73,10 +71,8 @@ public function setValue(string $value)

/**
* Returns the item value.
*
* @return string
*/
public function getValue()
public function getValue(): string
{
return $this->value;
}
Expand All @@ -86,7 +82,7 @@ public function getValue()
*
* @return $this
*/
public function setQuality(float $quality)
public function setQuality(float $quality): static
{
$this->quality = $quality;

Expand All @@ -95,10 +91,8 @@ public function setQuality(float $quality)

/**
* Returns the item quality.
*
* @return float
*/
public function getQuality()
public function getQuality(): float
{
return $this->quality;
}
Expand All @@ -108,7 +102,7 @@ public function getQuality()
*
* @return $this
*/
public function setIndex(int $index)
public function setIndex(int $index): static
{
$this->index = $index;

Expand All @@ -117,40 +111,32 @@ public function setIndex(int $index)

/**
* Returns the item index.
*
* @return int
*/
public function getIndex()
public function getIndex(): int
{
return $this->index;
}

/**
* Tests if an attribute exists.
*
* @return bool
*/
public function hasAttribute(string $name)
public function hasAttribute(string $name): bool
{
return isset($this->attributes[$name]);
}

/**
* Returns an attribute by its name.
*
* @return mixed
*/
public function getAttribute(string $name, mixed $default = null)
public function getAttribute(string $name, mixed $default = null): mixed
{
return $this->attributes[$name] ?? $default;
}

/**
* Returns all attributes.
*
* @return array
*/
public function getAttributes()
public function getAttributes(): array
{
return $this->attributes;
}
Expand All @@ -160,7 +146,7 @@ public function getAttributes()
*
* @return $this
*/
public function setAttribute(string $name, string $value)
public function setAttribute(string $name, string $value): static
{
if ('q' === $name) {
$this->quality = (float) $value;
Expand Down
16 changes: 8 additions & 8 deletions src/Symfony/Component/HttpFoundation/BinaryFileResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function __construct(\SplFileInfo|string $file, int $status = 200, array
*
* @throws FileException
*/
public function setFile(\SplFileInfo|string $file, string $contentDisposition = null, bool $autoEtag = false, bool $autoLastModified = true)
public function setFile(\SplFileInfo|string $file, string $contentDisposition = null, bool $autoEtag = false, bool $autoLastModified = true): static
{
if (!$file instanceof File) {
if ($file instanceof \SplFileInfo) {
Expand Down Expand Up @@ -98,7 +98,7 @@ public function setFile(\SplFileInfo|string $file, string $contentDisposition =
*
* @return File The file to stream
*/
public function getFile()
public function getFile(): File
{
return $this->file;
}
Expand Down Expand Up @@ -132,7 +132,7 @@ public function setAutoEtag()
*
* @return $this
*/
public function setContentDisposition(string $disposition, string $filename = '', string $filenameFallback = '')
public function setContentDisposition(string $disposition, string $filename = '', string $filenameFallback = ''): static
{
if ('' === $filename) {
$filename = $this->file->getFilename();
Expand Down Expand Up @@ -161,7 +161,7 @@ public function setContentDisposition(string $disposition, string $filename = ''
/**
* {@inheritdoc}
*/
public function prepare(Request $request)
public function prepare(Request $request): static
{
if (!$this->headers->has('Content-Type')) {
$this->headers->set('Content-Type', $this->file->getMimeType() ?: 'application/octet-stream');
Expand Down Expand Up @@ -269,7 +269,7 @@ private function hasValidIfRangeHeader(?string $header): bool
*
* {@inheritdoc}
*/
public function sendContent()
public function sendContent(): static
{
if (!$this->isSuccessful()) {
return parent::sendContent();
Expand Down Expand Up @@ -299,7 +299,7 @@ public function sendContent()
*
* @throws \LogicException when the content is not null
*/
public function setContent(?string $content)
public function setContent(?string $content): static
{
if (null !== $content) {
throw new \LogicException('The content cannot be set on a BinaryFileResponse instance.');
Expand All @@ -311,7 +311,7 @@ public function setContent(?string $content)
/**
* {@inheritdoc}
*/
public function getContent()
public function getContent(): string|false
{
return false;
}
Expand All @@ -330,7 +330,7 @@ public static function trustXSendfileTypeHeader()
*
* @return $this
*/
public function deleteFileAfterSend(bool $shouldDelete = true)
public function deleteFileAfterSend(bool $shouldDelete = true): static
{
$this->deleteFileAfterSend = $shouldDelete;

Expand Down
Loading