Completed
Push — master ( 3e3b0a...f0448f )
by Julien
05:46 queued 03:36
created

NewDockerServiceInfoCommand::execute()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 17
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 10
nc 2
nop 2
dl 0
loc 17
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace TheAentMachine\AentDockerCompose\Command;
4
5
use Symfony\Component\Console\Command\Command;
6
use Symfony\Component\Console\Input\InputArgument;
7
use Symfony\Component\Console\Input\InputInterface;
8
use Symfony\Component\Console\Output\OutputInterface;
9
use Symfony\Component\Yaml\Yaml;
10
11
class NewDockerServiceInfoCommand extends Command
12
{
13
    protected function configure()
14
    {
15
        $this
16
            ->setName(Cst::NEW_DOCKER_SERVICE_INFO_EVENT)
17
            ->setDescription('Add a docker service to the docker-compose.yml')
18
            ->setHelp('TODO')
19
            ->addArgument('payload', InputArgument::OPTIONAL, 'The payload of the event');
20
    }
21
22
    protected function execute(InputInterface $input, OutputInterface $output)
23
    {
24
        $payload = $input->getArgument('payload');
25
        $formattedPayload = Utils::parsePayload($payload, $output);
26
27
        $yml = Yaml::dump($formattedPayload, 256, 4, Yaml::DUMP_OBJECT_AS_MAP);
28
        file_put_contents(Cst::TMP_YML_PATH, $yml);
29
30
        $dockerComposePath = getenv('PHEROMONE_CONTAINER_PROJECT_DIR') . '/docker-compose.yml';
31
32
        $yamlToolsCmd = array("yaml-tools", "merge", "-i", $dockerComposePath, Cst::TMP_YML_PATH, "-o", $dockerComposePath);
33
        $process = Utils::runAndGetProcess($yamlToolsCmd, $output);
34
        if (!$process->isSuccessful()) {
35
            exit($process->getExitCode());
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
36
        }
37
38
        unlink(Cst::TMP_YML_PATH);
39
    }
40
}
41