Skip to content

Commit

Permalink
minor #42203 Add return type unions to private/internal/final/test me…
Browse files Browse the repository at this point in the history
…thods (nicolas-grekas)

This PR was merged into the 6.0 branch.

Discussion
----------

Add return type unions to private/internal/final/test methods

| Q             | A
| ------------- | ---
| Branch?       | 6.0
| Bug fix?      | no
| New feature?  | no
| Deprecations? | no
| Tickets       | -
| License       | MIT
| Doc PR        | -

Spotted thanks to progress made on #42149

Commits
-------

af7ff7e Add return type unions to private/internal/final/test methods
  • Loading branch information
nicolas-grekas committed Jul 21, 2021
2 parents 439ce7b + af7ff7e commit eaa80d9
Show file tree
Hide file tree
Showing 59 changed files with 78 additions and 143 deletions.
7 changes: 1 addition & 6 deletions src/Symfony/Bridge/Twig/Extension/CodeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,12 +169,7 @@ public function formatFile(string $file, int $line, string $text = null): string
return $text;
}

/**
* Returns the link for a given file/line pair.
*
* @return string|false A link or false
*/
public function getFileLink(string $file, int $line)
public function getFileLink(string $file, int $line): string|false
{
if ($fmt = $this->fileLinkFormat) {
return \is_string($fmt) ? strtr($fmt, ['%f' => $file, '%l' => $line]) : $fmt->format($file, $line);
Expand Down
5 changes: 1 addition & 4 deletions src/Symfony/Bridge/Twig/Extension/FormExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,7 @@ public function getFieldName(FormView $view): string
return $view->vars['full_name'];
}

/**
* @return string|array
*/
public function getFieldValue(FormView $view)
public function getFieldValue(FormView $view): string|array
{
return $view->vars['value'];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public function getNamespace(): string
return '';
}

public function getXsdValidationBasePath()
public function getXsdValidationBasePath(): string|false
{
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ public function getUsername(): string
return $this->username;
}

public function getUserIdentifier()
public function getUserIdentifier(): string
{
return $this->username;
}
Expand Down
14 changes: 1 addition & 13 deletions src/Symfony/Component/BrowserKit/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,6 @@ public function __toString(): string
return $headers."\n".$this->content;
}

/**
* Gets the response content.
*
* @return string The response content
*/
public function getContent(): string
{
return $this->content;
Expand All @@ -69,22 +64,15 @@ public function getStatusCode(): int
return $this->status;
}

/**
* Gets the response headers.
*
* @return array The response headers
*/
public function getHeaders(): array
{
return $this->headers;
}

