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

PushEvent::buildSound()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 8
Ratio 100 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
dl 8
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\Type;
8
use ekinhbayar\GitAmp\Presentation\Ring;
9
use ekinhbayar\GitAmp\Presentation\Sound\BaseSound;
10
use ekinhbayar\GitAmp\Presentation\Sound\Celesta;
11
use ekinhbayar\GitAmp\Presentation\Sound\CelestaEgg;
12
13
class PushEvent 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(1),
25 4
            new Information($this->buildUrl($event), $this->buildPayload($event), $this->buildMessage($event)),
26 4
            new Ring(3000, 80),
27 4
            $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 4
    private function buildUrl(array $event): string
32
    {
33 4
        return 'https://github.com/' . $event['repo']['name'];
34
    }
35
36 4
    private function buildPayload(array $event): string
37
    {
38 4
        if (isset($event['payload']['commits'][0]['message'])) {
39 2
            return $event['payload']['commits'][0]['message'];
40
        }
41
42 2
        return 'https://github.com/' . $event['actor']['login'];
43
    }
44
45 4
    private function buildMessage(array $event): string
46
    {
47 4
        return \sprintf('%s pushed to %s', $event['actor']['login'], $event['repo']['name']);
48
    }
49
50 4
    private function buildSound(array $event): BaseSound
51
    {
52 4
        if (\in_array($event['repo']['name'], self::SPECIAL_REPOSITORIES, true)) {
53 2
            return new CelestaEgg();
54
        }
55
56 2
        return new Celesta(\strlen($this->buildPayload($event)) * 1.1);
57
    }
58
}
59