Test Setup Failed
Pull Request — master (#46)
by Ekin
06:26
created

IssueCommentEvent::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 14
ccs 10
cts 10
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 10
nc 1
nop 1
crap 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
    private const SPECIAL_REPOSITORIES = [
16
        'ekinhbayar/gitamp',
17
        'amphp/amp',
18
    ];
19
20 4
    public function __construct(array $event)
21
    {
22 4
        parent::__construct(
23 4
            (int) $event['id'],
24 4
            new Type(4),
25 4
            new Information(
26 4
                $event['payload']['issue']['html_url'],
27 4
                $this->buildPayload($event),
28 4
                $this->buildMessage($event)
29
            ),
30 4
            new Ring(3000, 80),
31 4
            $this->buildSound($event),
32
        );
0 ignored issues
show
Bug introduced by
This code did not parse for me. Apparently, there is an error somewhere around this line:

Syntax error, unexpected ')'
Loading history...
33
    }
34
35 4
    private function buildPayload(array $event): string
36
    {
37 4
        if (isset($event['comment']['body'])) {
38 2
            return $event['comment']['body'];
39
        }
40
41 2
        return $event['payload']['issue']['title'];
42
    }
43
44 4
    private function buildMessage(array $event): string
45
    {
46 4
        return \sprintf('%s commented in %s', $event['actor']['login'], $event['repo']['name']);
47
    }
48
49 4
    private function buildSound(array $event): BaseSound
50
    {
51 4
        if (\in_array($event['repo']['name'], self::SPECIAL_REPOSITORIES, true)) {
52 2
            return new ClavEgg();
53
        }
54
55 2
        return new Clav(\strlen($this->buildPayload($event)) * 1.1);
56
    }
57
}
58