ReverseLabel   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 7
c 1
b 0
f 0
dl 0
loc 34
ccs 11
cts 11
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A generate() 0 7 2
A format() 0 3 1
A __construct() 0 3 1
1
<?php
2
3
/**
4
 * League.Period (https://period.thephpleague.com)
5
 *
6
 * (c) Ignace Nyamagana Butera <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace League\Period\Chart;
15
16
use function iterator_to_array;
17
18
final class ReverseLabel implements LabelGenerator
19
{
20
    /**
21
     * @var LabelGenerator
22
     */
23
    private $labelGenerator;
24
25
    /**
26
     * New instance.
27
     */
28 12
    public function __construct(LabelGenerator $labelGenerator)
29
    {
30 12
        $this->labelGenerator = $labelGenerator;
31 12
    }
32
33
    /**
34
     * {@inheritdoc}
35
     */
36 9
    public function generate(int $nbLabels): \Iterator
37
    {
38 9
        $iterable = $this->labelGenerator->generate($nbLabels);
39 9
        $data = iterator_to_array($iterable, false);
40
41 9
        for (end($data); null !== ($key = key($data)); prev($data)) {
42 6
            yield $key => current($data);
43
        }
44 9
    }
45
46
    /**
47
     * {@inheritdoc}
48
     */
49 3
    public function format(string $label): string
50
    {
51 3
        return $this->labelGenerator->format($label);
52
    }
53
}
54