IterableMetricSource   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
eloc 7
dl 0
loc 27
ccs 9
cts 9
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getMetrics() 0 3 1
A getIterator() 0 3 1
A __construct() 0 7 2
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