Skip to content

Commit

Permalink
minor #33770 Add types to constructors and private/final/internal met…
Browse files Browse the repository at this point in the history
…hods (Batch III) (derrabus)

This PR was squashed before being merged into the 4.4 branch (closes #33770).

Discussion
----------

Add types to constructors and private/final/internal methods (Batch III)

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | no
| New feature?  | no
| Deprecations? | no
| Tickets       | #32179, #33228
| License       | MIT
| Doc PR        | N/A

Followup to #33709, this time with:
* Validator
* VarDumper
* Workflow
* Yaml
* all bridges
* all bundles

That should be the final batch. 😃

Commits
-------

6493902 Add types to constructors and private/final/internal methods (Batch III)
  • Loading branch information
nicolas-grekas committed Oct 7, 2019
2 parents 1998814 + 6493902 commit 62216ea
Show file tree
Hide file tree
Showing 50 changed files with 122 additions and 120 deletions.
2 changes: 1 addition & 1 deletion src/Symfony/Bridge/Doctrine/Logger/DbalLogger.php
Expand Up @@ -71,7 +71,7 @@ protected function log($message, array $params)
$this->logger->debug($message, $params);
}

private function normalizeParams(array $params)
private function normalizeParams(array $params): array
{
foreach ($params as $index => $param) {
// normalize recursively
Expand Down
11 changes: 7 additions & 4 deletions src/Symfony/Bridge/Doctrine/Security/User/EntityUserProvider.php
Expand Up @@ -12,6 +12,9 @@
namespace Symfony\Bridge\Doctrine\Security\User;

use Doctrine\Common\Persistence\ManagerRegistry;
use Doctrine\Common\Persistence\Mapping\ClassMetadata;
use Doctrine\Common\Persistence\ObjectManager;
use Doctrine\Common\Persistence\ObjectRepository;
use Symfony\Component\Security\Core\Exception\UnsupportedUserException;
use Symfony\Component\Security\Core\Exception\UsernameNotFoundException;
use Symfony\Component\Security\Core\User\PasswordUpgraderInterface;
Expand Down Expand Up @@ -124,17 +127,17 @@ public function upgradePassword(UserInterface $user, string $newEncodedPassword)
}
}

private function getObjectManager()
private function getObjectManager(): ObjectManager
{
return $this->registry->getManager($this->managerName);
}

private function getRepository()
private function getRepository(): ObjectRepository
{
return $this->getObjectManager()->getRepository($this->classOrAlias);
}

