Skip to content

Add generic types to traversable implementations #42471

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 3, 2021
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
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ final class MessengerTransportDoctrineSchemaSubscriber implements EventSubscribe
private $transports;

/**
* @param iterable|TransportInterface[] $transports
* @param iterable<int, TransportInterface> $transports
*/
public function __construct(iterable $transports)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ final class PdoCacheAdapterDoctrineSchemaSubscriber implements EventSubscriber
private $pdoAdapters;

/**
* @param iterable|PdoAdapter[] $pdoAdapters
* @param iterable<int, PdoAdapter> $pdoAdapters
*/
public function __construct(iterable $pdoAdapters)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ final class RememberMeTokenProviderDoctrineSchemaSubscriber implements EventSubs
private $rememberMeHandlers;

/**
* @param iterable|RememberMeHandlerInterface[] $rememberMeHandlers
* @param iterable<int, RememberMeHandlerInterface> $rememberMeHandlers
*/
public function __construct(iterable $rememberMeHandlers)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use Symfony\Component\HttpClient\HttpClient;
use Symfony\Contracts\HttpClient\Exception\ExceptionInterface;
use Symfony\Contracts\HttpClient\HttpClientInterface;
use Symfony\Contracts\HttpClient\ResponseInterface;

/**
* Push logs directly to Elasticsearch and format them according to Logstash specification.
Expand Down Expand Up @@ -47,6 +48,10 @@ class ElasticsearchLogstashHandler extends AbstractHandler
private $endpoint;
private $index;
private $client;

/**
* @var \SplObjectStorage<ResponseInterface, null>
*/
private $responses;

/**
Expand Down
5 changes: 5 additions & 0 deletions src/Symfony/Bridge/Twig/Extension/ProfilerExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace Symfony\Bridge\Twig\Extension;

use Symfony\Component\Stopwatch\Stopwatch;
use Symfony\Component\Stopwatch\StopwatchEvent;
use Twig\Extension\ProfilerExtension as BaseProfilerExtension;
use Twig\Profiler\Profile;

Expand All @@ -21,6 +22,10 @@
final class ProfilerExtension extends BaseProfilerExtension
{
private $stopwatch;

/**
* @var \SplObjectStorage<Profile, StopwatchEvent>
*/
private $events;

