Passed
Branch master (e04148)
by Patrick
03:20
created

JiraActivityPlugin   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 16
dl 0
loc 28
ccs 14
cts 14
cp 1
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A collect() 0 3 1
A createActivityDtoCollection() 0 18 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\JiraClient\Shared\Plugin;
13
14
use ForecastAutomation\Activity\Shared\Dto\ActivityDto;
15
use ForecastAutomation\Activity\Shared\Dto\ActivityDtoCollection;
16
use ForecastAutomation\Activity\Shared\Plugin\ActivityPluginInterface;
17
use ForecastAutomation\Kernel\Shared\Plugin\AbstractPlugin;
18
19
/**
20
 * @method \ForecastAutomation\JiraClient\JiraClientFacade getFacade()
21
 */
22
class JiraActivityPlugin extends AbstractPlugin implements ActivityPluginInterface
23
{
24
    public const ACTIVITY_DURATION = 30;
25
    public const COMMENT_IDENTIFIER = 'Ticket Bearbeitung';
26
27 1
    public function collect(): ActivityDtoCollection
28
    {
29 1
        return $this->createActivityDtoCollection($this->getFacade()->getComments(date('Y-m-d 00:00')));
30
    }
31
32 1
    private function createActivityDtoCollection(array $jiraComments): ActivityDtoCollection
33
    {
34 1
        $activityDtoArray = [];
35 1
        foreach ($jiraComments as $jiraTicketNumber => $jiraComment) {
36 1
            $activityDtoArray[] = new ActivityDto(
37 1
                $jiraTicketNumber,
38 1
                sprintf(
39 1
                    '%s: %s - %s',
40 1
                    self::COMMENT_IDENTIFIER,
41
                    $jiraTicketNumber,
42 1
                    sprintf('%s...', substr(preg_replace('/\[[^)]+\]/', '', $jiraComment[0]->body), 0, 60))
43
                ),
44 1
                new \DateTime($jiraComment[0]->updated),
45 1
                self::ACTIVITY_DURATION * \count($jiraComment)
46
            );
47
        }
48
49 1
        return new ActivityDtoCollection(...$activityDtoArray);
50
    }
51
}
52