Issues (7)

src/Common/Source/IterableMetricSource.php (1 issue)

1
<?php
2
3
namespace Lamoda\Metric\Common\Source;
4
5
use Lamoda\Metric\Common\MetricInterface;
6
use Lamoda\Metric\Common\MetricSourceInterface;
7
8
final class IterableMetricSource implements \IteratorAggregate, MetricSourceInterface
9
{
10
    /** @var MetricInterface[]|\Traversable|iterable */
11
    private $metrics;
12
13
    /**
14
     * @param iterable|MetricInterface[] $metrics
15
     */
16 2
    public function __construct(iterable $metrics)
17
    {
18 2
        if (\is_array($metrics)) {
19 1
            $metrics = new \ArrayIterator($metrics);
20
        }
21
22 2
        $this->metrics = $metrics;
23 2
    }
24
25
    /** {@inheritdoc} */
26 2
    public function getMetrics(): \Traversable
27
    {
28 2
        return $this->metrics;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->metrics could return the type Lamoda\Metric\Common\MetricInterface[]|iterable which is incompatible with the type-hinted return Traversable. Consider adding an additional type-check to rule them out.
Loading history...
29
    }
30
31
    /** {@inheritdoc} */
32 2
    public function getIterator(): \Traversable
33
    {
34 2
        return $this->getMetrics();
35
    }
36
}
37