IssueCommentEvent   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 17
dl 0
loc 52
ccs 21
cts 21
cp 1
rs 10
c 0
b 0
f 0
wmc 6

4 Methods

Rating   Name   Duplication   Size   Complexity  
A buildPayload() 0 7 2
A buildSound() 0 7 2
A buildMessage() 0 3 1
A __construct() 0 12 1
1
<?php declare(strict_types=1);
2
3
namespace ekinhbayar\GitAmp\Event\GitHub;
4
5
use ekinhbayar\GitAmp\Event\BaseEvent;
6
use ekinhbayar\GitAmp\Presentation\Information;
7
use ekinhbayar\GitAmp\Presentation\Ring;
8
use ekinhbayar\GitAmp\Presentation\Sound\BaseSound;
9
use ekinhbayar\GitAmp\Presentation\Sound\Clav;
10
use ekinhbayar\GitAmp\Presentation\Sound\ClavEgg;
11
use ekinhbayar\GitAmp\Presentation\Type;
12
13
class IssueCommentEvent extends BaseEvent
14
{
15
    /**
16
     * @param array<string,mixed> $event
17
     * @param array<string> $specialRepositories
18
     */
19 4
    public function __construct(array $event, array $specialRepositories)
20
    {
21 4
        parent::__construct(
22 4
            (int) $event['id'],
23 4
            new Type(Type::COMMENTED_ON_ISSUE),
24 4
            new Information(
25 4
                $event['payload']['issue']['html_url'],
26 4
                $this->buildPayload($event),
27 4
                $this->buildMessage($event),
28
            ),
29 4
            new Ring(3000, 80),
30 4
            $this->buildSound($event, $specialRepositories),
31
        );
32 4
    }
33
34
    /**
35
     * @param array<string,mixed> $event
36
     */
37 4
    private function buildPayload(array $event): string
38
    {
39 4
        if (isset($event['comment']['body'])) {
40 2
            return $event['comment']['body'];
41
        }
42
43 2
        return $event['payload']['issue']['title'];
44
    }
45
46
    /**
47
     * @param array<string,mixed> $event
48
     */
49 4
    private function buildMessage(array $event): string
50
    {
51 4
        return \sprintf('%s commented in %s', $event['actor']['login'], $event['repo']['name']);
52
    }
53
54
    /**
55
     * @param array<string,mixed> $event
56
     * @param array<string> $specialRepositories
57
     */
58 4
    private function buildSound(array $event, array $specialRepositories): BaseSound
59
    {
60 4
        if (in_array($event['repo']['name'], $specialRepositories, true)) {
61 2
            return new ClavEgg();
62
        }
63
64 2
        return new Clav(\strlen($this->buildPayload($event)) * 1.1);
65
    }
66
}
67