Passed
Push — master ( c86b68...6e4e21 )
by Patrick
01:30 queued 12s
created

ActivityCollector::mergeActivityDtoCollections()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 4
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 8
ccs 5
cts 5
cp 1
crap 2
rs 10
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