Completed
Push — master ( 328402...1cd18c )
by Julien
587:13 queued 584:54
created

getEventName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace TheAentMachine\Aent\Event\CI;
4
5
use Safe\Exceptions\StringsException;
6
use TheAentMachine\Aent\Context\Context;
7
use TheAentMachine\Aent\Event\AbstractJsonEvent;
8
use TheAentMachine\Aent\Payload\CI\DockerComposeDeployJobPayload;
9
use function Safe\sprintf;
10
11
abstract class AbstractCIDockerComposeDeployJobEvent extends AbstractJsonEvent
12
{
13
    /**
14
     * @param string $dockerComposeFilename
15
     * @return void
16
     */
17
    abstract protected function addDeployJob(string $dockerComposeFilename): void;
18
19
    /**
20
     * @return string
21
     */
22
    protected function getEventName(): string
23
    {
24
        return 'DOCKER_COMPOSE_DEPLOY_JOB';
25
    }
26
27
    /**
28
     * @return bool
29
     */
30
    protected function shouldRegisterEvents(): bool
31
    {
32
        return false;
33
    }
34
35
    /**
36
     * @return void
37
     * @throws StringsException
38
     */
39
    protected function beforeExecute(): void
40
    {
41
        /** @var Context $context */
42
        $context = Context::fromMetadata();
43
        $this->output->writeln(sprintf(
44
            "\nšŸ‘‹ Hello! I'm the aent <info>%s</info> and I'm going to setup a deploy job for Docker Compose on your <info>%s</info> environment <info>%s</info>.",
45
            $this->getAentName(),
46
            $context->getEnvironmentType(),
47
            $context->getEnvironmentName()
48
        ));
49
    }
50
51
    /**
52
     * @param array<string,string> $payload
53
     * @return mixed[]|null
54
     */
55
    protected function executeJsonEvent(array $payload): ?array
56
    {
57
        $payload = DockerComposeDeployJobPayload::fromArray($payload);
58
        $this->addDeployJob($payload->getDockerComposeFilename());
59
        return null;
60
    }
61
62
    /**
63
     * @return void
64
     * @throws StringsException
65
     */
66
    protected function afterExecute(): void
67
    {
68
        /** @var Context $context */
69
        $context = Context::fromMetadata();
70
        $this->output->writeln(
71
            sprintf(
72
                "\nI've added the deploy job for Docker Compose on your <info>%s</info> environment <info>%s</info>. See you later!",
73
                $context->getEnvironmentType(),
74
                $context->getEnvironmentName()
75
            )
76
        );
77
    }
78
}
79