Passed
Branch v2_rewrite (407290)
by Ekin
05:43
created

PushEvent::buildPayload()   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\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 4
    public function __construct(array $event)
16
    {
17 4
        parent::__construct(
18 4
            (int) $event['id'],
19 4
            new Type(1),
20 4
            new Information($this->buildUrl($event), $this->buildPayload($event), $this->buildMessage($event)),
21 4
            new Ring(3000, 80),
22 4
            $this->buildSound($event)
23
        );
24
    }
25
26 4
    private function buildUrl(array $event): string
27
    {
28 4
        return 'https://github.com/' . $event['repo']['name'];
29
    }
30
31 4
    private function buildPayload(array $event): string
32
    {
33 4
        if (isset($event['payload']['commits'][0]['message'])) {
34 2
            return $event['payload']['commits'][0]['message'];
35
        }
36
37 2
        return 'https://github.com/' . $event['actor']['login'];
38
    }
39
40 4
    private function buildMessage(array $event): string
41
    {
42 4
        return \sprintf('%s pushed to %s', $event['actor']['login'], $event['repo']['name']);
43
    }
44
45 4 View Code Duplication
    private function buildSound(array $event): BaseSound
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
46
    {
47 4
        if ($event['repo']['name'] === 'ekinhbayar/gitamp') {
48 2
            return new CelestaEgg();
49
        }
50
51 2
        return new Celesta(\strlen($this->buildPayload($event)) * 1.1);
52
    }
53
}
54