From 1b880677d494972df820f772c408dd1c1089554c Mon Sep 17 00:00:00 2001 From: "Alexander M. Turek" Date: Fri, 16 Aug 2019 02:46:59 +0200 Subject: [PATCH] Add types to private and final methods. --- .../Bridge/Doctrine/DataCollector/DoctrineDataCollector.php | 4 ++-- src/Symfony/Bridge/Monolog/Formatter/ConsoleFormatter.php | 2 +- src/Symfony/Bridge/Twig/Command/LintCommand.php | 6 +++--- .../CacheWarmer/AbstractPhpFileCacheWarmer.php | 2 +- .../DependencyInjection/FrameworkExtension.php | 4 ++-- src/Symfony/Component/BrowserKit/Cookie.php | 4 +++- src/Symfony/Component/Filesystem/Filesystem.php | 5 ++++- src/Symfony/Component/Form/Extension/Core/Type/FileType.php | 4 ++-- src/Symfony/Component/Form/FormFactoryBuilder.php | 5 +---- src/Symfony/Component/Messenger/MessageBus.php | 2 +- src/Symfony/Component/PropertyAccess/PropertyAccessor.php | 2 +- .../Security/Core/Authorization/AccessDecisionManager.php | 6 +++--- .../Security/Http/RememberMe/AbstractRememberMeServices.php | 3 ++- .../Component/Translation/Command/XliffLintCommand.php | 2 +- .../Component/Validator/Constraints/FileValidator.php | 4 ++-- src/Symfony/Component/Workflow/Registry.php | 6 +++++- 16 files changed, 34 insertions(+), 27 deletions(-) diff --git a/src/Symfony/Bridge/Doctrine/DataCollector/DoctrineDataCollector.php b/src/Symfony/Bridge/Doctrine/DataCollector/DoctrineDataCollector.php index a4fef5bbac..aa1cd95d8d 100644 --- a/src/Symfony/Bridge/Doctrine/DataCollector/DoctrineDataCollector.php +++ b/src/Symfony/Bridge/Doctrine/DataCollector/DoctrineDataCollector.php @@ -119,7 +119,7 @@ class DoctrineDataCollector extends DataCollector return 'db'; } - private function sanitizeQueries(string $connectionName, array $queries) + private function sanitizeQueries(string $connectionName, array $queries): array { foreach ($queries as $i => $query) { $queries[$i] = $this->sanitizeQuery($connectionName, $query); @@ -128,7 +128,7 @@ class DoctrineDataCollector extends DataCollector return $queries; } - private function sanitizeQuery(string $connectionName, $query) + private function sanitizeQuery(string $connectionName, array $query): array { $query['explainable'] = true; if (null === $query['params']) { diff --git a/src/Symfony/Bridge/Monolog/Formatter/ConsoleFormatter.php b/src/Symfony/Bridge/Monolog/Formatter/ConsoleFormatter.php index aafe9e45e0..101c61f078 100644 --- a/src/Symfony/Bridge/Monolog/Formatter/ConsoleFormatter.php +++ b/src/Symfony/Bridge/Monolog/Formatter/ConsoleFormatter.php @@ -180,7 +180,7 @@ class ConsoleFormatter implements FormatterInterface return $record; } - private function dumpData($data, $colors = null) + private function dumpData($data, bool $colors = null): string { if (null === $this->dumper) { return ''; diff --git a/src/Symfony/Bridge/Twig/Command/LintCommand.php b/src/Symfony/Bridge/Twig/Command/LintCommand.php index 76106e1a90..536ca7bdbb 100644 --- a/src/Symfony/Bridge/Twig/Command/LintCommand.php +++ b/src/Symfony/Bridge/Twig/Command/LintCommand.php @@ -118,13 +118,13 @@ EOF throw new RuntimeException(sprintf('File or directory "%s" is not readable', $filename)); } - private function validate(string $template, $file) + private function validate(string $template, string $file): array { $realLoader = $this->twig->getLoader(); try { - $temporaryLoader = new ArrayLoader([(string) $file => $template]); + $temporaryLoader = new ArrayLoader([$file => $template]); $this->twig->setLoader($temporaryLoader); - $nodeTree = $this->twig->parse($this->twig->tokenize(new Source($template, (string) $file))); + $nodeTree = $this->twig->parse($this->twig->tokenize(new Source($template, $file))); $this->twig->compile($nodeTree); $this->twig->setLoader($realLoader); } catch (Error $e) { diff --git a/src/Symfony/Bundle/FrameworkBundle/CacheWarmer/AbstractPhpFileCacheWarmer.php b/src/Symfony/Bundle/FrameworkBundle/CacheWarmer/AbstractPhpFileCacheWarmer.php index c44c4137df..a626ff8b0f 100644 --- a/src/Symfony/Bundle/FrameworkBundle/CacheWarmer/AbstractPhpFileCacheWarmer.php +++ b/src/Symfony/Bundle/FrameworkBundle/CacheWarmer/AbstractPhpFileCacheWarmer.php @@ -72,7 +72,7 @@ abstract class AbstractPhpFileCacheWarmer implements CacheWarmerInterface /** * @internal */ - final protected function ignoreAutoloadException($class, \Exception $exception) + final protected function ignoreAutoloadException(string $class, \Exception $exception): void { try { ClassExistenceResource::throwOnRequiredClass($class, $exception); diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php index f87ef6120d..423ec2db67 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php @@ -1069,7 +1069,7 @@ class FrameworkExtension extends Extension /** * Returns a definition for an asset package. */ - private function createPackageDefinition(?string $basePath, array $baseUrls, Reference $version) + private function createPackageDefinition(?string $basePath, array $baseUrls, Reference $version): Definition { if ($basePath && $baseUrls) { throw new \LogicException('An asset package cannot have base URLs and base paths.'); @@ -1085,7 +1085,7 @@ class FrameworkExtension extends Extension return $package; } - private function createVersion(ContainerBuilder $container, ?string $version, ?string $format, ?string $jsonManifestPath, string $name) + private function createVersion(ContainerBuilder $container, ?string $version, ?string $format, ?string $jsonManifestPath, string $name): Reference { // Configuration prevents $version and $jsonManifestPath from being set if (null !== $version) { diff --git a/src/Symfony/Component/BrowserKit/Cookie.php b/src/Symfony/Component/BrowserKit/Cookie.php index ee786e69c2..6afdbd970e 100644 --- a/src/Symfony/Component/BrowserKit/Cookie.php +++ b/src/Symfony/Component/BrowserKit/Cookie.php @@ -199,7 +199,7 @@ class Cookie ); } - private static function parseDate($dateValue) + private static function parseDate(string $dateValue): ?string { // trim single quotes around date if present if (($length = \strlen($dateValue)) > 1 && "'" === $dateValue[0] && "'" === $dateValue[$length - 1]) { @@ -216,6 +216,8 @@ class Cookie if (false !== $date = date_create($dateValue, new \DateTimeZone('GMT'))) { return $date->format('U'); } + + return null; } /** diff --git a/src/Symfony/Component/Filesystem/Filesystem.php b/src/Symfony/Component/Filesystem/Filesystem.php index c1c9f699f2..f44a5d3fc5 100644 --- a/src/Symfony/Component/Filesystem/Filesystem.php +++ b/src/Symfony/Component/Filesystem/Filesystem.php @@ -740,7 +740,10 @@ class Filesystem return 2 === \count($components) ? [$components[0], $components[1]] : [null, $components[0]]; } - private static function box($func) + /** + * @return mixed + */ + private static function box(callable $func) { self::$lastError = null; set_error_handler(__CLASS__.'::handleError'); diff --git a/src/Symfony/Component/Form/Extension/Core/Type/FileType.php b/src/Symfony/Component/Form/Extension/Core/Type/FileType.php index 839795732f..52368293f4 100644 --- a/src/Symfony/Component/Form/Extension/Core/Type/FileType.php +++ b/src/Symfony/Component/Form/Extension/Core/Type/FileType.php @@ -246,8 +246,8 @@ class FileType extends AbstractType /** * This method should be kept in sync with Symfony\Component\Validator\Constraints\FileValidator::moreDecimalsThan(). */ - private static function moreDecimalsThan($double, $numberOfDecimals) + private static function moreDecimalsThan(string $double, int $numberOfDecimals): bool { - return \strlen((string) $double) > \strlen(round($double, $numberOfDecimals)); + return \strlen($double) > \strlen(round($double, $numberOfDecimals)); } } diff --git a/src/Symfony/Component/Form/FormFactoryBuilder.php b/src/Symfony/Component/Form/FormFactoryBuilder.php index d73b438b4b..f7644bb1f6 100644 --- a/src/Symfony/Component/Form/FormFactoryBuilder.php +++ b/src/Symfony/Component/Form/FormFactoryBuilder.php @@ -47,10 +47,7 @@ class FormFactoryBuilder implements FormFactoryBuilderInterface */ private $typeGuessers = []; - /** - * @param bool $forceCoreExtension - */ - public function __construct($forceCoreExtension = false) + public function __construct(bool $forceCoreExtension = false) { $this->forceCoreExtension = $forceCoreExtension; } diff --git a/src/Symfony/Component/Messenger/MessageBus.php b/src/Symfony/Component/Messenger/MessageBus.php index 5809a1fcbe..d6e0219013 100644 --- a/src/Symfony/Component/Messenger/MessageBus.php +++ b/src/Symfony/Component/Messenger/MessageBus.php @@ -39,7 +39,7 @@ class MessageBus implements MessageBusInterface private $middlewareHandlers; private $cachedIterator; - public function __construct($middlewareHandlers) + public function __construct(\Traversable $middlewareHandlers) { $this->middlewareHandlers = $middlewareHandlers; } diff --git a/src/Symfony/Component/PropertyAccess/PropertyAccessor.php b/src/Symfony/Component/PropertyAccess/PropertyAccessor.php index 6fe3dd87ac..14be8444b2 100644 --- a/src/Symfony/Component/PropertyAccess/PropertyAccessor.php +++ b/src/Symfony/Component/PropertyAccess/PropertyAccessor.php @@ -181,7 +181,7 @@ class PropertyAccessor implements PropertyAccessorInterface } } - private static function throwInvalidArgumentException($message, $trace, $i, $propertyPath) + private static function throwInvalidArgumentException(string $message, array $trace, int $i, string $propertyPath): void { // the type mismatch is not caused by invalid arguments (but e.g. by an incompatible return type hint of the writer method) if (0 !== strpos($message, 'Argument ')) { diff --git a/src/Symfony/Component/Security/Core/Authorization/AccessDecisionManager.php b/src/Symfony/Component/Security/Core/Authorization/AccessDecisionManager.php index 8509844f9a..5e5f321b94 100644 --- a/src/Symfony/Component/Security/Core/Authorization/AccessDecisionManager.php +++ b/src/Symfony/Component/Security/Core/Authorization/AccessDecisionManager.php @@ -66,7 +66,7 @@ class AccessDecisionManager implements AccessDecisionManagerInterface * If all voters abstained from voting, the decision will be based on the * allowIfAllAbstainDecisions property value (defaults to false). */ - private function decideAffirmative(TokenInterface $token, array $attributes, $object = null) + private function decideAffirmative(TokenInterface $token, array $attributes, $object = null): bool { $deny = 0; foreach ($this->voters as $voter) { @@ -106,7 +106,7 @@ class AccessDecisionManager implements AccessDecisionManagerInterface * If all voters abstained from voting, the decision will be based on the * allowIfAllAbstainDecisions property value (defaults to false). */ - private function decideConsensus(TokenInterface $token, array $attributes, $object = null) + private function decideConsensus(TokenInterface $token, array $attributes, $object = null): bool { $grant = 0; $deny = 0; @@ -147,7 +147,7 @@ class AccessDecisionManager implements AccessDecisionManagerInterface * If all voters abstained from voting, the decision will be based on the * allowIfAllAbstainDecisions property value (defaults to false). */ - private function decideUnanimous(TokenInterface $token, array $attributes, $object = null) + private function decideUnanimous(TokenInterface $token, array $attributes, $object = null): bool { $grant = 0; foreach ($this->voters as $voter) { diff --git a/src/Symfony/Component/Security/Http/RememberMe/AbstractRememberMeServices.php b/src/Symfony/Component/Security/Http/RememberMe/AbstractRememberMeServices.php index cf98bc7766..0d7ab4e8ae 100644 --- a/src/Symfony/Component/Security/Http/RememberMe/AbstractRememberMeServices.php +++ b/src/Symfony/Component/Security/Http/RememberMe/AbstractRememberMeServices.php @@ -22,6 +22,7 @@ use Symfony\Component\Security\Core\Exception\CookieTheftException; use Symfony\Component\Security\Core\Exception\UnsupportedUserException; use Symfony\Component\Security\Core\Exception\UsernameNotFoundException; use Symfony\Component\Security\Core\User\UserInterface; +use Symfony\Component\Security\Core\User\UserProviderInterface; use Symfony\Component\Security\Http\Logout\LogoutHandlerInterface; use Symfony\Component\Security\Http\ParameterBagUtils; @@ -221,7 +222,7 @@ abstract class AbstractRememberMeServices implements RememberMeServicesInterface */ abstract protected function onLoginSuccess(Request $request, Response $response, TokenInterface $token); - final protected function getUserProvider($class) + final protected function getUserProvider(string $class): UserProviderInterface { foreach ($this->userProviders as $provider) { if ($provider->supportsClass($class)) { diff --git a/src/Symfony/Component/Translation/Command/XliffLintCommand.php b/src/Symfony/Component/Translation/Command/XliffLintCommand.php index 465489c584..ad18912f2d 100644 --- a/src/Symfony/Component/Translation/Command/XliffLintCommand.php +++ b/src/Symfony/Component/Translation/Command/XliffLintCommand.php @@ -106,7 +106,7 @@ EOF return $this->display($io, $filesInfo); } - private function validate(string $content, $file = null) + private function validate(string $content, string $file = null): array { $errors = []; diff --git a/src/Symfony/Component/Validator/Constraints/FileValidator.php b/src/Symfony/Component/Validator/Constraints/FileValidator.php index 29c25b70bb..eb06c732ec 100644 --- a/src/Symfony/Component/Validator/Constraints/FileValidator.php +++ b/src/Symfony/Component/Validator/Constraints/FileValidator.php @@ -199,9 +199,9 @@ class FileValidator extends ConstraintValidator } } - private static function moreDecimalsThan($double, $numberOfDecimals) + private static function moreDecimalsThan(string $double, int $numberOfDecimals): bool { - return \strlen((string) $double) > \strlen(round($double, $numberOfDecimals)); + return \strlen($double) > \strlen(round($double, $numberOfDecimals)); } /** diff --git a/src/Symfony/Component/Workflow/Registry.php b/src/Symfony/Component/Workflow/Registry.php index fe0c7ef3ab..6118516e01 100644 --- a/src/Symfony/Component/Workflow/Registry.php +++ b/src/Symfony/Component/Workflow/Registry.php @@ -82,7 +82,11 @@ class Registry return $matched; } - private function supports(WorkflowInterface $workflow, $supportStrategy, $subject, $workflowName): bool + /** + * @param WorkflowSupportStrategyInterface $supportStrategy + * @param object $subject + */ + private function supports(WorkflowInterface $workflow, $supportStrategy, $subject, ?string $workflowName): bool { if (null !== $workflowName && $workflowName !== $workflow->getName()) { return false;