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

ActivityCollector   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 2 1
A collect() 0 5 1
A mergeActivityDtoCollections() 0 8 2
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
28 1
        return $this->mergeActivityDtoCollections($activityDtoCollections);
29
    }
30
31 1
    private function mergeActivityDtoCollections(array $activityDtoCollections): ActivityDtoCollection
32
    {
33 1
        $mergedActivityDtoCollection = new ActivityDtoCollection();
34 1
        foreach ($activityDtoCollections as $activityDtoCollection) {
35 1
            $mergedActivityDtoCollection->merge($activityDtoCollection);
36
        }
37
38 1
        return $mergedActivityDtoCollection;
39
    }
40
}
41