8000 Add types to constructors and private/final/internal methods (Batch II) by derrabus · Pull Request #33709 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

Add types to constructors and private/final/internal methods (Batch II) #33709

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 3, 2019
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
Add types to constructors and private/final/internal methods (Batch II)
  • Loading branch information
derrabus authored and Tobion committed Oct 3, 2019
commit 9378eb4858de63fa74038e771f571b4150dbfa3a
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ protected function initializeCatalogue($locale)
/**
* @internal
*/
protected function doLoadCatalogue($locale): void
protected function doLoadCatalogue(string $locale): void
{
parent::doLoadCatalogue($locale);

Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Bundle/FrameworkBundle/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"symfony/security-http": "^3.4|^4.0|^5.0",
"symfony/serializer": "^4.3|^5.0",
"symfony/stopwatch": "^3.4|^4.0|^5.0",
"symfony/translation": "^4.3|^5.0",
"symfony/translation": "^4.4|^5.0",
"symfony/templating": "^3.4|^4.0|^5.0",
"symfony/twig-bundle": "^4.4|^5.0",
"symfony/validator": "^4.4|^5.0",
Expand Down Expand Up @@ -80,7 +80,7 @@
"symfony/property-info": "<3.4",
"symfony/serializer": "<4.2",
"symfony/stopwatch": "<3.4",
"symfony/translation": "<4.3",
"symfony/translation": "<4.4",
"symfony/twig-bridge": "<4.1.1",
"symfony/twig-bundle": "<4.4",
"symfony/validator": "<4.4",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ public function getValuesForChoices(array $choices)
*
* @internal
*/
protected function flatten(array $choices, $value, &$choicesByValues, &$keysByValues, &$structuredValues)
protected function flatten(array $choices, callable $value, ?array &$choicesByValues, ?array &$keysByValues, ?array &$structuredValues)
{
if (null === $choicesByValues) {
$choicesByValues = [];
Expand Down
6 changes: 3 additions & 3 deletions src/Symfony/Component/Form/Command/DebugCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$helper->describe($io, $object, $options);
}

private function getFqcnTypeClass(InputInterface $input, SymfonyStyle $io, string $shortClassName)
private function getFqcnTypeClass(InputInterface $input, SymfonyStyle $io, string $shortClassName): string
{
$classes = [];
sort($this->namespaces);
Expand Down Expand Up @@ -195,7 +195,7 @@ private function getFqcnTypeClass(InputInterface $input, SymfonyStyle $io, strin
return $io->choice(sprintf("The type \"%s\" is ambiguous.\n\nSelect one of the following form types to display its information:", $shortClassName), $classes, $classes[0]);
}

private function getCoreTypes()
private function getCoreTypes(): array
{
$coreExtension = new CoreExtension();
$loadTypesRefMethod = (new \ReflectionObject($coreExtension))->getMethod('loadTypes');
Expand Down Expand Up @@ -223,7 +223,7 @@ private function filterTypesByDeprecated(array $types): array
return $typesWithDeprecatedOptions;
}

private function findAlternatives(string $name, array $collection)
private function findAlternatives(string $name, array $collection): array
{
$alternatives = [];
foreach ($collection as $item) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ protected function filterOptionsByDeprecated(ResolvedFormTypeInterface $type)
$this->extensionOptions = $filterByDeprecated($this->extensionOptions);
}

private function getParentOptionsResolver(ResolvedFormTypeInterface $type)
private function getParentOptionsResolver(ResolvedFormTypeInterface $type): OptionsResolver
{
$this->parents[$class = \get_class($type->getInnerType())] = [];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ private function buildTableRows(array $headers, array $options): array
return $tableRows;
}

private function normalizeAndSortOptionsColumns(array $options)
private function normalizeAndSortOptionsColumns(array $options): array
{
foreach ($options as $group => $opts) {
$sorted = false;
Expand Down
7 changes: 4 additions & 3 deletions src/Symfony/Component/Form/DependencyInjection/FormPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace Symfony\Component\Form\DependencyInjection;

use Symfony\Component\DependencyInjection\Argument\ArgumentInterface;
use Symfony\Component\DependencyInjection\Argument\IteratorArgument;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\Compiler\PriorityTaggedServiceTrait;
Expand Down Expand Up @@ -60,7 +61,7 @@ public function process(ContainerBuilder $container)
$definition->replaceArgument(2, $this->processFormTypeGuessers($container));
}

private function processFormTypes(ContainerBuilder $container)
private function processFormTypes(ContainerBuilder $container): Reference
{
// Get service locator argument
$servicesMap = [];
Expand All @@ -83,7 +84,7 @@ private function processFormTypes(ContainerBuilder $container)
return ServiceLocatorTagPass::register($container, $servicesMap);
}

private function processFormTypeExtensions(ContainerBuilder $container)
private function processFormTypeExtensions(ContainerBuilder $container): array
{
$typeExtensions = [];
$typeExtensionsClasses = [];
Expand Down Expand Up @@ -130,7 +131,7 @@ private function processFormTypeExtensions(ContainerBuilder $container)
return $typeExtensions;
}

private function processFormTypeGuessers(ContainerBuilder $container)
private function processFormTypeGuessers(ContainerBuilder $container): ArgumentInterface
{
$guessers = [];
$guessersClasses = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public function reverseTransform($value)
return $dateInterval;
}

private function isISO8601(string $string)
private function isISO8601(string $string): bool
{
return preg_match('/^P(?=\w*(?:\d|%\w))(?:\d+Y|%[yY]Y)?(?:\d+M|%[mM]M)?(?:(?:\d+D|%[dD]D)|(?:\d+W|%[wW]W))?(?:T(?:\d+H|[hH]H)?(?:\d+M|[iI]M)?(?:\d+S|[sS]S)?)?$/', $string);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ private static function getValidationGroups(FormInterface $form)
*
* @param string|GroupSequence|(string|GroupSequence)[]|callable $groups The validation groups
*
* @return (string|GroupSequence)[] The validation groups
* @return GroupSequence|(string|GroupSequence)[] The validation groups
*/
private static function resolveValidationGroups($groups, FormInterface $form)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Form/FormRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ public function humanize($text)
/**
* @internal
*/
public function encodeCurrency(Environment $environment, $text, $widget = '')
public function encodeCurrency(Environment $environment, string $text, string $widget = ''): string
{
if ('UTF-8' === $charset = $environment->getCharset()) {
$text = htmlspecialchars($text, ENT_QUOTES | (\defined('ENT_SUBSTITUTE') ? ENT_SUBSTITUTE : 0), 'UTF-8');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ public function testItIsEmptyAfterReset()
$this->assertEquals(0, $sut->getRequestCount());
}

private function httpClientThatHasTracedRequests($tracedRequests)
private function httpClientThatHasTracedRequests($tracedRequests): TraceableHttpClient
{
$httpClient = new TraceableHttpClient(new NativeHttpClient());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*/
class HttpExceptionTraitTest extends TestCase
{
public function provideParseError()
public function provideParseError(): iterable
{
yield ['application/ld+json', '{"hydra:title": "An error occurred", "hydra:description": "Some details"}'];
yield ['application/problem+json', '{"title": "An error occurred", "detail": "Some details"}'];
Expand Down
12 changes: 6 additions & 6 deletions src/Symfony/Component/HttpClient/Tests/HttpClientTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class HttpClientTraitTest extends TestCase
/**
* @dataProvider providePrepareRequestUrl
*/
public function testPrepareRequestUrl($expected, $url, $query = [])
public function testPrepareRequestUrl(string $expected, string $url, array $query = [])
{
$defaults = [
'base_uri' => 'http://example.com?c=c',
Expand All @@ -36,7 +36,7 @@ public function testPrepareRequestUrl($expected, $url, $query = [])
$this->assertSame($expected, implode('', $url));
}

public function providePrepareRequestUrl()
public function providePrepareRequestUrl(): iterable
{
yield ['http://example.com/', 'http://example.com/'];
yield ['http://example.com/?a=1&b=b', '.'];
Expand All @@ -48,15 +48,15 @@ public function providePrepareRequestUrl()
/**
* @dataProvider provideResolveUrl
*/
public function testResolveUrl($base, $url, $expected)
public function testResolveUrl(string $base, string $url, string $expected)
{
$this->assertSame($expected, implode('', self::resolveUrl(self::parseUrl($url), self::parseUrl($base))));
}

/**
* From https://github.com/guzzle/psr7/blob/master/tests/UriResoverTest.php.
*/
public function provideResolveUrl()
public function provideResolveUrl(): array
{
return [
[self::RFC3986_BASE, 'http:h', 'http:h'],
Expand Down Expand Up @@ -123,14 +123,14 @@ public function provideResolveUrl()
/**
* @dataProvider provideParseUrl
*/
public function testParseUrl($expected, $url, $query = [])
public function testParseUrl(array $expected, string $url, array $query = [])
{
$expected = array_combine(['scheme', 'authority', 'path', 'query', 'fragment'], $expected);

$this->assertSame($expected, self::parseUrl($url, $query));
}

public function provideParseUrl()
public function provideParseUrl(): iterable
{
yield [['http:', '//example.com', null, null, null], 'http://Example.coM:80'];
yield [['https:', '//xn--dj-kia8a.example.com:8000', '/', null, null], 'https://DÉjà.Example.com:8000/'];
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/HttpClient/Tests/HttpOptionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
*/
class HttpOptionsTest extends TestCase
{
public function provideSetAuthBasic()
public function provideSetAuthBasic(): iterable
{
yield ['user:password', 'user', 'password'];
yield ['user:password', 'user:password'];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ protected function instantiateController($class)
return new $class();
}

private function getControllerError($callable)
private function getControllerError($callable): string
{
if (\is_string($callable)) {
if (false !== strpos($callable, '::')) {
Expand Down Expand Up @@ -213,7 +213,7 @@ private function getControllerError($callable)
return $message;
}

private function getClassMethodsWithoutMagicMethods($classOrObject)
private function getClassMethodsWithoutMagicMethods($classOrObject): array
{
$methods = get_class_methods($classOrObject);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public function getName()
return 'logger';
}

private function getContainerDeprecationLogs()
private function getContainerDeprecationLogs(): array
{
if (null === $this->containerPathPrefix || !file_exists($file = $this->containerPathPrefix.'Deprecations.log')) {
return [];
Expand Down Expand Up @@ -212,7 +212,7 @@ private function sanitizeLogs(array $logs)
return array_values($sanitizedLogs);
}

private function isSilencedOrDeprecationErrorLog(array $log)
private function isSilencedOrDeprecationErrorLog(array $log): bool
{
if (!isset($log['context']['exception'])) {
return false;
Expand All @@ -231,7 +231,7 @@ private function isSilencedOrDeprecationErrorLog(array $log)
return false;
}

private function computeErrorsCount(array $containerDeprecationLogs)
private function computeErrorsCount(array $containerDeprecationLogs): array
{
$silencedLogs = [];
$count = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public function getName()
return 'memory';
}

private function convertToBytes(string $memoryLimit)
private function convertToBytes(string $memoryLimit): int
{
if ('-1' === $memoryLimit) {
return -1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ private function expandClasses(array $patterns, array $classes): array
return array_unique($expanded);
}

private function getClassesInComposerClassMaps()
private function getClassesInComposerClassMaps(): array
{
$classes = [];

Expand All @@ -103,7 +103,7 @@ private function getClassesInComposerClassMaps()
return array_keys($classes);
}

private function patternsToRegexps(array $patterns)
private function patternsToRegexps(array $patterns): array
{
$regexps = [];

Expand All @@ -125,7 +125,7 @@ private function patternsToRegexps(array $patterns)
return $regexps;
}

private function matchAnyRegexps(string $class, array $regexps)
private function matchAnyRegexps(string $class, array $regexps): bool
{
$blacklisted = false !== strpos($class, 'Test');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ public static function getSubscribedEvents()
];
}

private function createWelcomeResponse()
private function createWelcomeResponse(): Response
{
$version = Kernel::VERSION;
$projectDir = realpath($this->projectDir).\DIRECTORY_SEPARATOR;
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/HttpKernel/UriSigner.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,12 @@ public function check($uri)
return $this->computeHash($this->buildUrl($url, $params)) === $hash;
}

private function computeHash(string $uri)
private function computeHash(string $uri): string
{
return base64_encode(hash_hmac('sha256', $uri, $this->secret, true));
}

private function buildUrl(array $url, array $params = [])
private function buildUrl(array $url, array $params = []): string
{
ksort($params, SORT_STRING);
$url['query'] = http_build_query($params, '', '&');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ private function generateAlpha3Codes(array $languageCodes, ArrayAccessibleResour
return array_keys($alpha3Codes);
}

private function generateAlpha2ToAlpha3Mapping(ArrayAccessibleResourceBundle $metadataBundle)
private function generateAlpha2ToAlpha3Mapping(ArrayAccessibleResourceBundle $metadataBundle): array
{
$aliases = iterator_to_array($metadataBundle['alias']['language']);
$alpha2ToAlpha3 = [];
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Intl/Locale.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public static function getDefaultFallback(): ?string
* @return string|null The ICU locale code of the fallback locale, or null
* if no fallback exists
*/
public static function getFallback($locale): ?string
public static function getFallback(string $locale): ?string
{
if (\function_exists('locale_parse')) {
$localeSubTags = locale_parse($locale);
Expand Down
Loading
0