8000 Replace more docblocks by type-hints by nicolas-grekas · Pull Request #24722 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

Replace more docblocks by type-hints #24722

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
Nov 7, 2017
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Original file line number Diff line number Diff line change
Expand Up @@ -165,12 +165,8 @@ private function sanitizeQuery($connectionName, $query)
* The return value is an array with the sanitized value and a boolean
* indicating if the original value was kept (allowing to use the sanitized
* value to explain the query).
*
* @param mixed $var
*
* @return array
*/
private function sanitizeParam($var)
private function sanitizeParam($var): array
{
if (is_object($var)) {
$className = get_class($var);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@ class DoctrineValidationPass implements CompilerPassInterface
{
private $managerType;

/**
* @param string $managerType
*/
public function __construct($managerType)
public function __construct(string $managerType)
{
$this->managerType = $managerType;
}
Expand All @@ -43,12 +40,8 @@ public function process(ContainerBuilder $container)
/**
* Gets the validation mapping files for the format and extends them with
* files matching a doctrine search pattern (Resources/config/validation.orm.xml).
*
* @param ContainerBuilder $container
* @param string $mapping
* @param string $extension
*/
private function updateValidatorMappingFiles(ContainerBuilder $container, $mapping, $extension)
private function updateValidatorMappingFiles(ContainerBuilder $container, string $mapping, string $extension)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't this have void return typehint?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find void useless, so I didn't add any.
If you want to make it your battle, please do :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Method without void can mean two types of things - either it's return type void, or it's just not filled in or the actual return type is in DocBlock. That's a lot of "or"s :)

For me, it would make sense to add it if it were to be enforced by phpcs (method either has return type hint, or @return docblock). Is there a plan to enforce return typehints?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no plan I know about

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

{
if (!$container->hasParameter('validator.mapping.loader.'.$mapping.'_files_loader.mapping_files')) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class RegisterEventListenersAndSubscribersPass implements CompilerPassInterface
* manager's service ID for a connection name
* @param string $tagPrefix Tag prefix for listeners and subscribers
*/
public function __construct($connections, $managerTemplate, $tagPrefix)
public function __construct(string $connections, string $managerTemplate, string $tagPrefix)
{
$this->connections = $connections;
$this->managerTemplate = $managerTemplate;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ abstract class RegisterMappingsPass implements CompilerPassInterface
* register alias
* @param string[] $aliasMap Map of alias to namespace
*/
public function __construct($driver, array $namespaces, array $managerParameters, $driverPattern, $enabledParameter = false, $configurationPattern = '', $registerAliasMethodName = '', array $aliasMap = array())
public function __construct($driver, array $namespaces, array $managerParameters, string $driverPattern, $enabledParameter = false, string $configurationPattern = '', string $registerAliasMethodName = '', array $aliasMap = array())
{
$this->driver = $driver;
$this->namespaces = $namespaces;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class EntityFactory implements UserProviderFactoryInterface
private $key;
private $providerId;

public function __construct($key, $providerId)
public function __c 8000 onstruct(string $key, string $providerId)
{
$this->key = $key;
$this->providerId = $providerId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use Doctrine\Common\Persistence\ObjectManager;
use Symfony\Component\Form\ChoiceList\ArrayChoiceList;
use Symfony\Component\Form\ChoiceList\ChoiceListInterface;
use Symfony\Component\Form\ChoiceList\Factory\ChoiceListFactoryInterface;
use Symfony\Component\Form\ChoiceList\Loader\ChoiceLoaderInterface;

/**
Expand Down Expand Up @@ -45,9 +44,8 @@ class DoctrineChoiceLoader implements ChoiceLoaderInterface
* @param string $class The class name of the loaded objects
* @param IdReader $idReader The reader for the object IDs
* @param null|EntityLoaderInterface $objectLoader The objects loader
* @param ChoiceListFactoryInterface $factory The factory for creating the loaded choice list
*/
public function __construct(ObjectManager $manager, $class, $idReader = null, $objectLoader = null, $factory = null)
public function __construct(ObjectManager $manager, string $class, IdReader $idReader = null, EntityLoaderInterface $objectLoader = null)
{
$classMetadata = $manager->getClassMetadata($class);

Expand Down
14 changes: 4 additions & 10 deletions src/Symfony/Bridge/Doctrine/PropertyInfo/DoctrineExtractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,13 +157,9 @@ public function getTypes($class, $property, array $context = array())
/**
* Determines whether an association is nullable.
*
* @param array $associationMapping
*
* @return bool
*
* @see https://github.com/doctrine/doctrine2/blob/v2.5.4/lib/Doctrine/ORM/Tools/EntityGenerator.php#L1221-L1246
*/
private function isAssociationNullable(array $associationMapping)
private function isAssociationNullable(array $associationMapping): bool
{
if (isset($associationMapping['id']) && $associationMapping['id']) {
return false;
Expand All @@ -185,12 +181,8 @@ private function isAssociationNullable(array $associationMapping)

/**
* Gets the corresponding built-in PHP type.
*
* @param string $doctrineType
*
* @return string|null
*/
private function getPhpType($doctrineType)
private function getPhpType(string $doctrineType): ?string
{
switch ($doctrineType) {
case DBALType::SMALLINT:
Expand All @@ -217,5 +209,7 @@ private function getPhpType($doctrineType)
case DBALType::OBJECT:
return Type::BUILTIN_TYPE_OBJECT;
}

return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class EntityUserProvider implements UserProviderInterface
private $class;
private $property;

public function __construct(ManagerRegistry $registry, $classOrAlias, $property = null, $managerName = null)
public function __construct(ManagerRegistry $registry, string $classOrAlias, string $property = null, string $managerName = null)
{
$this->registry = $registry;
$this->managerName = $managerName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,12 +187,9 @@ public function providerBasicDrivers()
}

/**
* @param string $class
* @param array $config
*
* @dataProvider providerBasicDrivers
*/
public function testLoadBasicCacheDriver($class, array $config, array $expectedCalls = array())
public function testLoadBasicCacheDriver(string $class, array $config, array $expectedCalls = array())
{
$container = $this->createContainer();
$cacheName = 'metadata_cache';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@ class StringWrapper
{
private $string;

/**
* @param string $string
*/
public function __construct($string = null)
public function __construct(string $string = null)
{
$this->string = $string;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Bridge/Monolog/Handler/ConsoleHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class ConsoleHandler extends AbstractProcessingHandler implements EventSubscribe
* @param array $verbosityLevelMap Array that maps the OutputInterface verbosity to a minimum logging
* level (leave empty to use the default mapping)
*/
public function __construct(OutputInterface $output = null, $bubble = true, array $verbosityLevelMap = array())
public function __construct(OutputInterface $output = null, bool $bubble = true, array $verbosityLevelMap = array())
{
parent::__construct(Logger::DEBUG, $bubble);
$this->output = $output;
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Bridge/Monolog/Handler/ServerLogHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class ServerLogHandler extends AbstractHandler
private $context;
private $socket;

public function __construct($host, $level = Logger::DEBUG, $bubble = true, $context = array())
public function __construct(string $host, int $level = Logger::DEBUG, bool $bubble = true, array $context = array())
{
parent::__construct($level, $bubble);

Expand Down
13 changes: 2 additions & 11 deletions src/Symfony/Bridge/Monolog/Tests/Processor/WebProcessorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,7 @@ public function testCanBeConstructedWithExtraFields()
$this->assertEquals($server['HTTP_REFERER'], $record['extra']['referrer']);
}

/**
* @return array
*/
private function createRequestEvent($additionalServerParameters = array())
private function createRequestEvent($additionalServerParameters = array()): array
{
$server = array_merge(
array(
Expand Down Expand Up @@ -101,13 +98,7 @@ private function createRequestEvent($additionalServerParameters = array())
return array($event, $server);
}

/**
* @param int $level
* @param string $message
*
* @return array Record
*/
private function getRecord($level = Logger::WARNING, $message = 'test')
private function getRecord(int $level = Logger::WARNING, string $message = 'test'): array
{
return array(
'message' => $message,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,7 @@ class ProxyDumper implements DumperInterface
private $proxyGenerator;
private $classGenerator;

/**
* @param string $salt
*/
public function __construct($salt = '')
public function __construct(string $salt = '')
{
$this->salt = $salt;
$this->proxyGenerator = new LazyLoadingValueHolderGenerator();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,8 @@ protected function setUp()

/**
* @dataProvider getProxyCandidates
*
* @param Definition $definition
* @param bool $expected
*/
public function testIsProxyCandidate(Definition $definition, $expected)
public function testIsProxyCandidate(Definition $definition, bool $expected)
{
$this->assertSame($expected, $this->dumper->isProxyCandidate($definition));
}
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Bridge/Twig/Command/DebugCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class DebugCommand extends Command
private $twig;
private $projectDir;

public function __construct(Environment $twig, $projectDir = null)
public function __construct(Environment $twig, string $projectDir = null)
{
parent::__construct();

Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Bridge/Twig/Extension/CodeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class CodeExtension extends AbstractExtension
* @param string $rootDir The project root directory
* @param string $charset The charset
*/
public function __construct($fileLinkFormat, $rootDir, $charset)
public function __construct($fileLinkFormat, string $rootDir, string $charset)
{
$this->fileLinkFormat = $fileLinkFormat ?: ini_get('xdebug.file_link_format') ?: get_cfg_var('xdebug.file_link_format');
$this->rootDir = str_replace('/', DIRECTORY_SEPARATOR, dirname($rootDir)).DIRECTORY_SEPARATOR;
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Bridge/Twig/Extension/StopwatchExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class StopwatchExtension extends AbstractExtension
private $stopwatch;
private $enabled;

public function __construct(Stopwatch $stopwatch = null, $enabled = true)
public function __construct(Stopwatch $stopwatch = null, bool $enabled = true)
{
$this->stopwatch = $stopwatch;
$this->enabled = $enabled;
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Bridge/Twig/Node/DumpNode.php
10000
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class DumpNode extends Node
{
private $varPrefix;

public function __construct($varPrefix, Node $values = null, $lineno, $tag = null)
public function __construct($varPrefix, Node $values = null, int $lineno, string $tag = null)
{
$nodes = array();
if (null !== $values) {
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Bridge/Twig/Node/FormThemeNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
*/
class FormThemeNode extends Node
{
public function __construct(Node $form, Node $resources, $lineno, $tag = null, $only = false)
public function __construct(Node $form, Node $resources, int $lineno, string $tag = null, bool $only = false)
{
parent::__construct(array('form' => $form, 'resources' => $resources), array('only' => (bool) $only), $lineno, $tag);
parent::__construct(array('form' => $form, 'resources' => $resources), array('only' => $only), $lineno, $tag);
}

public function compile(Compiler $compiler)
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Bridge/Twig/Node/StopwatchNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
*/
class StopwatchNode extends Node
{
public function __construct(Node $name, Node $body, AssignNameExpression $var, $lineno = 0, $tag = null)
public function __construct(Node $name, Node $body, AssignNameExpression $var, int $lineno = 0, string $tag = null)
{
parent::__construct(array('body' => $body, 'name' => $name, 'var' => $var), array(), $lineno, $tag);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Bridge/Twig/Node/TransDefaultDomainNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*/
class TransDefaultDomainNode extends Node
{
public function __construct(AbstractExpression $expr, $lineno = 0, $tag = null)
public function __construct(AbstractExpression $expr, int $lineno = 0, string $tag = null)
{
parent::__construct(array('expr' => $expr), array(), $lineno, $tag);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Bridge/Twig/Node/TransNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class_exists('Twig\Node\Expression\ArrayExpression');
*/
class TransNode extends Node
{
public function __construct(Node $body, Node $domain = null, AbstractExpression $count = null, AbstractExpression $vars = null, AbstractExpression $locale = null, $lineno = 0, $tag = null)
public function __construct(Node $body, Node $domain = null, AbstractExpression $count = null, AbstractExpression $vars = null, AbstractExpression $locale = null, int $lineno = 0, string $tag = null)
{
$nodes = array('body' => $body);
if (null !== $domain) {
Expand Down
15 changes: 3 additions & 12 deletions src/Symfony/Bridge/Twig/NodeVisitor/TranslationNodeVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,29 +103,20 @@ public function getPriority()
return 0;
}

/**
* @param Node $arguments
* @param int $index
*
* @return string|null
*/
private function getReadDomainFromArguments(Node $arguments, $index)
private function getReadDomainFromArguments(Node $arguments, int $index): ?string
{
if ($arguments->hasNode('domain')) {
$argument = $arguments->getNode('domain');
} elseif ($arguments->hasNode($index)) {
$argument = $arguments->getNode($index);
} else {
return;
return null;
}

return $this->getReadDomainFromNode($argument);
}

/**
* @return string|null
*/
private function getReadDomainFromNode(Node $node)
private function getReadDomainFromNode(Node $node): ?string
{
if ($node instanceof ConstantExpression) {
return $node->getAttribute('value');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class StopwatchTokenParser extends AbstractTokenParser
{
protected $stopwatchIsAvailable;

public function __construct($stopwatchIsAvailable)
public function __construct(bool $stopwatchIsAvailable)
{
$this->stopwatchIsAvailable = $stopwatchIsAvailable;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ abstract class AbstractPhpFileCacheWarmer implements CacheWarmerInterface
* @param string $phpArrayFile The PHP file where metadata are cached
* @param CacheItemPoolInterface $fallbackPool The pool where runtime-discovered metadata are cached
*/
public function __construct($phpArrayFile, CacheItemPoolInterface $fallbackPool)
public function __construct(string $phpArrayFile, CacheItemPoolInterface $fallbackPool)
{
$this->phpArrayFile = $phpArrayFile;
if (!$fallbackPool instanceof AdapterInterface) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class AnnotationsCacheWarmer extends AbstractPhpFileCacheWarmer
* @param string $phpArrayFile The PHP file where annotations are cached
* @param CacheItemPoolInterface $fallbackPool The pool where runtime-discovered annotations are cached
*/
public function __construct(Reader $annotationReader, $phpArrayFile, CacheItemPoolInterface $fallbackPool)
public function __construct(Reader $annotationReader, string $phpArrayFile, CacheItemPoolInterface $fallbackPool)
{
parent::__construct($phpArrayFile, $fallbackPool);
$this->annotationReader = $annotationReader;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class SerializerCacheWarmer extends AbstractPhpFileCacheWarmer
* @param string $phpArrayFile The PHP file where metadata are cached
* @param CacheItemPoolInterface $fallbackPool The pool where runtime-discovered metadata are cached
*/
public function __construct(array $loaders, $phpArrayFile, CacheItemPoolInterface $fallbackPool)
public function __construct(array $loaders, string $phpArrayFile, CacheItemPoolInterface $fallbackPool)
{
parent::__construct($phpArrayFile, $fallbackPool);
$this->loaders = $loaders;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class TemplateFinder implements TemplateFinderInterface
* @param TemplateNameParserInterface $parser A TemplateNameParserInterface instance
* @param string $rootDir The directory where global templates can be stored
*/
public function __construct(KernelInterface $kernel, TemplateNameParserInterface $parser, $rootDir)
public function __construct(KernelInterface $kernel, TemplateNameParserInterface $parser, string $rootDir)
{
$this->kernel = $kernel;
$this->parser = $parser;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class ValidatorCacheWarmer extends AbstractPhpFileCacheWarmer
* @param string $phpArrayFile The PHP file where metadata are cached
* @param CacheItemPoolInterface $fallbackPool The pool where runtime-discovered metadata are cached
*/
public function __construct(ValidatorBuilderInterface $validatorBuilder, $phpArrayFile, CacheItemPoolInterface $fallbackPool)
public function __construct(ValidatorBuilderInterface $validatorBuilder, string $phpArrayFile, CacheItemPoolInterface $fallbackPool)
{
parent::__construct($phpArrayFile, $fallbackPool);
$this->validatorBuilder = $validatorBuilder;
Expand Down
Loading
0