Completed
Push — master ( 08e6f3...81e954 )
by Kirill
02:15
created

DeployCommand   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 7

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 0
cbo 7
dl 0
loc 35
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 12 1
A execute() 0 17 3
1
<?php
2
3
namespace Chrl\AppBundle\Command;
4
5
use Chrl\AppBundle\Entity\Game;
6
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
7
use Symfony\Component\Console\Input\InputDefinition;
8
use Symfony\Component\Console\Input\InputOption;
9
use Symfony\Component\Console\Output\OutputInterface;
10
use Symfony\Component\Console\Input\InputInterface;
11
12
class DeployCommand extends ContainerAwareCommand
13
{
14
    // This is just a normal Command::configure() method
15
    protected function configure()
16
    {
17
        $this->setName('buktopuha:deploy')
18
                ->setDescription('Tell all active games about deploy')
19
                ->setDefinition(
20
                    new InputDefinition(
21
                        [
22
                            new InputOption('success')
23
                        ]
24
                    )
25
                );
26
    }
27
28
    // Execute will be called in a endless loop
29
    protected function execute(InputInterface $input, OutputInterface $output)
30
    {
31
        $output->writeln('Executing...');
32
33
        $gs = $this->getContainer()->get('app.gameservice');
34
        $tgApi = $this->getContainer()->get('buktopuha.telegram_bot_api');
35
        $games = $gs->getActiveGames();
36
37
        /** @var Game $game */
38
        foreach ($games as $game) {
39
            if($input->getOption('success')) {
40
                $tgApi->sendMessage($game->chatId, 'Bot is back online! The game continues...');
41
            } else {
42
                $tgApi->sendMessage($game->chatId, 'Bot rebooting due to deploy, sorry. The game will continue once bot boots again.');
43
            }
44
        }
45
    }
46
}
47