DefaultCommand   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 29
c 2
b 0
f 0
dl 0
loc 54
rs 10
wmc 6

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A __destruct() 0 3 1
A addLog() 0 4 1
A execute() 0 24 3
1
<?php
2
3
namespace ControleOnline\Command;
4
5
use Symfony\Component\Console\Command\Command;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Console\Command\Command was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
use Symfony\Component\Console\Input\InputInterface;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Console\Input\InputInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
7
use Symfony\Component\Console\Output\OutputInterface;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Console\Output\OutputInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
use Symfony\Component\Lock\LockFactory;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Lock\LockFactory was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
9
use ControleOnline\Service\DatabaseSwitchService;
0 ignored issues
show
Bug introduced by
The type ControleOnline\Service\DatabaseSwitchService was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
10
use Symfony\Component\Console\Input\InputArgument;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Console\Input\InputArgument was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
11
use Symfony\Component\Console\Input\InputOption;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Console\Input\InputOption was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
12
13
abstract class DefaultCommand extends Command
14
{
15
    protected $input;
16
    protected $output;
17
    protected $lock;
18
    protected $lockFactory;
19
    protected $databaseSwitchService;
20
    protected $loggerService;
21
    protected $skyNetService;
22
23
    abstract protected function runCommand(): int;
24
25
    public function __construct(string $name)
26
    {
27
        parent::__construct($name);
28
        $this->lock = $this->lockFactory->createLock($name);
29
        $this->addOption('domain', ['d'], InputOption::VALUE_OPTIONAL,  'Database domain identifier');
30
    }
31
32
    protected function execute(InputInterface $input, OutputInterface $output): int
33
    {
34
        $this->input = $input;
35
        $this->output = $output;
36
37
        $domain = $input->getOption('domain');
38
39
        if ($domain) {
40
            $this->addLog(sprintf('Executando worker para o domínio: %s', $domain));
41
            $this->databaseSwitchService->switchDatabaseByDomain($domain);
42
            $this->skyNetService->discoveryBotUser();
43
            return $this->runCommand();
44
        }
45
46
        $domains = $this->databaseSwitchService->getAllDomains();
47
48
        foreach ($domains as $domain) {
49
            $this->addLog(sprintf('Executando migrações para o domínio: %s', $domain));
50
            $this->databaseSwitchService->switchDatabaseByDomain($domain);
51
            $this->skyNetService->discoveryBotUser();
52
            $this->runCommand();
53
        }
54
55
        return Command::SUCCESS;
56
    }
57
58
    public function addLog(string|iterable $messages, int $options = 0, ?string $logName = 'integration')
59
    {
60
        $this->output->writeln($messages, $options);
61
        $this->loggerService->getLogger($logName)->info($messages);
62
    }
63
64
    public function __destruct()
65
    {
66
        $this->lock->release();
67
    }
68
}
69