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
![]() |
|||
29 | } |
||
30 | |||
31 | /** {@inheritdoc} */ |
||
32 | 2 | public function getIterator(): \Traversable |
|
33 | { |
||
34 | 2 | return $this->getMetrics(); |
|
35 | } |
||
36 | } |
||
37 |