add parameter type declarations where possible

This commit is contained in:
Christian Flothmann 2019-07-27 07:55:12 +02:00
parent 1cc7067cc1
commit 26634645d3
23 changed files with 66 additions and 146 deletions

View File

@ -44,7 +44,7 @@ class ProxyCacheWarmer implements CacheWarmerInterface
/**
* {@inheritdoc}
*/
public function warmUp($cacheDir)
public function warmUp(string $cacheDir)
{
foreach ($this->registry->getManagers() as $em) {
// we need the directory no matter the proxy cache generation strategy

View File

@ -129,10 +129,7 @@ class ContainerAwareEventManager extends EventManager
}
}
/**
* @param string $eventName
*/
private function initializeListeners($eventName)
private function initializeListeners(string $eventName)
{
foreach ($this->listeners[$eventName] as $hash => $listener) {
if (\is_string($listener)) {

View File

@ -44,11 +44,8 @@ class DoctrineDataCollector extends DataCollector
/**
* Adds the stack logger for a connection.
*
* @param string $name
* @param DebugStack $logger
*/
public function addLogger($name, DebugStack $logger)
public function addLogger(string $name, DebugStack $logger)
{
$this->loggers[$name] = $logger;
}
@ -120,7 +117,7 @@ class DoctrineDataCollector extends DataCollector
return 'db';
}
private function sanitizeQueries($connectionName, $queries)
private function sanitizeQueries(string $connectionName, array $queries)
{
foreach ($queries as $i => $query) {
$queries[$i] = $this->sanitizeQuery($connectionName, $query);
@ -129,7 +126,7 @@ class DoctrineDataCollector extends DataCollector
return $queries;
}
private function sanitizeQuery($connectionName, $query)
private function sanitizeQuery(string $connectionName, $query)
{
$query['explainable'] = true;
if (null === $query['params']) {

View File

@ -101,11 +101,8 @@ abstract class AbstractDoctrineExtension extends Extension
* Register the alias for this mapping driver.
*
* Aliases can be used in the Query languages of all the Doctrine object managers to simplify writing tasks.
*
* @param array $mappingConfig
* @param string $mappingName
*/
protected function setMappingDriverAlias($mappingConfig, $mappingName)
protected function setMappingDriverAlias(array $mappingConfig, string $mappingName)
{
if (isset($mappingConfig['alias'])) {
$this->aliasMap[$mappingConfig['alias']] = $mappingConfig['prefix'];
@ -117,12 +114,9 @@ abstract class AbstractDoctrineExtension extends Extension
/**
* Register the mapping driver configuration for later use with the object managers metadata driver chain.
*
* @param array $mappingConfig
* @param string $mappingName
*
* @throws \InvalidArgumentException
*/
protected function setMappingDriverConfig(array $mappingConfig, $mappingName)
protected function setMappingDriverConfig(array $mappingConfig, string $mappingName)
{
$mappingDirectory = $mappingConfig['dir'];
if (!is_dir($mappingDirectory)) {
@ -171,11 +165,8 @@ abstract class AbstractDoctrineExtension extends Extension
/**
* Register all the collected mapping information with the object manager by registering the appropriate mapping drivers.
*
* @param array $objectManager
* @param ContainerBuilder $container A ContainerBuilder instance
*/
protected function registerMappingDrivers($objectManager, ContainerBuilder $container)
protected function registerMappingDrivers(array $objectManager, ContainerBuilder $container)
{
// configure metadata driver for each bundle based on the type of mapping files found
if ($container->hasDefinition($this->getObjectManagerElementName($objectManager['name'].'_metadata_driver'))) {
@ -225,12 +216,9 @@ abstract class AbstractDoctrineExtension extends Extension
/**
* Assertion if the specified mapping information is valid.
*
* @param array $mappingConfig
* @param string $objectManagerName
*
* @throws \InvalidArgumentException
*/
protected function assertValidMappingConfiguration(array $mappingConfig, $objectManagerName)
protected function assertValidMappingConfiguration(array $mappingConfig, string $objectManagerName)
{
if (!$mappingConfig['type'] || !$mappingConfig['dir'] || !$mappingConfig['prefix']) {
throw new \InvalidArgumentException(sprintf('Mapping definitions for Doctrine manager "%s" require at least the "type", "dir" and "prefix" options.', $objectManagerName));
@ -252,12 +240,9 @@ abstract class AbstractDoctrineExtension extends Extension
/**
* Detects what metadata driver to use for the supplied directory.
*
* @param string $dir A directory path
* @param ContainerBuilder $container A ContainerBuilder instance
*
* @return string|null A metadata driver short name, if one can be detected
*/
protected function detectMetadataDriver($dir, ContainerBuilder $container)
protected function detectMetadataDriver(string $dir, ContainerBuilder $container)
{
$configPath = $this->getMappingResourceConfigDirectory();
$extension = $this->getMappingResourceExtension();
@ -286,13 +271,9 @@ abstract class AbstractDoctrineExtension extends Extension
/**
* Loads a configured object manager metadata, query or result cache driver.
*
* @param array $objectManager A configured object manager
* @param ContainerBuilder $container A ContainerBuilder instance
* @param string $cacheName
*
* @throws \InvalidArgumentException in case of unknown driver type
*/
protected function loadObjectManagerCacheDriver(array $objectManager, ContainerBuilder $container, $cacheName)
protected function loadObjectManagerCacheDriver(array $objectManager, ContainerBuilder $container, string $cacheName)
{
$this->loadCacheDriver($cacheName, $objectManager['name'], $objectManager[$cacheName.'_driver'], $container);
}
@ -300,16 +281,11 @@ abstract class AbstractDoctrineExtension extends Extension
/**
* Loads a cache driver.
*
* @param string $cacheName The cache driver name
* @param string $objectManagerName The object manager name
* @param array $cacheDriver The cache driver mapping
* @param ContainerBuilder $container The ContainerBuilder instance
*
* @return string
*
* @throws \InvalidArgumentException
*/
protected function loadCacheDriver($cacheName, $objectManagerName, array $cacheDriver, ContainerBuilder $container)
protected function loadCacheDriver(string $cacheName, string $objectManagerName, array $cacheDriver, ContainerBuilder $container)
{
$cacheDriverServiceId = $this->getObjectManagerElementName($objectManagerName.'_'.$cacheName);
@ -412,11 +388,9 @@ abstract class AbstractDoctrineExtension extends Extension
*
* @example $name is 'entity_manager' then the result would be 'doctrine.orm.entity_manager'
*
* @param string $name
*
* @return string
*/
abstract protected function getObjectManagerElementName($name);
abstract protected function getObjectManagerElementName(string $name);
/**
* Noun that describes the mapped objects such as Entity or Document.

View File

@ -109,7 +109,7 @@ class RegisterEventListenersAndSubscribersPass implements CompilerPassInterface
}
}
private function getEventManagerDef(ContainerBuilder $container, $name)
private function getEventManagerDef(ContainerBuilder $container, string $name)
{
if (!isset($this->eventManagers[$name])) {
$this->eventManagers[$name] = $container->getDefinition(sprintf($this->managerTemplate, $name));
@ -128,12 +128,9 @@ class RegisterEventListenersAndSubscribersPass implements CompilerPassInterface
* @see https://bugs.php.net/bug.php?id=53710
* @see https://bugs.php.net/bug.php?id=60926
*
* @param string $tagName
* @param ContainerBuilder $container
*
* @return array
*/
private function findAndSortTags($tagName, ContainerBuilder $container)
private function findAndSortTags(string $tagName, ContainerBuilder $container)
{
$sortedTags = [];

View File

@ -33,7 +33,7 @@ class EntityFactory implements UserProviderFactoryInterface
$this->providerId = $providerId;
}
public function create(ContainerBuilder $container, $id, $config)
public function create(ContainerBuilder $container, string $id, array $config)
{
$container
->setDefinition($id, new ChildDefinition($this->providerId))

View File

@ -62,7 +62,7 @@ class DoctrineChoiceLoader implements ChoiceLoaderInterface
/**
* {@inheritdoc}
*/
public function loadChoiceList($value = null)
public function loadChoiceList(callable $value = null)
{
if ($this->choiceList) {
return $this->choiceList;
@ -78,7 +78,7 @@ class DoctrineChoiceLoader implements ChoiceLoaderInterface
/**
* {@inheritdoc}
*/
public function loadValuesForChoices(array $choices, $value = null)
public function loadValuesForChoices(array $choices, callable $value = null)
{
// Performance optimization
if (empty($choices)) {
@ -110,7 +110,7 @@ class DoctrineChoiceLoader implements ChoiceLoaderInterface
/**
* {@inheritdoc}
*/
public function loadChoicesForValues(array $values, $value = null)
public function loadChoicesForValues(array $values, callable $value = null)
{
// Performance optimization
// Also prevents the generation of "WHERE id IN ()" queries through the

View File

@ -28,12 +28,7 @@ interface EntityLoaderInterface
/**
* Returns an array of entities matching the given identifiers.
*
* @param string $identifier The identifier field of the object. This method
* is not applicable for fields with multiple
* identifiers.
* @param array $values The values of the identifiers
*
* @return array The entities
*/
public function getEntitiesByIds($identifier, array $values);
public function getEntitiesByIds(string $identifier, array $values);
}

View File

@ -84,11 +84,9 @@ class IdReader
*
* This method assumes that the object has a single-column ID.
*
* @param object $object The object
*
* @return mixed The ID value
*/
public function getIdValue($object)
public function getIdValue(object $object = null)
{
if (!$object) {
return;

View File

@ -53,7 +53,7 @@ class ORMQueryBuilderLoader implements EntityLoaderInterface
/**
* {@inheritdoc}
*/
public function getEntitiesByIds($identifier, array $values)
public function getEntitiesByIds(string $identifier, array $values)
{
$qb = clone $this->queryBuilder;
$alias = current($qb->getRootAliases());

View File

@ -36,7 +36,7 @@ class DoctrineOrmTypeGuesser implements FormTypeGuesserInterface
/**
* {@inheritdoc}
*/
public function guessType($class, $property)
public function guessType(string $class, string $property)
{
if (!$ret = $this->getMetadata($class)) {
return new TypeGuess('Symfony\Component\Form\Extension\Core\Type\TextType', [], Guess::LOW_CONFIDENCE);
@ -94,7 +94,7 @@ class DoctrineOrmTypeGuesser implements FormTypeGuesserInterface
/**
* {@inheritdoc}
*/
public function guessRequired($class, $property)
public function guessRequired(string $class, string $property)
{
$classMetadatas = $this->getMetadata($class);
@ -132,7 +132,7 @@ class DoctrineOrmTypeGuesser implements FormTypeGuesserInterface
/**
* {@inheritdoc}
*/
public function guessMaxLength($class, $property)
public function guessMaxLength(string $class, string $property)
{
$ret = $this->getMetadata($class);
if ($ret && isset($ret[0]->fieldMappings[$property]) && !$ret[0]->hasAssociation($property)) {
@ -151,7 +151,7 @@ class DoctrineOrmTypeGuesser implements FormTypeGuesserInterface
/**
* {@inheritdoc}
*/
public function guessPattern($class, $property)
public function guessPattern(string $class, string $property)
{
$ret = $this->getMetadata($class);
if ($ret && isset($ret[0]->fieldMappings[$property]) && !$ret[0]->hasAssociation($property)) {
@ -161,7 +161,7 @@ class DoctrineOrmTypeGuesser implements FormTypeGuesserInterface
}
}
protected function getMetadata($class)
protected function getMetadata(string $class)
{
// normalize class name
$class = self::getRealClass(ltrim($class, '\\'));

View File

@ -14,6 +14,7 @@ namespace Symfony\Bridge\Doctrine\Form\Type;
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;
@ -49,14 +50,12 @@ abstract class DoctrineType extends AbstractType implements ResetInterface
*
* For backwards compatibility, objects are cast to strings by default.
*
* @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(object $choice)
{
return (string) $choice;
}
@ -68,17 +67,16 @@ abstract class DoctrineType extends AbstractType implements ResetInterface
* a single-column integer ID. In that case, the value of the field is
* the ID of the object. That ID is also used as field name.
*
* @param object $choice The object
* @param int|string $key The choice key
* @param string $value The choice value. Corresponds to the object's
* ID here.
* @param int|string $key The choice key
* @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(object $choice, $key, string $value)
{
return str_replace('-', '_', (string) $value);
}
@ -88,15 +86,13 @@ abstract class DoctrineType extends AbstractType implements ResetInterface
* 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
*
* @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)
{
return false;
}
@ -265,13 +261,9 @@ abstract class DoctrineType extends AbstractType implements ResetInterface
/**
* Return the default loader object.
*
* @param ObjectManager $manager
* @param mixed $queryBuilder
* @param string $class
*
* @return EntityLoaderInterface
*/
abstract public function getLoader(ObjectManager $manager, $queryBuilder, $class);
abstract public function getLoader(ObjectManager $manager, QueryBuilder $queryBuilder, string $class);
public function getParent()
{

View File

@ -46,13 +46,9 @@ class EntityType extends DoctrineType
/**
* Return the default loader object.
*
* @param ObjectManager $manager
* @param QueryBuilder $queryBuilder
* @param string $class
*
* @return ORMQueryBuilderLoader
*/
public function getLoader(ObjectManager $manager, $queryBuilder, $class)
public function getLoader(ObjectManager $manager, QueryBuilder $queryBuilder, string $class)
{
return new ORMQueryBuilderLoader($queryBuilder);
}
@ -69,14 +65,12 @@ class EntityType extends DoctrineType
* 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)
{
return [
$queryBuilder->getQuery()->getSQL(),

View File

@ -58,11 +58,8 @@ class DbalLogger implements SQLLogger
/**
* Logs a message.
*
* @param string $message A message to log
* @param array $params The context
*/
protected function log($message, array $params)
protected function log(string $message, array $params)
{
$this->logger->debug($message, $params);
}

View File

@ -40,7 +40,7 @@ class DoctrineExtractor implements PropertyListExtractorInterface, PropertyTypeE
/**
* {@inheritdoc}
*/
public function getProperties($class, array $context = [])
public function getProperties(string $class, array $context = [])
{
if (null === $metadata = $this->getMetadata($class)) {
return null;
@ -62,7 +62,7 @@ class DoctrineExtractor implements PropertyListExtractorInterface, PropertyTypeE
/**
* {@inheritdoc}
*/
public function getTypes($class, $property, array $context = [])
public function getTypes(string $class, string $property, array $context = [])
{
if (null === $metadata = $this->getMetadata($class)) {
return null;
@ -162,7 +162,7 @@ class DoctrineExtractor implements PropertyListExtractorInterface, PropertyTypeE
/**
* {@inheritdoc}
*/
public function isReadable($class, $property, array $context = [])
public function isReadable(string $class, string $property, array $context = [])
{
return null;
}
@ -170,7 +170,7 @@ class DoctrineExtractor implements PropertyListExtractorInterface, PropertyTypeE
/**
* {@inheritdoc}
*/
public function isWritable($class, $property, array $context = [])
public function isWritable(string $class, string $property, array $context = [])
{
if (
null === ($metadata = $this->getMetadata($class))

View File

@ -31,11 +31,9 @@ interface RegistryInterface extends ManagerRegistryInterface
/**
* Gets a named entity manager.
*
* @param string $name The entity manager name (null for the default one)
*
* @return EntityManager
*/
public function getEntityManager($name = null);
public function getEntityManager(string $name = null);
/**
* Gets an array of all registered entity managers.
@ -57,24 +55,20 @@ interface RegistryInterface extends ManagerRegistryInterface
* hold an obsolete reference. You can inject the registry instead
* to avoid this problem.
*
* @param string $name The entity manager name (null for the default one)
*
* @return EntityManager
*/
public function resetEntityManager($name = null);
public function resetEntityManager(string $name = null);
/**
* Resolves a registered namespace alias to the full namespace.
*
* This method looks for the alias in all registered entity managers.
*
* @param string $alias The alias
*
* @return string The full namespace
*
* @see Configuration::getEntityNamespace
*/
public function getEntityNamespace($alias);
public function getEntityNamespace(string $alias);
/**
* Gets all connection names.
@ -86,9 +80,7 @@ interface RegistryInterface extends ManagerRegistryInterface
/**
* Gets the entity manager associated with a given class.
*
* @param string $class A Doctrine Entity class name
*
* @return EntityManager|null
*/
public function getEntityManagerForClass($class);
public function getEntityManagerForClass(string $class);
}

View File

@ -31,9 +31,7 @@ interface UserLoaderInterface
*
* This method must return null if the user is not found.
*
* @param string $username The username
*
* @return UserInterface|null
*/
public function loadUserByUsername($username);
public function loadUserByUsername(string $username);
}

View File

@ -40,14 +40,14 @@ final class TestRepositoryFactory implements RepositoryFactory
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);
$this->repositoryList[$repositoryHash] = $repository;
}
private function createRepository(EntityManagerInterface $entityManager, $entityName): ObjectRepository
private function createRepository(EntityManagerInterface $entityManager, string $entityName): ObjectRepository
{
/* @var $metadata ClassMetadata */
$metadata = $entityManager->getClassMetadata($entityName);
@ -56,7 +56,7 @@ final class TestRepositoryFactory implements RepositoryFactory
return new $repositoryClassName($entityManager, $metadata);
}
private function getRepositoryHash(EntityManagerInterface $entityManager, $entityName): string
private function getRepositoryHash(EntityManagerInterface $entityManager, string $entityName): string
{
return $entityManager->getClassMetadata($entityName)->getName().spl_object_hash($entityManager);
}

View File

@ -27,11 +27,11 @@
"symfony/stopwatch": "^4.4|^5.0",
"symfony/config": "^4.4|^5.0",
"symfony/dependency-injection": "^4.4|^5.0",
"symfony/form": "^4.4|^5.0",
"symfony/http-kernel": "^4.4|^5.0",
"symfony/form": "^5.0",
"symfony/http-kernel": "^5.0",
"symfony/messenger": "^4.4|^5.0",
"symfony/property-access": "^4.4|^5.0",
"symfony/property-info": "^4.4|^5.0",
"symfony/property-info": "^5.0",
"symfony/proxy-manager-bridge": "^4.4|^5.0",
"symfony/security-core": "^5.0",
"symfony/expression-language": "^4.4|^5.0",
@ -48,8 +48,11 @@
"conflict": {
"phpunit/phpunit": "<5.4.3",
"symfony/dependency-injection": "<4.4",
"symfony/form": "<4.4",
"symfony/form": "<5",
"symfony/http-kernel": "<5",
"symfony/messenger": "<4.4",
"symfony/property-info": "<5",
"symfony/security-bundle": "<5",
"symfony/security-core": "<5"
},
"suggest": {

View File

@ -22,7 +22,7 @@ use Symfony\Component\DependencyInjection\ContainerBuilder;
*/
interface UserProviderFactoryInterface
{
public function create(ContainerBuilder $container, $id, $config);
public function create(ContainerBuilder $container, string $id, array $config);
public function getKey();

View File

@ -36,7 +36,7 @@ interface ChoiceLoaderInterface
*
* @return ChoiceListInterface The loaded choice list
*/
public function loadChoiceList($value = null);
public function loadChoiceList(callable $value = null);
/**
* Loads the choices corresponding to the given values.
@ -54,7 +54,7 @@ interface ChoiceLoaderInterface
*
* @return array An array of choices
*/
public function loadChoicesForValues(array $values, $value = null);
public function loadChoicesForValues(array $values, callable $value = null);
/**
* Loads the values corresponding to the given choices.
@ -72,5 +72,5 @@ interface ChoiceLoaderInterface
*
* @return string[] An array of choice values
*/
public function loadValuesForChoices(array $choices, $value = null);
public function loadValuesForChoices(array $choices, callable $value = null);
}

View File

@ -19,32 +19,23 @@ interface FormTypeGuesserInterface
/**
* Returns a field guess for a property name of a class.
*
* @param string $class The fully qualified class name
* @param string $property The name of the property to guess for
*
* @return Guess\TypeGuess|null A guess for the field's type and options
*/
public function guessType($class, $property);
public function guessType(string $class, string $property);
/**
* Returns a guess whether a property of a class is required.
*
* @param string $class The fully qualified class name
* @param string $property The name of the property to guess for
*
* @return Guess\ValueGuess|null A guess for the field's required setting
*/
public function guessRequired($class, $property);
public function guessRequired(string $class, string $property);
/**
* Returns a guess about the field's maximum length.
*
* @param string $class The fully qualified class name
* @param string $property The name of the property to guess for
*
* @return Guess\ValueGuess|null A guess for the field's maximum length
*/
public function guessMaxLength($class, $property);
public function guessMaxLength(string $class, string $property);
/**
* Returns a guess about the field's pattern.
@ -56,10 +47,7 @@ interface FormTypeGuesserInterface
*
* @see https://github.com/symfony/symfony/pull/3927
*
* @param string $class The fully qualified class name
* @param string $property The name of the property to guess for
*
* @return Guess\ValueGuess|null A guess for the field's required pattern
*/
public function guessPattern($class, $property);
public function guessPattern(string $class, string $property);
}

View File

@ -20,8 +20,6 @@ interface WarmableInterface
{
/**
* Warms up the cache.
*
* @param string $cacheDir The cache directory
*/
public function warmUp($cacheDir);
public function warmUp(string $cacheDir);
}