Passed
Push — master ( 055b76...bacc0b )
by Patrick
01:33 queued 12s
created

ForecastDataImportProcess   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Test Coverage

Coverage 94.12%

Importance

Changes 0
Metric Value
eloc 14
c 0
b 0
f 0
dl 0
loc 32
ccs 16
cts 17
cp 0.9412
rs 10
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A createMessageCollectionDto() 0 13 2
A __construct() 0 4 1
A start() 0 9 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\ForecastDataImport\Business;
13
14
use ForecastAutomation\Activity\ActivityFacade;
15
use ForecastAutomation\Activity\Shared\Dto\ActivityDtoCollection;
16
use ForecastAutomation\ForecastClient\Shared\Config\ForecastClientQueueConstants;
17
use ForecastAutomation\QueueClient\QueueClientFacade;
18
use ForecastAutomation\QueueClient\Shared\Dto\MessageCollectionDto;
19
use ForecastAutomation\QueueClient\Shared\Dto\MessageDto;
20
21
class ForecastDataImportProcess
22
{
23 1
    public function __construct(
24
        private ActivityFacade $activityFacade,
25
        private QueueClientFacade $queueClientFacade,
26
    ) {
27 1
    }
28
29 1
    public function start(): int
30
    {
31 1
        $activityDtoCollection = $this->activityFacade->collect();
32 1
        $this->queueClientFacade->sendMessages(
33 1
            ForecastClientQueueConstants::QUEUE_NAME,
34 1
            $this->createMessageCollectionDto($activityDtoCollection)
35
        );
36
37 1
        return \count($activityDtoCollection->activityDtos);
38
    }
39
40 1
    private function createMessageCollectionDto(ActivityDtoCollection $activityDtoCollection): MessageCollectionDto
41
    {
42 1
        $messages = [];
43 1
        foreach ($activityDtoCollection as $activityDto) {
44
            $messages[] =
45 1
                new MessageDto(
46 1
                    ['created' => $activityDto->created->format('c')] + (array) $activityDto,
47 1
                    ForecastClientQueueConstants::QUEUE_NAME,
48 1
                    ForecastClientQueueConstants::IMPORT_EVENT
49
                );
50
        }
51
52 1
        return new MessageCollectionDto(...$messages);
53
    }
54
}
55