PullRequestEvent   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 18
dl 0
loc 45
ccs 20
cts 20
cp 1
rs 10
c 0
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A buildSound() 0 7 2
A __construct() 0 12 1
A buildMessage() 0 7 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\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 PullRequestEvent extends BaseEvent
14
{
15
    /**
16
     * @param array<string,mixed> $event
17
     * @param array<string> $specialRepositories
18
     */
19 2
    public function __construct(array $event, array $specialRepositories)
20
    {
21 2
        parent::__construct(
22 2
            (int) $event['id'],
23 2
            new Type(Type::PR_ACTION),
24 2
            new Information(
25 2
                $event['payload']['pull_request']['html_url'],
26 2
                $event['payload']['pull_request']['title'],
27 2
                $this->buildMessage($event),
28
            ),
29 2
            new Ring(10000, 600),
30 2
            $this->buildSound($event, $specialRepositories),
31
        );
32 2
    }
33
34
    /**
35
     * @param array<string,mixed> $event
36
     */
37 2
    private function buildMessage(array $event): string
38
    {
39 2
        return \sprintf(
40
            '%s %s a PR for %s',
41 2
            $event['actor']['login'],
42 2
            $event['payload']['action'],
43 2
            $event['repo']['name'],
44
        );
45
    }
46
47
    /**
48
     * @param array<string,mixed> $event
49
     * @param array<string> $specialRepositories
50
     */
51 2
    private function buildSound(array $event, array $specialRepositories): BaseSound
52
    {
53 2
        if (in_array($event['repo']['name'], $specialRepositories, true)) {
54 1
            return new SwellEgg();
55
        }
56
57 1
        return new Swell();
58
    }
59
}
60