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

CreateEvent::buildSound()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 1
crap 2
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\Swell;
10
use ekinhbayar\GitAmp\Presentation\Sound\SwellEgg;
11
use ekinhbayar\GitAmp\Presentation\Type;
12
13
class CreateEvent extends BaseEvent
14
{
15
    private const SPECIAL_REPOSITORIES = [
16
        'ekinhbayar/gitamp',
17
        'amphp/amp',
18
    ];
19
20 6
    public function __construct(array $event)
21
    {
22 6
        parent::__construct(
23 6
            (int) $event['id'],
24 6
            new Type(6),
25 6
            new Information($this->buildUrl($event), $this->buildPayload($event), $this->buildMessage($event)),
26 6
            new Ring(3000, 80),
27 6
            $this->buildSound($event),
28
        );
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...
29
    }
30
31 6
    private function buildUrl(array $event): string
32
    {
33 6
        return 'https://github.com/' . $event['repo']['name'];
34
    }
35
36 6
    private function buildPayload(array $event): string
37
    {
38 6
        if (isset($event['payload']['description'])) {
39 2
            return $event['payload']['description'];
40
        }
41
42 4
        return 'https://github.com/' . $event['repo']['name'];
43
    }
44
45 6
    private function buildMessage(array $event): string
46
    {
47 6
        return \sprintf('%s created %s', $event['actor']['login'], $event['repo']['name']);
48
    }
49
50 6
    private function buildSound(array $event): BaseSound
51
    {
52 6
        if (\in_array($event['repo']['name'], self::SPECIAL_REPOSITORIES, true)) {
53 3
            return new SwellEgg();
54
        }
55
56 3
        return new Swell();
57
    }
58
}
59