SendCommentService::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 2
1
<?php
2
namespace TheCodingMachine\WashingMachine\Gitlab;
3
4
use Gitlab\Client;
5
use TheCodingMachine\WashingMachine\Clover\Analysis\Difference;
6
use TheCodingMachine\WashingMachine\Clover\CrapMethodFetcherInterface;
7
use TheCodingMachine\WashingMachine\Clover\DiffService;
8
9
class SendCommentService
10
{
11
    /**
12
     * @var Client
13
     */
14
    private $client;
15
    /**
16
     * @var DiffService
17
     */
18
    private $diffService;
19
20
    public function __construct(Client $client, DiffService $diffService)
21
    {
22
        $this->client = $client;
23
        $this->diffService = $diffService;
24
    }
25
26
27
    public function sendDifferencesCommentsInCommit(CrapMethodFetcherInterface $cloverFile, CrapMethodFetcherInterface $previousCloverFile, string $projectName, string $commitId, string $gitlabUrl)
28
    {
29
        $differences = $this->diffService->getMeaningfulDifferences($cloverFile, $previousCloverFile);
30
31
        foreach ($differences as $difference) {
32
            $message = new Message();
33
            $message->addDifference($difference, $commitId, $gitlabUrl, $projectName);
34
35
            $options = [];
36
            if ($difference->getFile() !== null) {
37
                $options = [
38
                    'path' => $difference->getFile(),
39
                    'line' => $difference->getLine(),
40
                    'line_type' => 'new'
41
                ];
42
            }
43
44
            $this->client->repositories->createCommitComment($projectName, $commitId, (string) $message, $options);
45
        }
46
    }
47
}
48