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
Branch develop (404a4d)
by Jasper
02:32
created

Configuration::setRecipientOverride()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 5
cts 5
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 1
crap 2
1
<?php
2
3
/**
4
 * @license https://github.com/f500/swiftmailer-sparkpost/blob/master/LICENSE Proprietary
5
 */
6
7
namespace SwiftSparkPost;
8
9
/**
10
 * @copyright Future500 B.V.
11
 * @author    Jasper N. Brouwer <[email protected]>
12
 */
13
final class Configuration
14
{
15
    const OPT_TRANSACTIONAL    = 'transactional';
16
    const OPT_OPEN_TRACKING    = 'open_tracking';
17
    const OPT_CLICK_TRACKING   = 'click_tracking';
18
    const OPT_SANDBOX          = 'sandbox';
19
    const OPT_SKIP_SUPPRESSION = 'skip_suppression';
20
    const OPT_INLINE_CSS       = 'inline_css';
21
    const OPT_IP_POOL          = 'ip_pool';
22
23
    /**
24
     * @var string
25
     */
26
    private $recipientOverride;
27
28
    /**
29
     * @var bool
30
     */
31
    private $overrideGmailStyle;
32
33
    /**
34
     * @var array
35
     */
36
    private $options;
37
38
    /**
39
     * @param array $options
40
     *
41
     * @throws Exception
42
     */
43 24
    public static function guardOptionValidity(array $options)
44
    {
45
        $validOptions = [
46 24
            self::OPT_TRANSACTIONAL,
47 24
            self::OPT_OPEN_TRACKING,
48 24
            self::OPT_CLICK_TRACKING,
49 24
            self::OPT_SANDBOX,
50 24
            self::OPT_SKIP_SUPPRESSION,
51 24
            self::OPT_INLINE_CSS,
52 24
            self::OPT_IP_POOL,
53 8
        ];
54
55 24
        foreach (array_keys($options) as $option) {
56 24
            if (!in_array($option, $validOptions, true)) {
57 18
                throw new Exception(sprintf('Unknown SparkPost option "%s"', $option));
58
            }
59 6
        }
60 18
    }
61
62
    /**
63
     * @return Configuration
64
     */
65 39
    public static function newInstance()
66
    {
67 39
        return new self();
68
    }
69
70 75
    public function __construct()
71
    {
72 75
        $this->recipientOverride  = '';
73 75
        $this->overrideGmailStyle = false;
74 75
        $this->options            = [self::OPT_TRANSACTIONAL => true];
75 75
    }
76
77 51
    public function overrideRecipients()
78
    {
79 51
        return $this->recipientOverride !== '';
80
    }
81
82
    /**
83
     * @return bool
84
     */
85 18
    public function overrideGmailStyle()
86
    {
87 18
        return $this->overrideGmailStyle;
88
    }
89
90
    /**
91
     * @param bool $overrideGmailStyle
92
     *
93
     * @return Configuration
94
     */
95 9
    public function setOverrideGmailStyle($overrideGmailStyle)
96
    {
97 9
        $this->overrideGmailStyle = (bool) $overrideGmailStyle;
98
99 9
        return $this;
100
    }
101
102
    /**
103
     * @return string
104
     */
105 18
    public function getRecipientOverride()
106
    {
107 18
        return $this->recipientOverride;
108
    }
109
110
    /**
111
     * @param string $recipientOverride
112
     *
113
     * @return Configuration
114
     * @throws Exception
115
     */
116 21
    public function setRecipientOverride($recipientOverride)
117
    {
118 21
        if (!filter_var($recipientOverride, FILTER_VALIDATE_EMAIL)) {
119 3
            throw new Exception('Recipient override must be a valid email address');
120
        }
121
122 18
        $this->recipientOverride = (string) $recipientOverride;
123
124 18
        return $this;
125
    }
126
127
    /**
128
     * @return array
129
     */
130 51
    public function getOptions()
131
    {
132 51
        return $this->options;
133
    }
134
135
    /**
136
     * @param array $options
137
     *
138
     * @return Configuration
139
     * @throws Exception
140
     */
141 15
    public function setOptions(array $options)
142
    {
143 15
        self::guardOptionValidity($options);
144
145 12
        foreach ($options as $option => $value) {
146 12
            if ($option === self::OPT_IP_POOL) {
147 9
                $this->options[$option] = (string) $value;
148 9
                continue;
149
            }
150
151 12
            $this->options[$option] = (bool) $value;
152 4
        }
153
154 12
        return $this;
155
    }
156
}
157