| Conditions | 7 |
| Paths | 26 |
| Total Lines | 59 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 87 | protected function execute(InputInterface $input, OutputInterface $output) |
||
| 88 | { |
||
| 89 | $baseUrl = $input->getArgument('url'); |
||
| 90 | $crawlProfile = $input->getOption('dont-crawl-external-links') ? new CrawlInternalUrls($baseUrl) : new CrawlAllUrls(); |
||
| 91 | |||
| 92 | $output->writeln("Start scanning {$baseUrl}"); |
||
| 93 | $output->writeln(''); |
||
| 94 | |||
| 95 | $crawlLogger = new CrawlLogger($output); |
||
| 96 | |||
| 97 | if ($input->getOption('output')) { |
||
| 98 | $outputFile = $input->getOption('output'); |
||
| 99 | |||
| 100 | if (file_exists($outputFile)) { |
||
| 101 | $helper = $this->getHelper('question'); |
||
| 102 | $question = new ConfirmationQuestion( |
||
| 103 | "The output file `{$outputFile}` already exists. Overwrite it? (y/n)", |
||
| 104 | false |
||
| 105 | ); |
||
| 106 | |||
| 107 | if (! $helper->ask($input, $output, $question)) { |
||
| 108 | $output->writeln('Aborting...'); |
||
| 109 | |||
| 110 | return 0; |
||
| 111 | } |
||
| 112 | |||
| 113 | unlink($outputFile); |
||
| 114 | } |
||
| 115 | |||
| 116 | $crawlLogger->setOutputFile($input->getOption('output')); |
||
| 117 | } |
||
| 118 | |||
| 119 | $clientOptions = [ |
||
| 120 | RequestOptions::TIMEOUT => $input->getOption('timeout'), |
||
| 121 | RequestOptions::VERIFY => ! $input->getOption('skip-verification'), |
||
| 122 | RequestOptions::ALLOW_REDIRECTS => [ |
||
| 123 | 'track_redirects' => true, |
||
| 124 | ], |
||
| 125 | ]; |
||
| 126 | |||
| 127 | $clientOptions = array_merge($clientOptions, $input->getOption('options')); |
||
| 128 | |||
| 129 | if ($input->getOption('user-agent')) { |
||
| 130 | $clientOptions[RequestOptions::HEADERS]['user-agent'] = $input->getOption('user-agent'); |
||
| 131 | } |
||
| 132 | |||
| 133 | $crawler = Crawler::create($clientOptions) |
||
| 134 | ->setConcurrency($input->getOption('concurrency')) |
||
| 135 | ->setCrawlObserver($crawlLogger) |
||
| 136 | ->setCrawlProfile($crawlProfile); |
||
| 137 | |||
| 138 | if ($input->getOption('ignore-robots')) { |
||
| 139 | $crawler->ignoreRobots(); |
||
| 140 | } |
||
| 141 | |||
| 142 | $crawler->startCrawling($baseUrl); |
||
|
|
|||
| 143 | |||
| 144 | return 0; |
||
| 145 | } |
||
| 146 | } |
||
| 147 |
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.