/**
* Gets a response header.
*
* @return string|array|null The first header value if $first is true, an array of values otherwise
*/
public function getHeader(string $header, bool $first = true)
public function getHeader(string $header, bool $first = true): string|array|null
{
$normalizedHeader = str_replace('-', '_', strtolower($header));
foreach ($this->headers as $key => $value) {
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Cache/Tests/Fixtures/ArrayCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class ArrayCache extends CacheProvider
{
private $data = [];

protected function doFetch($id)
protected function doFetch($id): mixed
{
return $this->doContains($id) ? $this->data[$id][0] : false;
}
Expand Down
8 changes: 2 additions & 6 deletions src/Symfony/Component/Console/Helper/QuestionHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -496,10 +496,8 @@ private function isInteractiveInput($inputStream): bool
*
* @param resource $inputStream The handler resource
* @param Question $question The question being asked
*
* @return string|false The input received, false in case input could not be read
*/
private function readInput($inputStream, Question $question)
private function readInput($inputStream, Question $question): string|false
{
if (!$question->isMultiline()) {
$cp = $this->setIOCodepage();
Expand Down Expand Up @@ -539,10 +537,8 @@ private function setIOCodepage(): int

/**
* Sets console I/O to the specified code page and converts the user input.
*
* @return string|false
*/
private function resetIOCodepage(int $cp, string|false $input)
private function resetIOCodepage(int $cp, string|false $input): string|false
{
if (0 !== $cp) {
sapi_windows_cp_set($cp);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public function load(array $configs, ContainerBuilder $configuration)
return $configuration;
}

public function getXsdValidationBasePath()
public function getXsdValidationBasePath(): string|false
{
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function load(array $configs, ContainerBuilder $configuration)
return $configuration;
}

public function getXsdValidationBasePath()
public function getXsdValidationBasePath(): string|false
{
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

class ProjectWithXsdExtension extends ProjectExtension
{
public function getXsdValidationBasePath()
public function getXsdValidationBasePath(): string|false
{
return __DIR__.'/schema';
}
Expand Down
6 changes: 2 additions & 4 deletions src/Symfony/Component/DomCrawler/Field/ChoiceFormField.php
Original file line number Diff line number Diff line change
Expand Up @@ -252,11 +252,9 @@ private function buildOptionValue(\DOMElement $node): array
/**
* Checks whether given value is in the existing options.
*
* @internal since Symfony 5.3
*
* @return bool
* @internal
*/
public function containsOption(string $optionValue, array $options)
public function containsOption(string $optionValue, array $options): bool
{
if ($this->validationDisabled) {
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,6 @@ private function renderException(FlattenException $exception, string $debugTempl
]);
}

/**
* Formats an array as a string.
*/
private function formatArgs(array $args): string
{
$result = [];
Expand Down Expand Up @@ -203,12 +200,7 @@ private function getFileRelative(string $file): ?string
return null;
}

/**
* Returns the link for a given file/line pair.
*
* @return string|false A link or false
*/
private function getFileLink(string $file, int $line)
private function getFileLink(string $file, int $line): string|false
{
if ($fmt = $this->fileLinkFormat) {
return \is_string($fmt) ? strtr($fmt, ['%f' => $file, '%l' => $line]) : $fmt->format($file, $line);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,12 +195,8 @@ protected function getNumberFormatter()

/**
* Rounds a number according to the configured scale and rounding mode.
*
* @param int|float $number A number
*
* @return int|float The rounded number
*/
private function round($number)
private function round(int|float $number): int|float
{
if (null !== $this->scale && null !== $this->roundingMode) {
// shift number to maintain the correct scale during rounding
Expand Down
4 changes: 1 addition & 3 deletions src/Symfony/Component/Form/Extension/Core/Type/FileType.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,8 @@ private function getFileUploadError(int $errorCode)
* Returns the maximum size of an uploaded file as configured in php.ini.
*
* This method should be kept in sync with Symfony\Component\HttpFoundation\File\UploadedFile::getMaxFilesize().
*
* @return int|float The maximum size of an uploaded file in bytes (returns float if size > PHP_INT_MAX)
*/
private static function getMaxFilesize()
private static function getMaxFilesize(): int|float
{
$iniMax = strtolower(ini_get('upload_max_filesize'));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ public function validate(mixed $form, Constraint $formConstraint)
*
* @return string|GroupSequence|array<string|GroupSequence> The validation groups
*/
private function getValidationGroups(FormInterface $form)
private function getValidationGroups(FormInterface $form): string|GroupSequence|array
{
// Determine the clicked button of the complete form tree
$clickedButton = null;
Expand Down
7 changes: 1 addition & 6 deletions src/Symfony/Component/HttpFoundation/File/UploadedFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -226,12 +226,7 @@ public static function getMaxFilesize()
return min($sizePostMax ?: \PHP_INT_MAX, $sizeUploadMax ?: \PHP_INT_MAX);
}

/**
* Returns the given size from an ini value in bytes.
*
* @return int|float Returns float if size > PHP_INT_MAX
*/
private static function parseFilesize(string $size)
private static function parseFilesize(string $size): int|float
{
if ('' === $size) {
return 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -386,11 +386,7 @@ public function getAttribute($attribute): mixed
return parent::getAttribute($attribute);
}

/**
* @return false|\PDOStatement
*/
#[\ReturnTypeWillChange]
public function prepare($statement, $driverOptions = [])
public function prepare($statement, $driverOptions = []): \PDOStatement|false
{
return \is_callable($this->prepareResult)
? ($this->prepareResult)($statement, $driverOptions)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,7 @@ public function getName(): string
return 'memory';
}

/**
* @return int|float
*/
private function convertToBytes(string $memoryLimit)
private function convertToBytes(string $memoryLimit): int|float
{
if ('-1' === $memoryLimit) {
return -1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
*
* @final
*
* @internal since Symfony 5.3
* @internal
*/
class DebugHandlersListener implements EventSubscriberInterface
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function isCatchingExceptions()
return $this->catch;
}

public function getController(Request $request)
public function getController(Request $request): callable|false
{
return [$this, 'callController'];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function handle(Request $request, $type = HttpKernelInterface::MAIN_REQUE
return parent::handle($request, $type, $catch);
}

public function getController(Request $request)
public function getController(Request $request): callable|false
{
return [$this, 'callController'];
}
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/HttpKernel/Tests/KernelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ public function getNamespace()
return '';
}

public function getXsdValidationBasePath()
public function getXsdValidationBasePath(): string|false
{
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/HttpKernel/Tests/TestHttpKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function __construct()
parent::__construct(new EventDispatcher(), $this, null, $this);
}

public function getController(Request $request)
public function getController(Request $request): callable|false
{
return [$this, 'callController'];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ public function testLdapUnboundUpdate()
/**
* @return Collection|Entry[]
*/
private function executeSearchQuery($expectedResults = 1)
private function executeSearchQuery($expectedResults = 1): Collection|array
{
$results = $this
->adapter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
use Symfony\Contracts\Service\ResetInterface;

/**
* @internal since Symfony 5.1
* @internal
*
* @author Vincent Touzet <vincent.touzet@gmail.com>
* @author Kévin Dunglas <dunglas@gmail.com>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

use Symfony\Component\ErrorHandler\Exception\FlattenException;
use Symfony\Component\Messenger\Transport\Serialization\Serializer;
use Symfony\Component\Serializer\Exception\InvalidArgumentException;
use Symfony\Component\Serializer\Normalizer\ContextAwareNormalizerInterface;
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
use Symfony\Component\Serializer\Normalizer\NormalizerAwareTrait;
Expand All @@ -30,7 +29,7 @@ final class FlattenExceptionNormalizer implements DenormalizerInterface, Context
/**
* {@inheritdoc}
*/
public function normalize(mixed $object, string $format = null, array $context = [])
public function normalize(mixed $object, string $format = null, array $context = []): array|string|int|float|bool|\ArrayObject|null
{
$normalized = [
'message' => $object->getMessage(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function getUsername(): string
return $this->username;
}

public function getUserIdentifier()
public function getUserIdentifier(): string
{
return $this->username;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

class FileLocatorStub implements FileLocatorInterface
{
public function locate(string $name, string $currentPath = null, bool $first = true)
public function locate(string $name, string $currentPath = null, bool $first = true): string|array
{
if (0 === strpos($name, 'http')) {
return $name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*
* @author Fabien Potencier <fabien@symfony.com>
*
* @internal since Symfony 5.3
* @internal
*/
interface AuthenticationManagerInterface
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Symfony\Component\Security\Core\Authentication\Token\AnonymousToken;
use Symfony\Component\Security\Core\Authentication\Token\RememberMeToken;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\User\UserInterface;

class AuthenticationTrustResolverTest extends TestCase
{
Expand Down Expand Up @@ -143,7 +144,7 @@ public function getCredentials(): mixed
{
}

public function getUser()
public function getUser(): string|\Stringable|UserInterface
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ public function getUsername(): string
return $this->name;
}

public function getUserIdentifier()
public function getUserIdentifier(): string
{
return $this->name;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ public function getUsername(): string
return $this->username;
}

public function getUserIdentifier()
public function getUserIdentifier(): string
{
return $this->username;
}
Expand Down
Loading

0 comments on commit eaa80d9

Please sign in to comment.