1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace whm\Smoke\Cli\Command; |
4
|
|
|
|
5
|
|
|
use phmLabs\Components\Annovent\Dispatcher; |
6
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
7
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
8
|
|
|
use Symfony\Component\Console\Input\InputOption; |
9
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
10
|
|
|
use whm\Html\Uri; |
11
|
|
|
use whm\Smoke\Config\Configuration; |
12
|
|
|
|
13
|
|
|
class ScanCommand extends SmokeCommand |
14
|
|
|
{ |
15
|
|
|
const CONFIG_FILE = 'analyze.yml'; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* {@inheritdoc} |
19
|
|
|
*/ |
20
|
|
|
protected function configure() |
21
|
|
|
{ |
22
|
|
|
$this |
23
|
|
|
->setDefinition([ |
24
|
|
|
new InputArgument('url', InputArgument::REQUIRED, 'the url to start with'), |
25
|
|
|
new InputOption('num_urls', 'u', InputOption::VALUE_OPTIONAL, 'number of urls to be checked', 20), |
26
|
|
|
new InputOption('run_level', 'l', InputOption::VALUE_OPTIONAL, 'limit the rules that are called', 10), |
27
|
|
|
]) |
28
|
|
|
->setDescription('analyses a website') |
29
|
|
|
->setHelp('The <info>analyse</info> command runs a cache test.') |
30
|
|
|
->setName('analyse'); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* {@inheritdoc} |
35
|
|
|
*/ |
36
|
|
View Code Duplication |
protected function execute(InputInterface $input, OutputInterface $output) |
37
|
|
|
{ |
38
|
|
|
$this->init($input, $output, $input->getArgument('url')); |
39
|
|
|
|
40
|
|
|
$this->initConfiguration( |
41
|
|
|
$input->getOption('num_urls'), |
42
|
|
|
$input->getOption('run_level'), |
43
|
|
|
new Uri($input->getArgument('url')), |
|
|
|
|
44
|
|
|
$this->eventDispatcher); |
45
|
|
|
|
46
|
|
|
return $this->scan(); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Initializes the configuration. |
51
|
|
|
* |
52
|
|
|
* @return Configuration |
53
|
|
|
*/ |
54
|
|
|
private function initConfiguration($num_urls, $run_level, Uri $uri, Dispatcher $dispatcher) |
55
|
|
|
{ |
56
|
|
|
$configArray = $this->getConfigArray(__DIR__ . '/../../settings/' . self::CONFIG_FILE); |
57
|
|
|
|
58
|
|
|
$config = new Configuration($uri, $dispatcher, $configArray); |
59
|
|
|
|
60
|
|
|
$crawler = $config->getExtension('_ResponseRetriever')->getRetriever(); |
61
|
|
|
$crawler->setStartPage($uri); |
62
|
|
|
|
63
|
|
|
$config->getExtension('_SmokeStop')->getStrategy('_CountStop')->init($num_urls); |
64
|
|
|
$config->getExtension('_ProgressBar')->setMax($num_urls); |
65
|
|
|
|
66
|
|
|
$config->getExtension('_SmokeRunLevel')->setRunLevel($run_level); |
67
|
|
|
|
68
|
|
|
$this->config = $config; |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
|
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.