Skip to content

Add types to private and final methods #33198

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 18, 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
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public function getName()
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);
Expand All @@ -128,7 +128,7 @@ private function sanitizeQueries(string $connectionName, array $queries)
return $queries;
}

private function sanitizeQuery(string $connectionName, $query)
private function sanitizeQuery(string $connectionName, array $query): array
{
$query['explainable'] = true;
if (null === $query['params']) {
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Bridge/Monolog/Formatter/ConsoleFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ private function replacePlaceHolder(array $record)
return $record;
}

private function dumpData($data, $colors = null)
private function dumpData($data, bool $colors = null): string
{
if (null === $this->dumper) {
return '';
Expand Down
6 changes: 3 additions & 3 deletions src/Symfony/Bridge/Twig/Command/LintCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,13 @@ protected function findFiles($filename)
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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ protected function warmUpPhpArrayAdapter(PhpArrayAdapter $phpArrayAdapter, array
/**
* @internal
*/
final protected function ignoreAutoloadException($class, \Exception $exception)
final protected function ignoreAutoloadException(string $class, \Exception $exception): void
{
try {
ClassExistenceResource::throwOnRequiredClass($class, $exception);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1069,7 +1069,7 @@ private function registerAssetsConfiguration(array $config, ContainerBuilder $co
/**
* 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.');
Expand All @@ -1085,7 +1085,7 @@ private function createPackageDefinition(?string $basePath, array $baseUrls, Ref
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) {
Expand Down
4 changes: 3 additions & 1 deletion src/Symfony/Component/BrowserKit/Cookie.php
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ public static function fromString($cookie, $url = null)
);
}

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]) {
Expand All @@ -216,6 +216,8 @@ private static function parseDate($dateValue)
if (false !== $date = date_create($dateValue, new \DateTimeZone('GMT'))) {
return $date->format('U');
}

return null;
}

/**
Expand Down
5 changes: 4 additions & 1 deletion src/Symfony/Component/Filesystem/Filesystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -740,7 +740,10 @@ private function getSchemeAndHierarchy(string $filename): array
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');
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/Form/Extension/Core/Type/FileType.php
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,8 @@ private function factorizeSizes(int $size, int $limit)
/**
* 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));
}
}
5 changes: 1 addition & 4 deletions src/Symfony/Component/Form/FormFactoryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Messenger/MessageBus.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function __construct(iterable $middlewareHandlers = [])
private $middlewareHandlers;
private $cachedIterator;

public function __construct($middlewareHandlers)
public function __construct(\Traversable $middlewareHandlers)
{
$this->middlewareHandlers = $middlewareHandlers;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/PropertyAccess/PropertyAccessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ public function setValue(&$objectOrArray, $propertyPath, $value)
}
}

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 ')) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public function decide(TokenInterface $token, array $attributes, $object = null)
* 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) {
Expand Down Expand Up @@ -106,7 +106,7 @@ private function decideAffirmative(TokenInterface $token, array $attributes, $ob
* 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;
Expand Down Expand Up @@ -147,7 +147,7 @@ private function decideConsensus(TokenInterface $token, array $attributes, $obje
* 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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
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;

Expand Down Expand Up @@ -221,7 +222,7 @@ protected function onLoginFail(Request $request, \Exception $exception = null)
*/
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)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
return $this->display($io, $filesInfo);
}

private function validate(string $content, $file = null)
private function validate(string $content, string $file = null): array
{
$errors = [];

Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/Validator/Constraints/FileValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,9 @@ public function validate($value, Constraint $constraint)
}
}

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

/**
Expand Down
6 changes: 5 additions & 1 deletion src/Symfony/Component/Workflow/Registry.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,11 @@ public function all($subject): array
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;
Expand Down