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
Push — develop ( 3d5dc4...404a4d )
by Jasper
06:53
created

Configuration::getOptions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
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 View Code Duplication
    public function setOptions(array $options)
1 ignored issue
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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