Skip to content

Add return types to internal|final|private methods #33255

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 20, 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
21 changes: 8 additions & 13 deletions src/Symfony/Bridge/Doctrine/Form/Type/DoctrineType.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Doctrine\Common\Collections\Collection;
use Doctrine\Common\Persistence\ManagerRegistry;
use Doctrine\Common\Persistence\ObjectManager;
use Doctrine\ORM\QueryBuilder;
use Symfony\Bridge\Doctrine\Form\ChoiceList\DoctrineChoiceLoader;
use Symfony\Bridge\Doctrine\Form\ChoiceList\EntityLoaderInterface;
use Symfony\Bridge\Doctrine\Form\ChoiceList\IdReader;
Expand Down Expand Up @@ -51,12 +52,10 @@ abstract class DoctrineType extends AbstractType implements ResetInterface
*
* @param object $choice The object
*
* @return string The string representation of the object
*
* @internal This method is public to be usable as callback. It should not
* be used in user code.
*/
public static function createChoiceLabel($choice)
public static function createChoiceLabel($choice): string
{
return (string) $choice;
}
Expand All @@ -73,12 +72,10 @@ public static function createChoiceLabel($choice)
* @param string $value The choice value. Corresponds to the object's
* ID here.
*
* @return string The field name
*
* @internal This method is public to be usable as callback. It should not
* be used in user code.
*/
public static function createChoiceName($choice, $key, $value)
public static function createChoiceName($choice, $key, $value): string
{
return str_replace('-', '_', (string) $value);
}
Expand All @@ -88,17 +85,15 @@ public static function createChoiceName($choice, $key, $value)
* For instance in ORM two query builders with an equal SQL string and
* equal parameters are considered to be equal.
*
* @param object $queryBuilder
*
* @return array|false Array with important QueryBuilder parts or false if
* they can't be determined
* @return array|null Array with important QueryBuilder parts or null if
* they can't be determined
*
* @internal This method is public to be usable as callback. It should not
* be used in user code.
*/
public function getQueryBuilderPartsForCachingHash($queryBuilder)
public function getQueryBuilderPartsForCachingHash(QueryBuilder $queryBuilder): ?array
{
return false;
return null;
}

