DashboardStatisticsProvider::getStatistics()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.9332
c 0
b 0
f 0
cc 2
nc 2
nop 0
1
<?php
2
3
/*
4
 * This file is part of monofony.
5
 *
6
 * (c) Mobizel
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 App\Dashboard;
15
16
use App\Dashboard\Statistics\StatisticInterface;
17
use Webmozart\Assert\Assert;
18
19
class DashboardStatisticsProvider
20
{
21
    /** @var iterable&StatisticInterface[] */
22
    private $statistics;
23
24
    public function __construct(iterable $statistics)
25
    {
26
        $this->statistics = $statistics;
27
    }
28
29
    public function getStatistics(): array
30
    {
31
        $statistics = [];
32
        foreach ($this->statistics as $statistic) {
33
            Assert::implementsInterface($statistic, StatisticInterface::class, sprintf('Class %s must implement %s', get_class($statistic), StatisticInterface::class));
34
            $statistics[] = $statistic->generate();
35
        }
36
37
        return $statistics;
38
    }
39
}
40