Passed
Pull Request — master (#19)
by Patrick
03:30
created

ActivityCollector   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 22
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A mergeActivityDtoCollections() 0 10 1
A __construct() 0 2 1
A collect() 0 4 1
1
<?php
2
3
declare(strict_types = 1);
4
5
/*
6
 * This file is part of forecast.it.fill project.
7
 * (c) Patrick Jaja <[email protected]>
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
namespace ForecastAutomation\Activity\Business;
13
14
use ForecastAutomation\Activity\Shared\Dto\ActivityDtoCollection;
15
use ForecastAutomation\Activity\Shared\Plugin\ActivityPluginCollection;
16
use GuzzleHttp\Promise\Utils;
17
18
class ActivityCollector
19
{
20 1
    public function __construct(private ActivityPluginCollection $activityPluginCollection)
21
    {
22 1
    }
23
24 1
    public function collect(): ActivityDtoCollection
25
    {
26 1
        $activityDtoCollections = Utils::all($this->activityPluginCollection->collect())->wait();
27 1
        return $this->mergeActivityDtoCollections($activityDtoCollections);
28
    }
29
30 1
    private function mergeActivityDtoCollections(array $activityDtoCollections): ActivityDtoCollection
31
    {
32 1
        $mergedActivityDtoCollection = new ActivityDtoCollection();
33 1
        array_map(
34 1
            static fn($activityDtoCollection): ActivityDtoCollection => $mergedActivityDtoCollection->merge(
35 1
                $activityDtoCollection
36 1
            ),
37
            $activityDtoCollections
38
        );
39 1
        return $mergedActivityDtoCollection;
40
    }
41
}
42