private function getClass()
private function getClass(): string
{
if (null === $this->class) {
$class = $this->classOrAlias;
Expand All @@ -149,7 +152,7 @@ private function getClass()
return $this->class;
}

private function getClassMetadata()
private function getClassMetadata(): ClassMetadata
{
return $this->getObjectManager()->getClassMetadata($this->classOrAlias);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Bridge/Doctrine/Test/TestRepositoryFactory.php
Expand Up @@ -40,7 +40,7 @@ public function getRepository(EntityManagerInterface $entityManager, $entityName
return $this->repositoryList[$repositoryHash] = $this->createRepository($entityManager, $entityName);
}

public function setRepository(EntityManagerInterface $entityManager, $entityName, ObjectRepository $repository)
public function setRepository(EntityManagerInterface $entityManager, string $entityName, ObjectRepository $repository)
{
$repositoryHash = $this->getRepositoryHash($entityManager, $entityName);

Expand All @@ -56,7 +56,7 @@ private function createRepository(EntityManagerInterface $entityManager, string
return new $repositoryClassName($entityManager, $metadata);
}

private function getRepositoryHash(EntityManagerInterface $entityManager, string $entityName)
private function getRepositoryHash(EntityManagerInterface $entityManager, string $entityName): string
{
return $entityManager->getClassMetadata($entityName)->getName().spl_object_hash($entityManager);
}
Expand Down
Expand Up @@ -11,9 +11,11 @@

namespace Symfony\Bridge\Doctrine\Tests\Security\User;

use Doctrine\Common\Persistence\ObjectRepository;
use Doctrine\ORM\Tools\SchemaTool;
use PHPUnit\Framework\TestCase;
use Symfony\Bridge\Doctrine\Security\User\EntityUserProvider;
use Symfony\Bridge\Doctrine\Security\User\UserLoaderInterface;
use Symfony\Bridge\Doctrine\Test\DoctrineTestHelper;
use Symfony\Bridge\Doctrine\Tests\Fixtures\User;
use Symfony\Component\Security\Core\User\PasswordUpgraderInterface;
Expand Down Expand Up @@ -59,9 +61,7 @@ public function testLoadUserByUsernameWithUserLoaderRepositoryAndWithoutProperty
{
$user = new User(1, 1, 'user1');

$repository = $this->getMockBuilder('Symfony\Bridge\Doctrine\Security\User\UserLoaderInterface')
->disableOriginalConstructor()
->getMock();
$repository = $this->createMock([ObjectRepository::class, UserLoaderInterface::class]);
$repository
->expects($this->once())
->method('loadUserByUsername')
Expand Down Expand Up @@ -147,7 +147,7 @@ public function testSupportProxy()

public function testLoadUserByUserNameShouldLoadUserWhenProperInterfaceProvided()
{
$repository = $this->getMockBuilder('\Symfony\Bridge\Doctrine\Security\User\UserLoaderInterface')->getMock();
$repository = $this->createMock([ObjectRepository::class, UserLoaderInterface::class]);
$repository->expects($this->once())
->method('loadUserByUsername')
->with('name')
Expand All @@ -166,7 +166,7 @@ public function testLoadUserByUserNameShouldLoadUserWhenProperInterfaceProvided(
public function testLoadUserByUserNameShouldDeclineInvalidInterface()
{
$this->expectException('InvalidArgumentException');
$repository = $this->getMockBuilder('\Symfony\Component\Security\Core\User\AdvancedUserInterface')->getMock();
$repository = $this->createMock(ObjectRepository::class);

$provider = new EntityUserProvider(
$this->getManager($this->getObjectManager($repository)),
Expand All @@ -180,7 +180,7 @@ public function testPasswordUpgrades()
{
$user = new User(1, 1, 'user1');

$repository = $this->getMockBuilder(PasswordUpgraderInterface::class)->getMock();
$repository = $this->createMock([ObjectRepository::class, PasswordUpgraderInterface::class]);
$repository->expects($this->once())
->method('upgradePassword')
->with($user, 'foobar');
Expand Down
6 changes: 3 additions & 3 deletions src/Symfony/Bridge/Monolog/Formatter/ConsoleFormatter.php
Expand Up @@ -133,7 +133,7 @@ public function format(array $record)
/**
* @internal
*/
public function echoLine($line, $depth, $indentPad)
public function echoLine(string $line, int $depth, string $indentPad)
{
if (-1 !== $depth) {
fwrite($this->outputBuffer, $line);
Expand All @@ -143,7 +143,7 @@ public function echoLine($line, $depth, $indentPad)
/**
* @internal
*/
public function castObject($v, array $a, Stub $s, $isNested)
public function castObject($v, array $a, Stub $s, bool $isNested): array
{
if ($this->options['multiline']) {
return $a;
Expand All @@ -157,7 +157,7 @@ public function castObject($v, array $a, Stub $s, $isNested)
return $a;
}

private function replacePlaceHolder(array $record)
private function replacePlaceHolder(array $record): array
{
$message = $record['message'];

Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Bridge/Monolog/Handler/ServerLogHandler.php
Expand Up @@ -103,7 +103,7 @@ private function createSocket()
return $socket;
}

private function formatRecord(array $record)
private function formatRecord(array $record): string
{
if ($this->processors) {
foreach ($this->processors as $processor) {
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Bridge/Twig/Command/DebugCommand.php
Expand Up @@ -364,7 +364,7 @@ private function getMetadata(string $type, $entity)
return null;
}

private function getPrettyMetadata(string $type, $entity, bool $decorated)
private function getPrettyMetadata(string $type, $entity, bool $decorated): ?string
{
if ('tests' === $type) {
return '';
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Bridge/Twig/Command/LintCommand.php
Expand Up @@ -119,7 +119,7 @@ private function getStdin(): string
return $template;
}

private function getFilesInfo(array $filenames)
private function getFilesInfo(array $filenames): array
{
$filesInfo = [];
foreach ($filenames as $filename) {
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Bridge/Twig/Extension/CodeExtension.php
Expand Up @@ -236,7 +236,7 @@ public function formatFileFromText($text)
/**
* @internal
*/
public function formatLogMessage($message, array $context)
public function formatLogMessage(string $message, array $context): string
{
if ($context && false !== strpos($message, '{')) {
$replacements = [];
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Bridge/Twig/Extension/FormExtension.php
Expand Up @@ -111,7 +111,7 @@ public function getName()
*
* @see ChoiceView::isSelected()
*/
function twig_is_selected_choice(ChoiceView $choice, $selectedValue)
function twig_is_selected_choice(ChoiceView $choice, $selectedValue): bool
{
if (\is_array($selectedValue)) {
return \in_array($choice->value, $selectedValue, true);
Expand All @@ -123,7 +123,7 @@ function twig_is_selected_choice(ChoiceView $choice, $selectedValue)
/**
* @internal
*/
function twig_is_root_form(FormView $formView)
function twig_is_root_form(FormView $formView): bool
{
return null === $formView->parent;
}
Expand Down
Expand Up @@ -132,7 +132,7 @@ private function isNamedArguments(Node $arguments): bool
return false;
}

private function getVarName()
private function getVarName(): string
{
return sprintf('__internal_%s', hash('sha256', uniqid(mt_rand(), true), false));
}
Expand Down
6 changes: 3 additions & 3 deletions src/Symfony/Bridge/Twig/UndefinedCallableHandler.php
Expand Up @@ -65,7 +65,7 @@ class UndefinedCallableHandler
'workflow' => 'enable "framework.workflows"',
];

public static function onUndefinedFilter($name)
public static function onUndefinedFilter(string $name): bool
{
if (!isset(self::$filterComponents[$name])) {
return false;
Expand All @@ -76,7 +76,7 @@ public static function onUndefinedFilter($name)
return true;
}

public static function onUndefinedFunction($name)
public static function onUndefinedFunction(string $name): bool
{
if (!isset(self::$functionComponents[$name])) {
return false;
Expand All @@ -87,7 +87,7 @@ public static function onUndefinedFunction($name)
return true;
}

private static function onUndefined($name, $type, $component)
private static function onUndefined(string $name, string $type, string $component)
{
if (class_exists(FullStack::class) && isset(self::$fullStackEnable[$component])) {
throw new SyntaxError(sprintf('Did you forget to %s? Unknown %s "%s".', self::$fullStackEnable[$component], $type, $name));
Expand Down
Expand Up @@ -262,7 +262,7 @@ private function hardCopy(string $originDir, string $targetDir): string
return self::METHOD_COPY;
}

private function getPublicDirectory(ContainerInterface $container)
private function getPublicDirectory(ContainerInterface $container): string
{
$defaultPublicDir = 'public';

Expand Down
Expand Up @@ -238,7 +238,7 @@ protected function getContainerBuilder(): ContainerBuilder
return $this->containerBuilder = $container;
}

private function findProperServiceName(InputInterface $input, SymfonyStyle $io, ContainerBuilder $builder, string $name, bool $showHidden)
private function findProperServiceName(InputInterface $input, SymfonyStyle $io, ContainerBuilder $builder, string $name, bool $showHidden): string
{
$name = ltrim($name, '\\');

Expand All @@ -258,7 +258,7 @@ private function findProperServiceName(InputInterface $input, SymfonyStyle $io,
return $io->choice('Select one of the following services to display its information', $matchingServices);
}

private function findServiceIdsContaining(ContainerBuilder $builder, string $name, bool $showHidden)
private function findServiceIdsContaining(ContainerBuilder $builder, string $name, bool $showHidden): array
{
$serviceIds = $builder->getServiceIds();
$foundServiceIds = $foundServiceIdsIgnoringBackslashes = [];
Expand All @@ -280,7 +280,7 @@ private function findServiceIdsContaining(ContainerBuilder $builder, string $nam
/**
* @internal
*/
public function filterToServiceTypes($serviceId)
public function filterToServiceTypes(string $serviceId): bool
{
// filter out things that could not be valid class names
if (!preg_match('/(?(DEFINE)(?<V>[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*+))^(?&V)(?:\\\\(?&V))*+(?: \$(?&V))?$/', $serviceId)) {
Expand Down
Expand Up @@ -47,7 +47,7 @@ abstract class AbstractController implements ServiceSubscriberInterface
* @internal
* @required
*/
public function setContainer(ContainerInterface $container)
public function setContainer(ContainerInterface $container): ?ContainerInterface
{
$previous = $this->container;
$this->container = $container;
Expand Down
Expand Up @@ -13,6 +13,7 @@

@trigger_error('The '.RequestHelper::class.' class is deprecated since version 4.3 and will be removed in 5.0; use Twig instead.', E_USER_DEPRECATED);

use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\Templating\Helper\Helper;

Expand Down Expand Up @@ -57,7 +58,7 @@ public function getLocale()
return $this->getRequest()->getLocale();
}

private function getRequest()
private function getRequest(): Request
{
if (!$this->requestStack->getCurrentRequest()) {
throw new \LogicException('A Request must be available.');
Expand Down
Expand Up @@ -14,6 +14,7 @@
@trigger_error('The '.SessionHelper::class.' class is deprecated since version 4.3 and will be removed in 5.0; use Twig instead.', E_USER_DEPRECATED);

use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Component\Templating\Helper\Helper;

/**
Expand Down Expand Up @@ -61,7 +62,7 @@ public function hasFlash($name)
return $this->getSession()->getFlashBag()->has($name);
}

private function getSession()
private function getSession(): SessionInterface
{
if (null === $this->session) {
if (!$this->requestStack->getMasterRequest()) {
Expand Down
Expand Up @@ -93,7 +93,7 @@ public function __call(string $method, array $arguments)
return $this->$method(...$arguments);
}

public function setContainer(ContainerInterface $container)
public function setContainer(ContainerInterface $container): ?ContainerInterface
{
if (!$this->throwOnUnexpectedService) {
return parent::setContainer($container);
Expand Down
Expand Up @@ -182,12 +182,12 @@ private function createPasswordQuestion(): Question
})->setHidden(true)->setMaxAttempts(20);
}

private function generateSalt()
private function generateSalt(): string
{
return base64_encode(random_bytes(30));
}

private function getUserClass(InputInterface $input, SymfonyStyle $io)
private function getUserClass(InputInterface $input, SymfonyStyle $io): string
{
if (null !== $userClass = $input->getArgument('user-class')) {
return $userClass;
Expand Down
Expand Up @@ -60,7 +60,7 @@ public function __invoke(RequestEvent $event)
/**
* Proxies all method calls to the original listener.
*/
public function __call($method, $arguments)
public function __call(string $method, array $arguments)
{
return $this->listener->{$method}(...$arguments);
}
Expand Down
Expand Up @@ -89,7 +89,7 @@ public function addConfiguration(NodeDefinition $node)
}
}

final public function addOption($name, $default = null)
final public function addOption(string $name, $default = null)
{
$this->options[$name] = $default;
}
Expand Down
Expand Up @@ -92,7 +92,7 @@ public function create(ContainerBuilder $container, $id, $config, $userProvider,
return [$providerId, $listenerId, $entryPointId];
}

private function determineEntryPoint(?string $defaultEntryPointId, array $config)
private function determineEntryPoint(?string $defaultEntryPointId, array $config): string
{
if ($defaultEntryPointId) {
// explode if they've configured the entry_point, but there is already one
Expand Down

0 comments on commit 62216ea

Please sign in to comment.