Passed
Push — master ( 657f5c...767802 )
by Ekin
03:11
created

CreateEvent   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 6

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 7
lcom 0
cbo 6
dl 0
loc 41
ccs 19
cts 19
cp 1
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 10 1
A buildUrl() 0 4 1
A buildPayload() 0 8 2
A buildMessage() 0 4 1
A buildSound() 0 8 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\Swell;
11
use ekinhbayar\GitAmp\Presentation\Sound\SwellEgg;
12
13
class CreateEvent extends BaseEvent
14
{
15 6
    public function __construct(array $event)
16
    {
17 6
        parent::__construct(
18 6
            (int) $event['id'],
19 6
            new Type(6),
20 6
            new Information($this->buildUrl($event), $this->buildPayload($event), $this->buildMessage($event)),
21 6
            new Ring(3000, 80),
22 6
            $this->buildSound($event)
23
        );
24
    }
25
26 6
    private function buildUrl(array $event): string
27
    {
28 6
        return 'https://github.com/' . $event['repo']['name'];
29
    }
30
31 6
    private function buildPayload(array $event): string
32
    {
33 6
        if (isset($event['payload']['description'])) {
34 2
            return $event['payload']['description'];
35
        }
36
37 4
        return 'https://github.com/' . $event['repo']['name'];
38
    }
39
40 6
    private function buildMessage(array $event): string
41
    {
42 6
        return \sprintf('%s created %s', $event['actor']['login'], $event['repo']['name']);
43
    }
44
45 6
    private function buildSound(array $event): BaseSound
46
    {
47 6
        if ($event['repo']['name'] === 'ekinhbayar/gitamp') {
48 3
            return new SwellEgg();
49
        }
50
51 3
        return new Swell();
52
    }
53
}
54