|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Suitmedia\LighthouseAudit\Audit\Concerns; |
|
4
|
|
|
|
|
5
|
|
|
use Suitmedia\LighthouseAudit\Command; |
|
6
|
|
|
|
|
7
|
|
|
trait CanRetrieveInputValues |
|
8
|
|
|
{ |
|
9
|
|
|
use SanitizeInput; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Console input interface. |
|
13
|
|
|
* |
|
14
|
|
|
* @var \Symfony\Component\Console\Input\InputInterface |
|
15
|
|
|
*/ |
|
16
|
|
|
protected $input; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* Get analysis emulation mode. |
|
20
|
|
|
* |
|
21
|
|
|
* @return string |
|
22
|
|
|
*/ |
|
23
|
|
|
protected function getMode() :string |
|
24
|
|
|
{ |
|
25
|
|
|
$mode = $this->input->getOption('mode'); |
|
26
|
|
|
|
|
27
|
|
|
return $this->trimDoubleQuotes(is_string($mode) ? $mode : Command::DEFAULT_MODE); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* Get URL prefix from input. |
|
32
|
|
|
* |
|
33
|
|
|
* @return string |
|
34
|
|
|
*/ |
|
35
|
|
|
protected function getUrlPrefix() :string |
|
36
|
|
|
{ |
|
37
|
|
|
$prefix = $this->input->getOption('url-prefix'); |
|
38
|
|
|
|
|
39
|
|
|
return $this->trimDoubleQuotes(is_string($prefix) ? $prefix : Command::DEFAULT_URL_PREFIX); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* Get the chrome flags. |
|
44
|
|
|
* |
|
45
|
|
|
* @return array |
|
46
|
|
|
*/ |
|
47
|
|
|
protected function getChromeFlags() :array |
|
48
|
|
|
{ |
|
49
|
|
|
$flags = $this->input->getOption('chrome-flags'); |
|
50
|
|
|
|
|
51
|
|
|
$flags = is_string($flags) ? explode(' ', $this->trimDoubleQuotes($flags)) : []; |
|
52
|
|
|
$flags = array_filter(array_map('trim', $flags)); |
|
53
|
|
|
|
|
54
|
|
|
$flags = array_unique(array_merge($this->getDefaultChromeFlags(), $flags)); |
|
55
|
|
|
sort($flags); |
|
56
|
|
|
|
|
57
|
|
|
return $flags; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* Get minimal performance score. |
|
62
|
|
|
* |
|
63
|
|
|
* @return string |
|
64
|
|
|
*/ |
|
65
|
|
|
protected function getPerformanceScore() :string |
|
66
|
|
|
{ |
|
67
|
|
|
$score = $this->input->getOption('performance'); |
|
68
|
|
|
|
|
69
|
|
|
return $this->trimDoubleQuotes(is_string($score) ? $score : Command::DEFAULT_PERFORMANCE); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* Get minimal best-practices score. |
|
74
|
|
|
* |
|
75
|
|
|
* @return string |
|
76
|
|
|
*/ |
|
77
|
|
|
protected function getBestPracticesScore() :string |
|
78
|
|
|
{ |
|
79
|
|
|
$score = $this->input->getOption('best-practices'); |
|
80
|
|
|
|
|
81
|
|
|
return $this->trimDoubleQuotes(is_string($score) ? $score : Command::DEFAULT_BEST_PRACTICES); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* Get minimal accessibility score. |
|
86
|
|
|
* |
|
87
|
|
|
* @return string |
|
88
|
|
|
*/ |
|
89
|
|
|
protected function getAccessibilityScore() :string |
|
90
|
|
|
{ |
|
91
|
|
|
$score = $this->input->getOption('accessibility'); |
|
92
|
|
|
|
|
93
|
|
|
return $this->trimDoubleQuotes(is_string($score) ? $score : Command::DEFAULT_ACCESSIBILITY); |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
/** |
|
97
|
|
|
* Get minimal SEO score. |
|
98
|
|
|
* |
|
99
|
|
|
* @return string |
|
100
|
|
|
*/ |
|
101
|
|
|
protected function getSeoScore() :string |
|
102
|
|
|
{ |
|
103
|
|
|
$score = $this->input->getOption('seo'); |
|
104
|
|
|
|
|
105
|
|
|
return $this->trimDoubleQuotes(is_string($score) ? $score : Command::DEFAULT_SEO); |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
/** |
|
109
|
|
|
* Get minimal PWA score. |
|
110
|
|
|
* |
|
111
|
|
|
* @return string |
|
112
|
|
|
*/ |
|
113
|
|
|
protected function getPwaScore() :string |
|
114
|
|
|
{ |
|
115
|
|
|
$score = $this->input->getOption('pwa'); |
|
116
|
|
|
|
|
117
|
|
|
return $this->trimDoubleQuotes(is_string($score) ? $score : Command::DEFAULT_PWA); |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
/** |
|
121
|
|
|
* Get the default chrome flags. |
|
122
|
|
|
* |
|
123
|
|
|
* @return array |
|
124
|
|
|
*/ |
|
125
|
|
|
abstract protected function getDefaultChromeFlags() :array; |
|
126
|
|
|
} |
|
127
|
|
|
|