ReplaceCommand::configure()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 8
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace MyBuilder\Bundle\CronosBundle\Command;
4
5
use Symfony\Component\Console\Input\InputInterface;
6
use Symfony\Component\Console\Output\OutputInterface;
7
8
class ReplaceCommand extends CommandBase
9
{
10
    /**
11
     * @inheritdoc
12
     */
13
    protected function configure()
14
    {
15
        $this
16
            ->setName('cronos:replace')
17
            ->setDescription('Replace the current content of your crontab with the cron annotations within this project');
18
19
        $this->addServerOption();
20
    }
21
22
    /**
23
     * @inheritdoc
24
     */
25
    protected function execute(InputInterface $input, OutputInterface $output)
26
    {
27
        $cron = $this->configureCronExport($input, $output);
28
        $key = $this->getExportKey();
29
30
        try {
31
            $this->getContainer()->get('mybuilder.cronos_bundle.cron_process_updater')->updateWith($cron, $key);
32
            $output->writeln(sprintf('<info>Cron successfully updated with key </info><comment>%s</comment>', $key));
33
        } catch (\RuntimeException $e) {
34
            $output->writeln(sprintf('<comment>Cron cannot be updated - %s</comment>', $e->getMessage()));
35
        }
36
37
        return 0;
38
    }
39
40
    private function getExportKey()
41
    {
42
        $config = $this->getContainer()->getParameter('mybuilder.cronos_bundle.exporter_config');
43
44
        return $config['key'];
45
    }
46
}
47