Skip to content

Commit 2663464

Browse files
committed
add parameter type declarations where possible
1 parent 1cc7067 commit 2663464

File tree

23 files changed

+66
-146
lines changed

23 files changed

+66
-146
lines changed

src/Symfony/Bridge/Doctrine/CacheWarmer/ProxyCacheWarmer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public function isOptional()
4444
/**
4545
* {@inheritdoc}
4646
*/
47-
public function warmUp($cacheDir)
47+
public function warmUp(string $cacheDir)
4848
{
4949
foreach ($this->registry->getManagers() as $em) {
5050
// we need the directory no matter the proxy cache generation strategy

src/Symfony/Bridge/Doctrine/ContainerAwareEventManager.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,7 @@ public function removeEventListener($events, $listener)
129129
}
130130
}
131131

132-
/**
133-
* @param string $eventName
134-
*/
135-
private function initializeListeners($eventName)
132+
private function initializeListeners(string $eventName)
136133
{
137134
foreach ($this->listeners[$eventName] as $hash => $listener) {
138135
if (\is_string($listener)) {

src/Symfony/Bridge/Doctrine/DataCollector/DoctrineDataCollector.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,8 @@ public function __construct(ManagerRegistry $registry)
4444

4545
/**
4646
* Adds the stack logger for a connection.
47-
*
48-
* @param string $name
49-
* @param DebugStack $logger
5047
*/
51-
public function addLogger($name, DebugStack $logger)
48+
public function addLogger(string $name, DebugStack $logger)
5249
{
5350
$this->loggers[$name] = $logger;
5451
}
@@ -120,7 +117,7 @@ public function getName()
120117
return 'db';
121118
}
122119

123-
private function sanitizeQueries($connectionName, $queries)
120+
private function sanitizeQueries(string $connectionName, array $queries)
124121
{
125122
foreach ($queries as $i => $query) {
126123
$queries[$i] = $this->sanitizeQuery($connectionName, $query);
@@ -129,7 +126,7 @@ private function sanitizeQueries($connectionName, $queries)
129126
return $queries;
130127
}
131128

132-
private function sanitizeQuery($connectionName, $query)
129+
private function sanitizeQuery(string $connectionName, $query)
133130
{
134131
$query['explainable'] = true;
135132
if (null === $query['params']) {

src/Symfony/Bridge/Doctrine/DependencyInjection/AbstractDoctrineExtension.php

Lines changed: 8 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,8 @@ protected function loadMappingInformation(array $objectManager, ContainerBuilder
101101
* Register the alias for this mapping driver.
102102
*
103103
* Aliases can be used in the Query languages of all the Doctrine object managers to simplify writing tasks.
104-
*
105-
* @param array $mappingConfig
106-
* @param string $mappingName
107104
*/
108-
protected function setMappingDriverAlias($mappingConfig, $mappingName)
105+
protected function setMappingDriverAlias(array $mappingConfig, string $mappingName)
109106
{
110107
if (isset($mappingConfig['alias'])) {
111108
$this->aliasMap[$mappingConfig['alias']] = $mappingConfig['prefix'];
@@ -117,12 +114,9 @@ protected function setMappingDriverAlias($mappingConfig, $mappingName)
117114
/**
118115
* Register the mapping driver configuration for later use with the object managers metadata driver chain.
119116
*
120-
* @param array $mappingConfig
121-
* @param string $mappingName
122-
*
123117
* @throws \InvalidArgumentException
124118
*/
125-
protected function setMappingDriverConfig(array $mappingConfig, $mappingName)
119+
protected function setMappingDriverConfig(array $mappingConfig, string $mappingName)
126120
{
127121
$mappingDirectory = $mappingConfig['dir'];
128122
if (!is_dir($mappingDirectory)) {
@@ -171,11 +165,8 @@ protected function getMappingDriverBundleConfigDefaults(array $bundleConfig, \Re
171165

172166
/**
173167
* Register all the collected mapping information with the object manager by registering the appropriate mapping drivers.
174-
*
175-
* @param array $objectManager
176-
* @param ContainerBuilder $container A ContainerBuilder instance
177168
*/
178-
protected function registerMappingDrivers($objectManager, ContainerBuilder $container)
169+
protected function registerMappingDrivers(array $objectManager, ContainerBuilder $container)
179170
{
180171
// configure metadata driver for each bundle based on the type of mapping files found
181172
if ($container->hasDefinition($this->getObjectManagerElementName($objectManager['name'].'_metadata_driver'))) {
@@ -225,12 +216,9 @@ protected function registerMappingDrivers($objectManager, ContainerBuilder $cont
225216
/**
226217
* Assertion if the specified mapping information is valid.
227218
*
228-
* @param array $mappingConfig
229-
* @param string $objectManagerName
230-
*
231219
* @throws \InvalidArgumentException
232220
*/
233-
protected function assertValidMappingConfiguration(array $mappingConfig, $objectManagerName)
221+
protected function assertValidMappingConfiguration(array $mappingConfig, string $objectManagerName)
234222
{
235223
if (!$mappingConfig['type'] || !$mappingConfig['dir'] || !$mappingConfig['prefix']) {
236224
throw new \InvalidArgumentException(sprintf('Mapping definitions for Doctrine manager "%s" require at least the "type", "dir" and "prefix" options.', $objectManagerName));
@@ -252,12 +240,9 @@ protected function assertValidMappingConfiguration(array $mappingConfig, $object
252240
/**
253241
* Detects what metadata driver to use for the supplied directory.
254242
*
255-
* @param string $dir A directory path
256-
* @param ContainerBuilder $container A ContainerBuilder instance
257-
*
258243
* @return string|null A metadata driver short name, if one can be detected
259244
*/
260-
protected function detectMetadataDriver($dir, ContainerBuilder $container)
245+
protected function detectMetadataDriver(string $dir, ContainerBuilder $container)
261246
{
262247
$configPath = $this->getMappingResourceConfigDirectory();
263248
$extension = $this->getMappingResourceExtension();
@@ -286,30 +271,21 @@ protected function detectMetadataDriver($dir, ContainerBuilder $container)
286271
/**
287272
* Loads a configured object manager metadata, query or result cache driver.
288273
*
289-
* @param array $objectManager A configured object manager
290-
* @param ContainerBuilder $container A ContainerBuilder instance
291-
* @param string $cacheName
292-
*
293274
* @throws \InvalidArgumentException in case of unknown driver type
294275
*/
295-
protected function loadObjectManagerCacheDriver(array $objectManager, ContainerBuilder $container, $cacheName)
276+
protected function loadObjectManagerCacheDriver(array $objectManager, ContainerBuilder $container, string $cacheName)
296277
{
297278
$this->loadCacheDriver($cacheName, $objectManager['name'], $objectManager[$cacheName.'_driver'], $container);
298279
}
299280

300281
/**
301282
* Loads a cache driver.
302283
*
303-
* @param string $cacheName The cache driver name
304-
* @param string $objectManagerName The object manager name
305-
* @param array $cacheDriver The cache driver mapping
306-
* @param ContainerBuilder $container The ContainerBuilder instance
307-
*
308284
* @return string
309285
*
310286
* @throws \InvalidArgumentException
311287
*/
312-
protected function loadCacheDriver($cacheName, $objectManagerName, array $cacheDriver, ContainerBuilder $container)
288+
protected function loadCacheDriver(string $cacheName, string $objectManagerName, array $cacheDriver, ContainerBuilder $container)
313289
{
314290
$cacheDriverServiceId = $this->getObjectManagerElementName($objectManagerName.'_'.$cacheName);
315291

@@ -412,11 +388,9 @@ protected function fixManagersAutoMappings(array $managerConfigs, array $bundles
412388
*
413389
* @example $name is 'entity_manager' then the result would be 'doctrine.orm.entity_manager'
414390
*
415-
* @param string $name
416-
*
417391
* @return string
418392
*/
419-
abstract protected function getObjectManagerElementName($name);
393+
abstract protected function getObjectManagerElementName(string $name);
420394

421395
/**
422396
* Noun that describes the mapped objects such as Entity or Document.

src/Symfony/Bridge/Doctrine/DependencyInjection/CompilerPass/RegisterEventListenersAndSubscribersPass.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ private function addTaggedListeners(ContainerBuilder $container)
109109
}
110110
}
111111

112-
private function getEventManagerDef(ContainerBuilder $container, $name)
112+
private function getEventManagerDef(ContainerBuilder $container, string $name)
113113
{
114114
if (!isset($this->eventManagers[$name])) {
115115
$this->eventManagers[$name] = $container->getDefinition(sprintf($this->managerTemplate, $name));
@@ -128,12 +128,9 @@ private function getEventManagerDef(ContainerBuilder $container, $name)
128128
* @see https://bugs.php.net/bug.php?id=53710
129129
* @see https://bugs.php.net/bug.php?id=60926
130130
*
131-
* @param string $tagName
132-
* @param ContainerBuilder $container
133-
*
134131
* @return array
135132
*/
136-
private function findAndSortTags($tagName, ContainerBuilder $container)
133+
private function findAndSortTags(string $tagName, ContainerBuilder $container)
137134
{
138135
$sortedTags = [];
139136

src/Symfony/Bridge/Doctrine/DependencyInjection/Security/UserProvider/EntityFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function __construct(string $key, string $providerId)
3333
$this->providerId = $providerId;
3434
}
3535

36-
public function create(ContainerBuilder $container, $id, $config)
36+
public function create(ContainerBuilder $container, string $id, array $config)
3737
{
3838
$container
3939
->setDefinition($id, new ChildDefinition($this->providerId))

src/Symfony/Bridge/Doctrine/Form/ChoiceList/DoctrineChoiceLoader.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public function __construct(ObjectManager $manager, string $class, IdReader $idR
6262
/**
6363
* {@inheritdoc}
6464
*/
65-
public function loadChoiceList($value = null)
65+
public function loadChoiceList(callable $value = null)
6666
{
6767
if ($this->choiceList) {
6868
return $this->choiceList;
@@ -78,7 +78,7 @@ public function loadChoiceList($value = null)
7878
/**
7979
* {@inheritdoc}
8080
*/
81-
public function loadValuesForChoices(array $choices, $value = null)
81+
public function loadValuesForChoices(array $choices, callable $value = null)
8282
{
8383
// Performance optimization
8484
if (empty($choices)) {
@@ -110,7 +110,7 @@ public function loadValuesForChoices(array $choices, $value = null)
110110
/**
111111
* {@inheritdoc}
112112
*/
113-
public function loadChoicesForValues(array $values, $value = null)
113+
public function loadChoicesForValues(array $values, callable $value = null)
114114
{
115115
// Performance optimization
116116
// Also prevents the generation of "WHERE id IN ()" queries through the

src/Symfony/Bridge/Doctrine/Form/ChoiceList/EntityLoaderInterface.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,7 @@ public function getEntities();
2828
/**
2929
* Returns an array of entities matching the given identifiers.
3030
*
31-
* @param string $identifier The identifier field of the object. This method
32-
* is not applicable for fields with multiple
33-
* identifiers.
34-
* @param array $values The values of the identifiers
35-
*
3631
* @return array The entities
3732
*/
38-
public function getEntitiesByIds($identifier, array $values);
33+
public function getEntitiesByIds(string $identifier, array $values);
3934
}

src/Symfony/Bridge/Doctrine/Form/ChoiceList/IdReader.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,9 @@ public function isIntId(): bool
8484
*
8585
* This method assumes that the object has a single-column ID.
8686
*
87-
* @param object $object The object
88-
*
8987
* @return mixed The ID value
9088
*/
91-
public function getIdValue($object)
89+
public function getIdValue(object $object = null)
9290
{
9391
if (!$object) {
9492
return;

src/Symfony/Bridge/Doctrine/Form/ChoiceList/ORMQueryBuilderLoader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public function getEntities()
5353
/**
5454
* {@inheritdoc}
5555
*/
56-
public function getEntitiesByIds($identifier, array $values)
56+
public function getEntitiesByIds(string $identifier, array $values)
5757
{
5858
$qb = clone $this->queryBuilder;
5959
$alias = current($qb->getRootAliases());

src/Symfony/Bridge/Doctrine/Form/DoctrineOrmTypeGuesser.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function __construct(ManagerRegistry $registry)
3636
/**
3737
* {@inheritdoc}
3838
*/
39-
public function guessType($class, $property)
39+
public function guessType(string $class, string $property)
4040
{
4141
if (!$ret = $this->getMetadata($class)) {
4242
return new TypeGuess('Symfony\Component\Form\Extension\Core\Type\TextType', [], Guess::LOW_CONFIDENCE);
@@ -94,7 +94,7 @@ public function guessType($class, $property)
9494
/**
9595
* {@inheritdoc}
9696
*/
97-
public function guessRequired($class, $property)
97+
public function guessRequired(string $class, string $property)
9898
{
9999
$classMetadatas = $this->getMetadata($class);
100100

@@ -132,7 +132,7 @@ public function guessRequired($class, $property)
132132
/**
133133
* {@inheritdoc}
134134
*/
135-
public function guessMaxLength($class, $property)
135+
public function guessMaxLength(string $class, string $property)
136136
{
137137
$ret = $this->getMetadata($class);
138138
if ($ret && isset($ret[0]->fieldMappings[$property]) && !$ret[0]->hasAssociation($property)) {
@@ -151,7 +151,7 @@ public function guessMaxLength($class, $property)
151151
/**
152152
* {@inheritdoc}
153153
*/
154-
public function guessPattern($class, $property)
154+
public function guessPattern(string $class, string $property)
155155
{
156156
$ret = $this->getMetadata($class);
157157
if ($ret && isset($ret[0]->fieldMappings[$property]) && !$ret[0]->hasAssociation($property)) {
@@ -161,7 +161,7 @@ public function guessPattern($class, $property)
161161
}
162162
}
163163

164-
protected function getMetadata($class)
164+
protected function getMetadata(string $class)
165165
{
166166
// normalize class name
167167
$class = self::getRealClass(ltrim($class, '\\'));

src/Symfony/Bridge/Doctrine/Form/Type/DoctrineType.php

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Doctrine\Common\Collections\Collection;
1515
use Doctrine\Common\Persistence\ManagerRegistry;
1616
use Doctrine\Common\Persistence\ObjectManager;
17+
use Doctrine\ORM\QueryBuilder;
1718
use Symfony\Bridge\Doctrine\Form\ChoiceList\DoctrineChoiceLoader;
1819
use Symfony\Bridge\Doctrine\Form\ChoiceList\EntityLoaderInterface;
1920
use Symfony\Bridge\Doctrine\Form\ChoiceList\IdReader;
@@ -49,14 +50,12 @@ abstract class DoctrineType extends AbstractType implements ResetInterface
4950
*
5051
* For backwards compatibility, objects are cast to strings by default.
5152
*
52-
* @param object $choice The object
53-
*
5453
* @return string The string representation of the object
5554
*
5655
* @internal This method is public to be usable as callback. It should not
5756
* be used in user code.
5857
*/
59-
public static function createChoiceLabel($choice)
58+
public static function createChoiceLabel(object $choice)
6059
{
6160
return (string) $choice;
6261
}
@@ -68,17 +67,16 @@ public static function createChoiceLabel($choice)
6867
* a single-column integer ID. In that case, the value of the field is
6968
* the ID of the object. That ID is also used as field name.
7069
*
71-
* @param object $choice The object
72-
* @param int|string $key The choice key
73-
* @param string $value The choice value. Corresponds to the object's
74-
* ID here.
70+
* @param int|string $key The choice key
71+
* @param string $value The choice value. Corresponds to the object's
72+
* ID here.
7573
*
7674
* @return string The field name
7775
*
7876
* @internal This method is public to be usable as callback. It should not
7977
* be used in user code.
8078
*/
81-
public static function createChoiceName($choice, $key, $value)
79+
public static function createChoiceName(object $choice, $key, string $value)
8280
{
8381
return str_replace('-', '_', (string) $value);
8482
}
@@ -88,15 +86,13 @@ public static function createChoiceName($choice, $key, $value)
8886
* For instance in ORM two query builders with an equal SQL string and
8987
* equal parameters are considered to be equal.
9088
*
91-
* @param object $queryBuilder
92-
*
9389
* @return array|false Array with important QueryBuilder parts or false if
9490
* they can't be determined
9591
*
9692
* @internal This method is public to be usable as callback. It should not
9793
* be used in user code.
9894
*/
99-
public function getQueryBuilderPartsForCachingHash($queryBuilder)
95+
public function getQueryBuilderPartsForCachingHash(QueryBuilder $queryBuilder)
10096
{
10197
return false;
10298
}
@@ -265,13 +261,9 @@ public function configureOptions(OptionsResolver $resolver)
265261
/**
266262
* Return the default loader object.
267263
*
268-
* @param ObjectManager $manager
269-
* @param mixed $queryBuilder
270-
* @param string $class
271-
*
272264
* @return EntityLoaderInterface
273265
*/
274-
abstract public function getLoader(ObjectManager $manager, $queryBuilder, $class);
266+
abstract public function getLoader(ObjectManager $manager, QueryBuilder $queryBuilder, string $class);
275267

276268
public function getParent()
277269
{

0 commit comments

Comments
 (0)