Completed
Pull Request — master (#46)
by Ekin
06:38
created

src/Event/GitHub/IssuesEvent.php (1 issue)

Labels
Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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\Clav;
10
use ekinhbayar\GitAmp\Presentation\Sound\ClavEgg;
11
use ekinhbayar\GitAmp\Presentation\Type;
12
13
class IssuesEvent extends BaseEvent
14
{
15
    private const SPECIAL_REPOSITORIES = [
16
        'ekinhbayar/gitamp',
17
        'amphp/amp',
18
    ];
19
20 2
    public function __construct(array $event)
21
    {
22 2
        parent::__construct(
23 2
            (int) $event['id'],
24 2
            new Type(3),
25 2
            new Information(
26 2
                $event['payload']['issue']['html_url'],
27 2
                $event['payload']['issue']['title'],
28 2
                $this->buildMessage($event)
29
            ),
30 2
            new Ring(3000, 80),
31 2
            $this->buildSound($event),
32
        );
0 ignored issues
show
This code did not parse for me. Apparently, there is an error somewhere around this line:

Syntax error, unexpected ')'
Loading history...
33
    }
34
35 2
    private function buildMessage(array $event): string
36
    {
37 2
        return \sprintf(
38 2
            '%s %s an issue in %s',
39 2
            $event['actor']['login'],
40 2
            $event['payload']['action'],
41 2
            $event['repo']['name'],
42
        );
43
    }
44
45 2
    private function buildSound(array $event): BaseSound
46
    {
47 2
        if (\in_array($event['repo']['name'], self::SPECIAL_REPOSITORIES, true)) {
48 1
            return new ClavEgg();
49
        }
50
51 1
        return new Clav(\strlen($event['payload']['issue']['title']) * 1.1);
52
    }
53
}
54