Add types to private and final methods.

This commit is contained in:
Alexander M. Turek 2019-08-16 02:46:59 +02:00
parent ff63bb325d
commit 1b880677d4
16 changed files with 34 additions and 27 deletions

View File

@ -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']) {

View File

@ -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 '';

View File

@ -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) {

View File

@ -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);

View File

@ -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) {

View File

@ -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;
}
/**

View File

@ -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');

View File

@ -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));
}
}

View File

@ -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;
}

View File

@ -39,7 +39,7 @@ class MessageBus implements MessageBusInterface
private $middlewareHandlers;
private $cachedIterator;
public function __construct($middlewareHandlers)
public function __construct(\Traversable $middlewareHandlers)
{
$this->middlewareHandlers = $middlewareHandlers;
}

View File

@ -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 ')) {

View File

@ -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) {

View File

@ -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)) {

View File

@ -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 = [];

View File

@ -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));
}
/**

View File

@ -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;