Completed
Push — master ( be473f...8253c0 )
by Vladimir
05:20
created

CheckHealthCommand::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 2
dl 0
loc 5
ccs 0
cts 4
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * This file is part of the `tvi/monitor-bundle` project.
5
 *
6
 * (c) https://github.com/turnaev/monitor-bundle/graphs/contributors
7
 *
8
 * For the full copyright and license information, please view the LICENSE.md
9
 * file that was distributed with this source code.
10
 */
0 ignored issues
show
Coding Style introduced by
PHP version not specified
Loading history...
Coding Style introduced by
Missing @category tag in file comment
Loading history...
Coding Style introduced by
Missing @package tag in file comment
Loading history...
Coding Style introduced by
Missing @author tag in file comment
Loading history...
Coding Style introduced by
Missing @license tag in file comment
Loading history...
Coding Style introduced by
Missing @link tag in file comment
Loading history...
11
12
namespace Tvi\MonitorBundle\Command;
13
14
use Symfony\Component\Console\Command\Command;
15
use Symfony\Component\Console\Input\InputInterface;
16
use Symfony\Component\Console\Input\InputOption;
17
use Symfony\Component\Console\Output\OutputInterface;
18
use Tvi\MonitorBundle\Runner\Manager;
19
use Tvi\MonitorBundle\Runner\Reporter\ConsoleReporter;
20
use Tvi\MonitorBundle\Runner\Reporter\RawConsoleReporter;
21
22
/**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
23
 * @author Vladimir Turnaev <[email protected]>
24
 */
0 ignored issues
show
Coding Style introduced by
Missing @category tag in class comment
Loading history...
Coding Style introduced by
Missing @package tag in class comment
Loading history...
Coding Style introduced by
Missing @license tag in class comment
Loading history...
Coding Style introduced by
Missing @link tag in class comment
Loading history...
25
class CheckHealthCommand extends Command
26
{
27
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
28
     * @var Manager
29
     */
30
    private $manager;
0 ignored issues
show
Coding Style introduced by
Private member variable "manager" must be prefixed with an underscore
Loading history...
31
32
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
Coding Style introduced by
Parameter $manager should have a doc-comment as per coding-style.
Loading history...
33
     * @param ?string $name
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Doc comment for parameter $name does not match actual variable name $manager
Loading history...
34
     */
35
    public function __construct(Manager $manager, string $name = null)
36
    {
37
        parent::__construct($name);
38
39
        $this->manager = $manager;
40
    }
41
42
    protected function configure()
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function configure()
Loading history...
43
    {
44
        $this
45
            ->setName('tvi:monitor:check:info')
46
            ->setDescription('Runs health checks')
47
            ->addOption(
48
                'reporter',
49
                'r',
50
                InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY,
51
                'Additional reporters to run.',
52
                ['sss']
53
            )
54
            ->addOption(
55
                'check',
56
                'c',
57
                InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY,
58
                'Check filter'
59
            )
60
            ->addOption(
61
                'group',
62
                'g',
63
                InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY,
64
                'Groups filter'
65
            )
66
            ->addOption(
67
                'tag',
68
                't',
69
                InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY,
70
                'Tag(s) filter'
71
            )
72
            ->setHelp(
73
                <<<'EOT'
74
The <info>%command.name%</info> get check info
75
76
* INfo Checks:
77
78
  <info>php %command.full_name% [--check=... ,] [--group=... ,] [--tag==... ,] </info>
79
80
EOT
81
            );
82
    }
83
84
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
Coding Style introduced by
Parameter $input should have a doc-comment as per coding-style.
Loading history...
Coding Style introduced by
Parameter $output should have a doc-comment as per coding-style.
Loading history...
85
     * @return int|null|void
86
     */
87
    protected function execute(InputInterface $input, OutputInterface $output)
88
    {
89
        $checkFilter = $input->getOption('check');
90
        $groupFilter = $input->getOption('group');
91
        $tagFilter = $input->getOption('tag');
92
93
        $runner = $this->manager->getRunner($checkFilter, $groupFilter, $tagFilter);
94
95
        $reporter = new ConsoleReporter($output);
96
        $runner->addReporter($reporter);
97
98
//        $reporter = new RawConsoleReporter($output);
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected at least 8 spaces, found 0
Loading history...
99
//        $runner->addReporter($reporter);
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected at least 8 spaces, found 0
Loading history...
100
101
        $runner->run();
102
    }
103
}
104