AllCommand   A
last analyzed

Complexity

Total Complexity 12

Size/Duplication

Total Lines 120
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 5

Importance

Changes 0
Metric Value
wmc 12
lcom 2
cbo 5
dl 0
loc 120
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 13 1
A execute() 0 24 5
A executeStart() 0 10 2
A executeEnd() 0 8 2
A afterScan() 0 8 2
1
<?php
2
/**
3
 * Mage Scan
4
 *
5
 * PHP version 5
6
 *
7
 * @category  MageScan
8
 * @package   MageScan
9
 * @author    Steve Robbins <[email protected]>
10
 * @copyright 2015 Steve Robbins
11
 * @license   http://creativecommons.org/licenses/by/4.0/ CC BY 4.0
12
 * @link      https://github.com/steverobbins/magescan
13
 */
14
15
namespace MageScan\Command\Scan;
16
17
use MageScan\Url;
18
use Symfony\Component\Console\Input\ArrayInput;
19
use Symfony\Component\Console\Input\InputInterface;
20
use Symfony\Component\Console\Input\InputOption;
21
use Symfony\Component\Console\Output\NullOutput;
22
use Symfony\Component\Console\Output\OutputInterface;
23
24
/**
25
 * Run all scan commands
26
 *
27
 * @category  MageScan
28
 * @package   MageScan
29
 * @author    Steve Robbins <[email protected]>
30
 * @copyright 2015 Steve Robbins
31
 * @license   http://creativecommons.org/licenses/by/4.0/ CC BY 4.0
32
 * @link      https://github.com/steverobbins/magescan
33
 */
34
class AllCommand extends AbstractCommand
35
{
36
    /**
37
     * Names of all the scans
38
     *
39
     * @var array
40
     */
41
    protected $scanNames = [
42
        'scan:version',
43
        'scan:module',
44
        'scan:catalog',
45
        'scan:patch',
46
        'scan:sitemap',
47
        'scan:server',
48
        'scan:unreachable',
49
    ];
50
51
    /**
52
     * Configure command
53
     *
54
     * @return void
55
     */
56
    protected function configure()
57
    {
58
        $this
59
            ->setName('scan:all')
60
            ->setDescription('Run all scans')
61
            ->addOption(
62
                'show-modules',
63
                null,
64
                InputOption::VALUE_NONE,
65
                'Show all modules that were scanned for, not just matches'
66
            );
67
        parent::configure();
68
    }
69
70
    /**
71
     * Execute command
72
     *
73
     * @param InputInterface  $input
74
     * @param OutputInterface $output
75
     *
76
     * @return void
77
     */
78
    protected function execute(InputInterface $input, OutputInterface $output)
79
    {
80
        $url = new Url;
81
        $url = $url->clean($input->getArgument('url'));
0 ignored issues
show
Bug introduced by
It seems like $input->getArgument('url') targeting Symfony\Component\Consol...nterface::getArgument() can also be of type array<integer,string>; however, MageScan\Url::clean() does only seem to accept string, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
82
        $format = $input->getOption('format');
83
        $this->executeStart($format, $url);
84
        $scanCount = count($this->scanNames);
85
        foreach ($this->scanNames as $i => $commandName) {
86
            $command = $this->getApplication()->find($commandName);
87
            $args = [
88
                'command'  => $commandName,
89
                'url'      => $url,
90
                '--format' => $format,
91
            ];
92
            if ($commandName === 'scan:module' && $input->getOption('show-modules')) {
93
                $args['--show-modules'] = true;
94
            }
95
            $command->run(new ArrayInput($args), $output);
96
            if (++$i < $scanCount) {
97
                $this->afterScan($format);
98
            }
99
        }
100
        $this->executeEnd($format);
101
    }
102
103
    /**
104
     * Things to output when execusion starts
105
     *
106
     * @param string $format
107
     * @param string $url
108
     *
109
     * @return void
110
     */
111
    protected function executeStart($format, $url)
112
    {
113
        switch ($format) {
114
            case 'json':
115
                echo '[';
116
                break;
117
            default:
118
                $this->output->writeln(sprintf('Scanning <info>%s</info>...', $url));
119
        }
120
    }
121
122
    /**
123
     * Things to output when execusion ends
124
     *
125
     * @param string $format
126
     *
127
     * @return void
128
     */
129
    protected function executeEnd($format)
130
    {
131
        switch ($format) {
132
            case 'json':
133
                echo ']';
134
                break;
135
        }
136
    }
137
138
    /**
139
     * Things to output after a scan
140
     *
141
     * @param string $format
142
     *
143
     * @return void
144
     */
145
    protected function afterScan($format)
146
    {
147
        switch ($format) {
148
            case 'json':
149
                echo ',';
150
                break;
151
        }
152
    }
153
}
154