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.

ScanCommand   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 7
dl 0
loc 64
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 12 1
A execute() 0 31 3
A getClientOptions() 0 16 2
1
<?php
2
3
namespace Spatie\MixedContentScannerCli;
4
5
use GuzzleHttp\RequestOptions;
6
use Spatie\Crawler\Crawler;
7
use Spatie\MixedContentScanner\MixedContentScanner;
8
use Symfony\Component\Console\Command\Command;
9
use Symfony\Component\Console\Input\InputArgument;
10
use Symfony\Component\Console\Input\InputInterface;
11
use Symfony\Component\Console\Input\InputOption;
12
use Symfony\Component\Console\Output\OutputInterface;
13
use Symfony\Component\Console\Style\SymfonyStyle;
14
15
class ScanCommand extends Command
16
{
17
    protected function configure()
18
    {
19
        $this
20
            ->setName('scan')
21
            ->setDescription('Scan a site for mixed content.')
22
            ->addArgument('url', InputArgument::REQUIRED, 'Which argument do you want to scan')
23
            ->addOption('filter', null, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'urls whose path pass the regex will be scanned')
24
            ->addOption('ignore', null, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'urls whose path pass the regex will not be scanned')
25
            ->addOption('ignore-robots', null, InputOption::VALUE_NONE, 'Ignore robots.txt, robots meta tags and -headers.')
26
            ->addOption('verify-ssl', null, InputOption::VALUE_NONE, 'Verify the craweld urls have a valid certificate. If they do not an empty response will be the result of the crawl')
27
            ->addOption('user-agent', null, InputOption::VALUE_REQUIRED, 'User agent string to use for requests');
28
    }
29
30
    protected function execute(InputInterface $input, OutputInterface $output)
31
    {
32
        $scanUrl = $input->getArgument('url');
33
34
        $styledOutput = new SymfonyStyle($input, $output);
35
36
        $styledOutput->title("Start scanning {$scanUrl} for mixed content");
37
38
        $mixedContentLogger = new MixedContentLogger($styledOutput);
39
40
        $crawlProfile = new CrawlProfile(
41
            $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> or null; however, Spatie\MixedContentScann...lProfile::__construct() 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...
42
            $input->getOption('filter'),
43
            $input->getOption('ignore')
44
        );
45
46
        $ignoreRobots = $input->getOption('ignore-robots');
47
        $userAgent = $input->getOption('user-agent');
48
49
        (new MixedContentScanner($mixedContentLogger))
50
            ->configureCrawler(function (Crawler $crawler) use ($ignoreRobots, $userAgent) {
51
                if ($ignoreRobots) {
52
                    $crawler->ignoreRobots();
53
                }
54
                if ($userAgent) {
55
                    $crawler->setUserAgent($userAgent);
56
                }
57
            })
58
            ->setCrawlProfile($crawlProfile)
59
            ->scan($scanUrl, $this->getClientOptions($input));
0 ignored issues
show
Bug introduced by
It seems like $scanUrl defined by $input->getArgument('url') on line 32 can also be of type array<integer,string> or null; however, Spatie\MixedContentScann...dContentScanner::scan() does only seem to accept string, maybe add an additional type check?

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:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
60
    }
61
62
    protected function getClientOptions(InputInterface $input): array
63
    {
64
        $httpClientOptions = [
65
            RequestOptions::VERIFY => false,
66
            RequestOptions::COOKIES => true,
67
            RequestOptions::CONNECT_TIMEOUT => 10,
68
            RequestOptions::TIMEOUT => 10,
69
            RequestOptions::ALLOW_REDIRECTS => false,
70
        ];
71
72
        if ($input->getOption('verify-ssl')) {
73
            $httpClientOptions[RequestOptions::VERIFY] = true;
74
        }
75
76
        return $httpClientOptions;
77
    }
78
}
79