public function __construct(Profile $profile, Stopwatch $stopwatch = null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class ExpressionCacheWarmer implements CacheWarmerInterface
private $expressionLanguage;

/**
* @param iterable|Expression[] $expressions
* @param iterable<int, Expression> $expressions
*/
public function __construct(iterable $expressions, ExpressionLanguage $expressionLanguage)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class MainConfiguration implements ConfigurationInterface
private $userProviderFactories;

/**
* @param (SecurityFactoryInterface|AuthenticatorFactoryInterface)[] $factories
* @param array<int, SecurityFactoryInterface|AuthenticatorFactoryInterface> $factories
*/
public function __construct(array $factories, array $userProviderFactories)
{
Expand Down Expand Up @@ -219,6 +219,9 @@ private function addAccessControlSection(ArrayNodeDefinition $rootNode)
;
}

/**
* @param array<int, SecurityFactoryInterface|AuthenticatorFactoryInterface> $factories
*/
private function addFirewallsSection(ArrayNodeDefinition $rootNode, array $factories)
{
$firewallNodeBuilder = $rootNode
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1188,7 +1188,7 @@ private function isValidIp(string $cidr): bool
}

/**
* @return (AuthenticatorFactoryInterface|SecurityFactoryInterface)[]
* @return array<int, SecurityFactoryInterface|AuthenticatorFactoryInterface>
*/
private function getSortedFactories(): array
{
Expand Down
2 changes: 2 additions & 0 deletions src/Symfony/Bundle/TwigBundle/TemplateIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
* @author Fabien Potencier <fabien@symfony.com>
*
* @internal
*
* @implements \IteratorAggregate<int, string>
*/
class TemplateIterator implements \IteratorAggregate
{
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Cache/Adapter/AdapterInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function getItem($key);
/**
* {@inheritdoc}
*
* @return \Traversable|CacheItem[]
* @return \Traversable<string, CacheItem>
*/
public function getItems(array $keys = []);

Expand Down
2 changes: 2 additions & 0 deletions src/Symfony/Component/Config/Resource/GlobResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
* @author Nicolas Grekas <p@tchwork.com>
*
* @final
*
* @implements \IteratorAggregate<string, \SplFileInfo>
*/
class GlobResource implements \IteratorAggregate, SelfCheckingResourceInterface
{
Expand Down
7 changes: 3 additions & 4 deletions src/Symfony/Component/Config/ResourceCheckerConfigCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ class ResourceCheckerConfigCache implements ConfigCacheInterface
private $file;

/**
* @var iterable|ResourceCheckerInterface[]
* @var iterable<int, ResourceCheckerInterface>
*/
private $resourceCheckers;

/**
* @param string $file The absolute cache path
* @param iterable|ResourceCheckerInterface[] $resourceCheckers The ResourceCheckers to use for the freshness check
* @param string $file The absolute cache path
* @param iterable<int, ResourceCheckerInterface> $resourceCheckers The ResourceCheckers to use for the freshness check
*/
public function __construct(string $file, iterable $resourceCheckers = [])
{
Expand Down Expand Up @@ -91,7 +91,6 @@ public function isFresh()
$time = filemtime($this->file);

foreach ($meta as $resource) {
/* @var ResourceInterface $resource */
foreach ($this->resourceCheckers as $checker) {
if (!$checker->supports($resource)) {
continue; // next checker
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class ResourceCheckerConfigCacheFactory implements ConfigCacheFactoryInterface
private $resourceCheckers = [];

/**
* @param iterable|ResourceCheckerInterface[] $resourceCheckers
* @param iterable<int, ResourceCheckerInterface> $resourceCheckers
*/
public function __construct(iterable $resourceCheckers = [])
{
Expand Down
4 changes: 3 additions & 1 deletion src/Symfony/Component/Console/Helper/HelperSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
* HelperSet represents a set of helpers to be used with a command.
*
* @author Fabien Potencier <fabien@symfony.com>
*
* @implements \IteratorAggregate<string, Helper>
*/
class HelperSet implements \IteratorAggregate
{
Expand Down Expand Up @@ -98,7 +100,7 @@ public function getCommand()
}

/**
* @return \Traversable<Helper>
* @return \Traversable<string, Helper>
*/
#[\ReturnTypeWillChange]
public function getIterator()
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/DependencyInjection/Definition.php
Original file line number Diff line number Diff line change
Expand Up @@ -846,7 +846,7 @@ public function setAutowired(bool $autowired)
/**
* Gets bindings.
*
* @return array|BoundArgument[]
* @return BoundArgument[]
*/
public function getBindings()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ class PhpDumper extends Dumper
*/
public const NON_FIRST_CHARS = 'abcdefghijklmnopqrstuvwxyz0123456789_';

/**
* @var \SplObjectStorage<Definition, Variable>|null
*/
private $definitionVariables;
private $referenceVariables;
private $variableCount;
Expand Down
4 changes: 3 additions & 1 deletion src/Symfony/Component/DomCrawler/Crawler.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
* Crawler eases navigation of a list of \DOMNode objects.
*
* @author Fabien Potencier <fabien@symfony.com>
*
* @implements \IteratorAggregate<int, \DOMNode>
*/
class Crawler implements \Countable, \IteratorAggregate
{
Expand Down Expand Up @@ -1129,7 +1131,7 @@ public function count()
}

/**
* @return \ArrayIterator|\DOMNode[]
* @return \ArrayIterator<int, \DOMNode>
*/
#[\ReturnTypeWillChange]
public function getIterator()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ class TraceableEventDispatcher implements EventDispatcherInterface, ResetInterfa
protected $logger;
protected $stopwatch;

/**
* @var \SplObjectStorage<WrappedListener, array{string, string}>
*/
private $callStack;
private $dispatcher;
private $wrappedListeners;
Expand Down
3 changes: 3 additions & 0 deletions src/Symfony/Component/EventDispatcher/GenericEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
* Encapsulates events thus decoupling the observer from the subject they encapsulate.
*
* @author Drak <drak@zikula.org>
*
* @implements \ArrayAccess<string, mixed>
* @implements \IteratorAggregate<string, mixed>
*/
class GenericEvent extends Event implements \ArrayAccess, \IteratorAggregate
{
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/Finder/Finder.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
*
* @author Fabien Potencier <fabien@symfony.com>
*
* @implements \IteratorAggregate<SplFileInfo>
* @implements \IteratorAggregate<string, SplFileInfo>
*/
class Finder implements \IteratorAggregate, \Countable
{
Expand Down Expand Up @@ -603,7 +603,7 @@ public function in($dirs)
*
* This method implements the IteratorAggregate interface.
*
* @return \Iterator|SplFileInfo[]
* @return \Iterator<string, SplFileInfo>
*
* @throws \LogicException if the in() method has not been called
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,16 @@
* to remove files.
*
* @author Fabien Potencier <fabien@symfony.com>
*
* @extends \FilterIterator<string, \SplFileInfo>
*/
class CustomFilterIterator extends \FilterIterator
{
private $filters = [];

/**
* @param \Iterator $iterator The Iterator to filter
* @param callable[] $filters An array of PHP callbacks
* @param \Iterator<string, \SplFileInfo> $iterator The Iterator to filter
* @param callable[] $filters An array of PHP callbacks
*
* @throws \InvalidArgumentException
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,16 @@
* DateRangeFilterIterator filters out files that are not in the given date range (last modified dates).
*
* @author Fabien Potencier <fabien@symfony.com>
*
* @extends \FilterIterator<string, \SplFileInfo>
*/
class DateRangeFilterIterator extends \FilterIterator
{
private $comparators = [];

/**
* @param \Iterator $iterator The Iterator to filter
* @param DateComparator[] $comparators An array of DateComparator instances
* @param \Iterator<string, \SplFileInfo> $iterator
* @param DateComparator[] $comparators
*/
public function __construct(\Iterator $iterator, array $comparators)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,20 @@
* DepthRangeFilterIterator limits the directory depth.
*
* @author Fabien Potencier <fabien@symfony.com>
*
* @template TKey
* @template TValue
*
* @extends \FilterIterator<TKey, TValue>
*/
class DepthRangeFilterIterator extends \FilterIterator
{
private $minDepth = 0;

/**
* @param \RecursiveIteratorIterator $iterator The Iterator to filter
* @param int $minDepth The min depth
* @param int $maxDepth The max depth
* @param \RecursiveIteratorIterator<\RecursiveIterator<TKey, TValue>> $iterator The Iterator to filter
* @param int $minDepth The min depth
* @param int $maxDepth The max depth
*/
public function __construct(\RecursiveIteratorIterator $iterator, int $minDepth = 0, int $maxDepth = \PHP_INT_MAX)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
* ExcludeDirectoryFilterIterator filters out directories.
*
* @author Fabien Potencier <fabien@symfony.com>
*
* @extends \FilterIterator<string, \SplFileInfo>
* @implements \RecursiveIterator<string, \SplFileInfo>
*/
class ExcludeDirectoryFilterIterator extends \FilterIterator implements \RecursiveIterator
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
* FileTypeFilterIterator only keeps files, directories, or both.
*
* @author Fabien Potencier <fabien@symfony.com>
*
* @extends \FilterIterator<string, \SplFileInfo>
*/
class FileTypeFilterIterator extends \FilterIterator
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
*
* @author Fabien Potencier <fabien@symfony.com>
* @author Włodzimierz Gajda <gajdaw@gajdaw.pl>
*
* @extends MultiplePcreFilterIterator<string, \SplFileInfo>
*/
class FilecontentFilterIterator extends MultiplePcreFilterIterator
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
* FilenameFilterIterator filters files by patterns (a regexp, a glob, or a string).
*
* @author Fabien Potencier <fabien@symfony.com>
*
* @extends MultiplePcreFilterIterator<string, \SplFileInfo>
*/
class FilenameFilterIterator extends MultiplePcreFilterIterator
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
* MultiplePcreFilterIterator filters files using patterns (regexps, globs or strings).
*
* @author Fabien Potencier <fabien@symfony.com>
*
* @template-covariant TKey
* @template-covariant TValue
*
* @extends \FilterIterator<TKey, TValue>
*/
abstract class MultiplePcreFilterIterator extends \FilterIterator
{
Expand Down
2 changes: 2 additions & 0 deletions src/Symfony/Component/Finder/Iterator/PathFilterIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
*
* @author Fabien Potencier <fabien@symfony.com>
* @author Włodzimierz Gajda <gajdaw@gajdaw.pl>
*
* @extends MultiplePcreFilterIterator<string, \SplFileInfo>
*/
class PathFilterIterator extends MultiplePcreFilterIterator
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,16 @@
* SizeRangeFilterIterator filters out files that are not in the given size range.
*
* @author Fabien Potencier <fabien@symfony.com>
*
* @extends \FilterIterator<string, \SplFileInfo>
*/
class SizeRangeFilterIterator extends \FilterIterator
{
private $comparators = [];

/**
* @param \Iterator $iterator The Iterator to filter
* @param NumberComparator[] $comparators An array of NumberComparator instances
* @param \Iterator<string, \SplFileInfo> $iterator
* @param NumberComparator[] $comparators
*/
public function __construct(\Iterator $iterator, array $comparators)
{
Expand Down
Loading