1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Spatie\MixedContentScannerCli; |
4
|
|
|
|
5
|
|
|
use GuzzleHttp\Exception\RequestException; |
6
|
|
|
use Psr\Http\Message\UriInterface; |
7
|
|
|
use Spatie\MixedContentScanner\MixedContent; |
8
|
|
|
use Spatie\MixedContentScanner\MixedContentObserver; |
9
|
|
|
use Symfony\Component\Console\Style\SymfonyStyle; |
10
|
|
|
|
11
|
|
|
class MixedContentLogger extends MixedContentObserver |
12
|
|
|
{ |
13
|
|
|
protected $nonResponsiveUrls = []; |
14
|
|
|
|
15
|
|
|
protected $mixedContent = []; |
16
|
|
|
|
17
|
|
|
protected $urlsWithoutMixedContent = []; |
18
|
|
|
|
19
|
|
|
/** @var \Symfony\Component\Console\Style\SymfonyStyle */ |
20
|
|
|
protected $output; |
21
|
|
|
|
22
|
|
|
public function __construct(SymfonyStyle $output) |
23
|
|
|
{ |
24
|
|
|
$this->output = $output; |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
public function didNotRespond(UriInterface $crawledUrl) |
28
|
|
|
{ |
29
|
|
|
$this->log("{$crawledUrl}: server did not respond when crawling", 'comment'); |
30
|
|
|
|
31
|
|
|
$this->nonResponsiveUrls[] = $crawledUrl; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
public function mixedContentFound(MixedContent $mixedContent) |
35
|
|
|
{ |
36
|
|
|
$foundOnUrl = $mixedContent->foundOnUrl; |
37
|
|
|
$elementName = $mixedContent->elementName; |
38
|
|
|
$mixedContentUrl = $mixedContent->mixedContentUrl; |
39
|
|
|
|
40
|
|
|
$this->log( |
41
|
|
|
"{$foundOnUrl}: found mixed content on element {$elementName} with url {$mixedContentUrl}", |
42
|
|
|
'error' |
43
|
|
|
); |
44
|
|
|
|
45
|
|
|
$this->mixedContent[] = $mixedContent; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public function noMixedContentFound(UriInterface $url) |
49
|
|
|
{ |
50
|
|
|
$this->log("{$url}: ok"); |
51
|
|
|
|
52
|
|
|
$this->urlsWithoutMixedContent[] = $url; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public function crawlFailed( |
56
|
|
|
UriInterface $url, |
57
|
|
|
RequestException $requestException, |
58
|
|
|
?UriInterface $foundOnUrl = null |
59
|
|
|
) { |
60
|
|
|
$this->didNotRespond($url); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
public function finishedCrawling() |
64
|
|
|
{ |
65
|
|
|
$this->output->title('Scan results'); |
66
|
|
|
|
67
|
|
|
if (count($this->mixedContent)) { |
68
|
|
|
$this->log('Found '.count($this->mixedContent).' pieces of mixed content', 'error'); |
69
|
|
|
|
70
|
|
|
$mixedContentMessages = array_map(function (MixedContent $mixedContent) { |
71
|
|
|
$foundOnUrl = $mixedContent->foundOnUrl; |
72
|
|
|
$elementName = $mixedContent->elementName; |
73
|
|
|
$mixedContentUrl = $mixedContent->mixedContentUrl; |
74
|
|
|
|
75
|
|
|
return "{$foundOnUrl}: found mixed content on element {$elementName} with url {$mixedContentUrl}"; |
76
|
|
|
}, $this->mixedContent); |
77
|
|
|
|
78
|
|
|
$this->output->listing($mixedContentMessages, 'error'); |
|
|
|
|
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
if (count($this->nonResponsiveUrls)) { |
82
|
|
|
$this->log('Found '.count($this->nonResponsiveUrls).' non responsive url(s)', 'comment'); |
83
|
|
|
$this->output->listing($this->nonResponsiveUrls); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
$this->log('Found '.count($this->urlsWithoutMixedContent).' pages without mixed content'); |
87
|
|
|
|
88
|
|
|
$this->output->newLine(1); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
protected function log($message, $level = 'info') |
92
|
|
|
{ |
93
|
|
|
$this->output->writeln("<{$level}>{$message}</{$level}>"); |
94
|
|
|
} |
95
|
|
|
} |
96
|
|
|
|
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.
In this case you can add the
@ignore
PhpDoc annotation to the duplicate definition and it will be ignored.