JiraCollector   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 16
dl 0
loc 31
ccs 18
cts 18
cp 1
rs 10
c 0
b 0
f 0
wmc 7

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 2 1
A getComments() 0 25 6
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\Business;
13
14
use ForecastAutomation\JiraClient\Shared\Dto\JiraConfigDto;
15
use JiraRestApi\Issue\Issue;
16
use JiraRestApi\Issue\IssueService;
17
18
/**
19
 * @method \ForecastAutomation\JiraClient\JiraClientFactory getFactory()
20
 */
21
class JiraCollector
22
{
23 1
    public function __construct(private JiraConfigDto $jiraConfigDto, private IssueService $jiraClient)
24
    {
25 1
    }
26
27 1
    public function getComments(string $startDate): array
28
    {
29 1
        $activities = $this->jiraClient->search(
30 1
            sprintf($this->jiraConfigDto->jiraQuery, $startDate),
31 1
            0,
32 1
            $this->jiraConfigDto->jiraMaxResults
33
        );
34 1
        $ticketList = array_map(
35 1
            static fn (Issue $issue) => $issue->key,
36 1
            $activities->getIssues()
37
        );
38
39 1
        $jiraActivities = [];
40 1
        foreach ($ticketList as $issueKey) {
41 1
            $comments = $this->jiraClient->getComments($issueKey);
42 1
            foreach ($comments->comments as $comment) {
43 1
                $passedDate = \DateTime::createFromFormat('Y-m-d H:i', $startDate);
44 1
                if (($comment->updated >= $passedDate)
45 1
                    && (isset($comment->author->emailAddress) && $comment->author->emailAddress === $this->jiraConfigDto->jiraUser)) {
46
                    $jiraActivities[$issueKey][] = $comment;
47
                }
48
            }
49
        }
50 1
51
        return $jiraActivities;
52
    }
53
}
54