GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( e9f02a...2016a5 )
by Freek
01:49
created

ScanCommand::configure()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 30
Code Lines 24

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 30
rs 8.8571
c 0
b 0
f 0
cc 1
eloc 24
nc 1
nop 0
1
<?php
2
3
namespace Spatie\HttpStatusCheck;
4
5
use Spatie\Crawler\Crawler;
6
use Spatie\Crawler\CrawlAllUrls;
7
use Spatie\Crawler\CrawlInternalUrls;
8
use Symfony\Component\Console\Command\Command;
9
use Symfony\Component\Console\Input\InputOption;
10
use Symfony\Component\Console\Input\InputArgument;
11
use Symfony\Component\Console\Input\InputInterface;
12
use Symfony\Component\Console\Output\OutputInterface;
13
use Symfony\Component\Console\Question\ConfirmationQuestion;
14
15
class ScanCommand extends Command
16
{
17
    protected function configure()
18
    {
19
        $this->setName('scan')
20
            ->setDescription('Check the http status code of all links on a website.')
21
            ->addArgument(
22
                'url',
23
                InputArgument::REQUIRED,
24
                'The url to check'
25
            )
26
            ->addOption(
27
                'concurrency',
28
                'c',
29
                InputOption::VALUE_REQUIRED,
30
                'The amount of concurrent connections to use',
31
                10
32
            )
33
            ->addOption(
34
                'output',
35
                'o',
36
                InputOption::VALUE_REQUIRED,
37
                'Log all non-2xx and non-3xx responses in this file'
38
            )
39
            ->addOption(
40
                'external',
41
                'x',
42
                InputOption::VALUE_REQUIRED,
43
                'Check external links',
44
                true
45
            );
46
    }
47
48
    /**
49
     * @param \Symfony\Component\Console\Input\InputInterface $input
50
     * @param \Symfony\Component\Console\Output\OutputInterface $output
51
     *
52
     * @return int
53
     */
54
    protected function execute(InputInterface $input, OutputInterface $output)
55
    {
56
        $baseUrl = $input->getArgument('url');
57
        $crawlProfile = $input->getOption('external') === 'false' ? new CrawlInternalUrls($baseUrl) : new CrawlAllUrls();
58
59
        $output->writeln("Start scanning {$baseUrl}");
60
        $output->writeln('');
61
62
        $crawlLogger = new CrawlLogger($output);
63
64
        if ($input->getOption('output')) {
65
            $outputFile = $input->getOption('output');
66
67
            if (file_exists($outputFile)) {
68
                $helper = $this->getHelper('question');
69
                $question = new ConfirmationQuestion(
70
                    "The output file `{$outputFile}` already exists. Overwrite it? (y/n)",
71
                    false
72
                );
73
74
                if (! $helper->ask($input, $output, $question)) {
75
                    $output->writeln('Aborting...');
76
77
                    return 0;
78
                }
79
            }
80
81
            $crawlLogger->setOutputFile($input->getOption('output'));
82
        }
83
84
        Crawler::create()
85
            ->setConcurrency($input->getOption('concurrency'))
86
            ->setCrawlObserver($crawlLogger)
87
            ->setCrawlProfile($crawlProfile)
88
            ->startCrawling($baseUrl);
89
90
        return 0;
91
    }
92
}
93