public function __construct(ManagerRegistry $registry)
Expand Down Expand Up @@ -127,7 +122,7 @@ public function configureOptions(OptionsResolver $resolver)
// If there is no QueryBuilder we can safely cache DoctrineChoiceLoader,
// also if concrete Type can return important QueryBuilder parts to generate
// hash key we go for it as well
if (!$options['query_builder'] || false !== ($qbParts = $this->getQueryBuilderPartsForCachingHash($options['query_builder']))) {
if (!$options['query_builder'] || null !== $qbParts = $this->getQueryBuilderPartsForCachingHash($options['query_builder'])) {
$hash = CachingFactoryDecorator::generateHash([
$options['em'],
$options['class'],
Expand Down
6 changes: 1 addition & 5 deletions src/Symfony/Bridge/Doctrine/Form/Type/EntityType.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,10 @@ public function getBlockPrefix()
* We consider two query builders with an equal SQL string and
* equal parameters to be equal.
*
* @param QueryBuilder $queryBuilder
*
* @return array
*
* @internal This method is public to be usable as callback. It should not
* be used in user code.
*/
public function getQueryBuilderPartsForCachingHash($queryBuilder)
public function getQueryBuilderPartsForCachingHash(QueryBuilder $queryBuilder): ?array
{
return [
$queryBuilder->getQuery()->getSQL(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,8 @@ public function setFluentSafe(bool $fluentSafe)

/**
* {@inheritdoc}
*
* @return void
*/
public function generate(\ReflectionClass $originalClass, ClassGenerator $classGenerator)
public function generate(\ReflectionClass $originalClass, ClassGenerator $classGenerator): void
{
parent::generate($originalClass, $classGenerator);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@ public function __construct(string $salt = '')
/**
* {@inheritdoc}
*/
public function isProxyCandidate(Definition $definition)
public function isProxyCandidate(Definition $definition): bool
{
return ($definition->isLazy() || $definition->hasTag('proxy')) && $this->proxyGenerator->getProxifiedClass($definition);
}

/**
* {@inheritdoc}
*/
public function getProxyFactoryCode(Definition $definition, $id, $factoryCode = null)
public function getProxyFactoryCode(Definition $definition, $id, $factoryCode = null): string
{
$instantiation = 'return';

Expand Down Expand Up @@ -82,7 +82,7 @@ public function getProxyFactoryCode(Definition $definition, $id, $factoryCode =
/**
* {@inheritdoc}
*/
public function getProxyCode(Definition $definition)
public function getProxyCode(Definition $definition): string
{
$code = $this->classGenerator->generate($this->generateProxyClass($definition));

Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Bridge/Twig/Extension/RoutingExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public function getUrl($name, $parameters = [], $schemeRelative = false)
*
* @final
*/
public function isUrlGenerationSafe(Node $argsNode)
public function isUrlGenerationSafe(Node $argsNode): array
{
// support named arguments
$paramsNode = $argsNode->hasNode('parameters') ? $argsNode->getNode('parameters') : (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,15 @@ public function warmUp($cacheDir)
*
* @return bool always true
*/
public function isOptional()
public function isOptional(): bool
{
return true;
}

/**
* {@inheritdoc}
*/
public static function getSubscribedServices()
public static function getSubscribedServices(): array
{
return [
'router' => RouterInterface::class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,11 +213,9 @@ protected function validateInput(InputInterface $input)
/**
* Loads the ContainerBuilder from the cache.
*
* @return ContainerBuilder
*
* @throws \LogicException
*/
protected function getContainerBuilder()
protected function getContainerBuilder(): ContainerBuilder
{
if ($this->containerBuilder) {
return $this->containerBuilder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,23 +84,12 @@ public function describe(OutputInterface $output, $object, array $options = [])
}
}

/**
* Returns the output.
*
* @return OutputInterface The output
*/
protected function getOutput()
protected function getOutput(): OutputInterface
{
return $this->output;
}

/**
* Writes content to output.
*
* @param string $content
* @param bool $decorated
*/
protected function write($content, $decorated = false)
protected function write(string $content, bool $decorated = false)
{
$this->output->write($content, false, $decorated ? OutputInterface::OUTPUT_NORMAL : OutputInterface::OUTPUT_RAW);
}
Expand Down Expand Up @@ -182,10 +171,8 @@ abstract protected function describeCallable($callable, array $options = []);
* Formats a value as string.
*
* @param mixed $value
*
* @return string
*/
protected function formatValue($value)
protected function formatValue($value): string
{
if (\is_object($value)) {
return sprintf('object(%s)', \get_class($value));
Expand All @@ -202,10 +189,8 @@ protected function formatValue($value)
* Formats a parameter.
*
* @param mixed $value
*
* @return string
*/
protected function formatParameter($value)
protected function formatParameter($value): string
{
if (\is_bool($value) || \is_array($value) || (null === $value)) {
$jsonString = json_encode($value);
Expand Down Expand Up @@ -246,10 +231,8 @@ protected function resolveServiceDefinition(ContainerBuilder $builder, $serviceI

/**
* @param bool $showHidden
*
* @return array
*/
protected function findDefinitionsByTag(ContainerBuilder $builder, $showHidden)
protected function findDefinitionsByTag(ContainerBuilder $builder, $showHidden): array
{
$definitions = [];
$tags = $builder->findTags();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,7 @@ private function writeData(array $data, array $options)
$this->write(json_encode($data, $flags | JSON_PRETTY_PRINT)."\n");
}

/**
* @return array
*/
protected function getRouteData(Route $route)
protected function getRouteData(Route $route): array
{
$data = [
'path' => $route->getPath(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class RedirectableCompiledUrlMatcher extends CompiledUrlMatcher implements Redir
/**
* {@inheritdoc}
*/
public function redirect($path, $route, $scheme = null)
public function redirect($path, $route, $scheme = null): array
{
return [
'_controller' => 'Symfony\\Bundle\\FrameworkBundle\\Controller\\RedirectController::urlRedirectAction',
Expand Down
15 changes: 8 additions & 7 deletions src/Symfony/Bundle/FrameworkBundle/Test/TestContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace Symfony\Bundle\FrameworkBundle\Test;

use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Component\HttpKernel\KernelInterface;

/**
Expand Down Expand Up @@ -41,15 +42,15 @@ public function compile()
/**
* {@inheritdoc}
*/
public function isCompiled()
public function isCompiled(): bool
{
return $this->getPublicContainer()->isCompiled();
}

/**
* {@inheritdoc}
*/
public function getParameterBag()
public function getParameterBag(): ParameterBagInterface
{
return $this->getPublicContainer()->getParameterBag();
}
Expand All @@ -65,7 +66,7 @@ public function getParameter($name)
/**
* {@inheritdoc}
*/
public function hasParameter($name)
public function hasParameter($name): bool
{
return $this->getPublicContainer()->hasParameter($name);
}
Expand All @@ -89,7 +90,7 @@ public function set($id, $service)
/**
* {@inheritdoc}
*/
public function has($id)
public function has($id): bool
{
return $this->getPublicContainer()->has($id) || $this->getPrivateContainer()->has($id);
}
Expand All @@ -105,7 +106,7 @@ public function get($id, $invalidBehavior = /* self::EXCEPTION_ON_INVALID_REFERE
/**
* {@inheritdoc}
*/
public function initialized($id)
public function initialized($id): bool
{
return $this->getPublicContainer()->initialized($id);
}
Expand All @@ -121,15 +122,15 @@ public function reset()
/**
* {@inheritdoc}
*/
public function getServiceIds()
public function getServiceIds(): array
{
return $this->getPublicContainer()->getServiceIds();
}

/**
* {@inheritdoc}
*/
public function getRemovedIds()
public function getRemovedIds(): array
{
return $this->getPublicContainer()->getRemovedIds();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function onVoterVote(VoteEvent $event)
$this->traceableAccessDecisionManager->addVoterVote($event->getVoter(), $event->getAttributes(), $event->getVote());
}

public static function getSubscribedEvents()
public static function getSubscribedEvents(): array
{
return ['debug.security.authorization.vote' => 'onVoterVote'];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,8 @@ public function __construct(NonceGenerator $nonceGenerator)
* - The request - In case HTML content is fetched via AJAX and inserted in DOM, it must use the same nonce as origin
* - The response - A call to getNonces() has already been done previously. Same nonce are returned
* - They are otherwise randomly generated
*
* @return array
*/
public function getNonces(Request $request, Response $response)
public function getNonces(Request $request, Response $response): array
{
if ($request->headers->has('X-SymfonyProfiler-Script-Nonce') && $request->headers->has('X-SymfonyProfiler-Style-Nonce')) {
return [
Expand Down Expand Up @@ -83,7 +81,7 @@ public function disableCsp()
*
* @return array Nonces used by the bundle in Content-Security-Policy header
*/
public function updateResponseHeaders(Request $request, Response $response)
public function updateResponseHeaders(Request $request, Response $response): array
{
if ($this->cspDisabled) {
$this->removeCspHeaders($response);
Expand Down
5 changes: 1 addition & 4 deletions src/Symfony/Component/Cache/Traits/PdoTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -403,10 +403,7 @@ private function getConnection()
return $this->conn;
}

/**
* @return string
*/
private function getServerVersion()
private function getServerVersion(): string
{
if (null === $this->serverVersion) {
$conn = $this->conn instanceof \PDO ? $this->conn : $this->conn->getWrappedConnection();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,7 @@ public function __construct(Application $application, string $namespace = null,
$this->showHidden = $showHidden;
}

/**
* @return array
*/
public function getNamespaces()
public function getNamespaces(): array
{
if (null === $this->namespaces) {
$this->inspectApplication();
Expand All @@ -65,7 +62,7 @@ public function getNamespaces()
/**
* @return Command[]
*/
public function getCommands()
public function getCommands(): array
{
if (null === $this->commands) {
$this->inspectApplication();
Expand All @@ -75,13 +72,9 @@ public function getCommands()
}

/**
* @param string $name
*
* @return Command
*
* @throws CommandNotFoundException
*/
public function getCommand($name)
public function getCommand(string $name): Command
{
if (!isset($this->commands[$name]) && !isset($this->aliases[$name])) {
throw new CommandNotFoundException(sprintf('Command %s does not exist.', $name));
Expand Down
Loading