AbstractCIKubernetesDeployJobEvent::afterExecute()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

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