Completed
Push — master ( da521e...2646ae )
by Richan
01:12
created

CanRetrieveInputValues::getPwaScore()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 2
nc 1
nop 0
1
<?php
2
3
namespace Suitmedia\LighthouseAudit\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
        $server = $this->input->getOption('server');
38
39
        $server = $this->trimDoubleQuotes(is_string($server) ? $server : Command::DEFAULT_SERVER);
40
41
        return 'http://' . $server . '/';
42
    }
43
44
    /**
45
     * Get the chrome flags.
46
     *
47
     * @return array
48
     */
49
    protected function getChromeFlags() :array
50
    {
51
        $flags = $this->input->getOption('chrome-flags');
52
53
        $flags = is_string($flags) ? explode(' ', $this->trimDoubleQuotes($flags)) : [];
54
        $flags = array_filter(array_map('trim', $flags));
55
56
        $flags = array_unique(array_merge($this->getDefaultChromeFlags(), $flags));
57
        sort($flags);
58
59
        return $flags;
60
    }
61
62
    /**
63
     * Get minimal performance score.
64
     *
65
     * @return string
66
     */
67
    protected function getPerformanceScore() :string
68
    {
69
        $score = $this->input->getOption('performance');
70
71
        return $this->trimDoubleQuotes(is_string($score) ? $score : Command::DEFAULT_PERFORMANCE);
72
    }
73
74
    /**
75
     * Get minimal best-practices score.
76
     *
77
     * @return string
78
     */
79
    protected function getBestPracticesScore() :string
80
    {
81
        $score = $this->input->getOption('best-practices');
82
83
        return $this->trimDoubleQuotes(is_string($score) ? $score : Command::DEFAULT_BEST_PRACTICES);
84
    }
85
86
    /**
87
     * Get minimal accessibility score.
88
     *
89
     * @return string
90
     */
91
    protected function getAccessibilityScore() :string
92
    {
93
        $score = $this->input->getOption('accessibility');
94
95
        return $this->trimDoubleQuotes(is_string($score) ? $score : Command::DEFAULT_ACCESSIBILITY);
96
    }
97
98
    /**
99
     * Get minimal SEO score.
100
     *
101
     * @return string
102
     */
103
    protected function getSeoScore() :string
104
    {
105
        $score = $this->input->getOption('seo');
106
107
        return $this->trimDoubleQuotes(is_string($score) ? $score : Command::DEFAULT_SEO);
108
    }
109
110
    /**
111
     * Get minimal PWA score.
112
     *
113
     * @return string
114
     */
115
    protected function getPwaScore() :string
116
    {
117
        $score = $this->input->getOption('pwa');
118
119
        return $this->trimDoubleQuotes(is_string($score) ? $score : Command::DEFAULT_PWA);
120
    }
121
122
    /**
123
     * Get the default chrome flags.
124
     *
125
     * @return array
126
     */
127
    abstract protected function getDefaultChromeFlags() :array;
128
}
129