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 — master ( eef5cb...fe4976 )
by Joni
06:29
created

PathValidationConfig::defaultConfig()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
nc 1
cc 1
eloc 2
nop 0
crap 1
1
<?php
2
3
namespace X509\CertificationPath\PathValidation;
4
5
use X509\Certificate\Certificate;
6
use X509\Certificate\Extension\CertificatePolicy\PolicyInformation;
7
8
9
/**
10
 * Configuration for the certification path validation process.
11
 *
12
 * @link https://tools.ietf.org/html/rfc5280#section-6.1.1
13
 */
14
class PathValidationConfig
15
{
16
	/**
17
	 * Maximum allowed certification path length.
18
	 *
19
	 * @var int $_maxLength
20
	 */
21
	protected $_maxLength;
22
	
23
	/**
24
	 * Reference time.
25
	 *
26
	 * @var \DateTimeImmutable $_dateTime
27
	 */
28
	protected $_dateTime;
29
	
30
	/**
31
	 * List of acceptable policy identifiers.
32
	 *
33
	 * @var string[] $_policySet
34
	 */
35
	protected $_policySet;
36
	
37
	/**
38
	 * Trust anchor certificate.
39
	 *
40
	 * If not set, path validation uses the first certificate of the path.
41
	 *
42
	 * @var Certificate|null $_trustAnchor
43
	 */
44
	protected $_trustAnchor;
45
	
46
	/**
47
	 * Whether policy mapping in inhibited.
48
	 *
49
	 * Setting this to true disallows policy mapping.
50
	 *
51
	 * @var bool $_policyMappingInhibit
52
	 */
53
	protected $_policyMappingInhibit;
54
	
55
	/**
56
	 * Whether the path must be valid for at least one policy in the
57
	 * initial policy set.
58
	 *
59
	 * @var bool $_explicitPolicy
60
	 */
61
	protected $_explicitPolicy;
62
	
63
	/**
64
	 * Whether anyPolicy OID processing should be inhibited.
65
	 *
66
	 * Setting this to true disallows the usage of anyPolicy.
67
	 *
68
	 * @var bool $_anyPolicyInhibit
69
	 */
70
	protected $_anyPolicyInhibit;
71
	
72
	/**
73
	 *
74
	 * @todo Implement
75
	 * @var unknown $_permittedSubtrees
76
	 */
77
	protected $_permittedSubtrees;
78
	
79
	/**
80
	 *
81
	 * @todo Implement
82
	 * @var unknown $_excludedSubtrees
83
	 */
84
	protected $_excludedSubtrees;
85
	
86
	/**
87
	 * Constructor
88
	 *
89
	 * @param \DateTimeImmutable $dt Reference date and time
90
	 * @param int $max_length Maximum certification path length
91
	 */
92 48
	public function __construct(\DateTimeImmutable $dt, $max_length) {
93 48
		$this->_dateTime = $dt;
94 48
		$this->_maxLength = (int) $max_length;
95 48
		$this->_policySet = array((string) PolicyInformation::OID_ANY_POLICY);
96 48
		$this->_policyMappingInhibit = false;
97 48
		$this->_explicitPolicy = false;
98 48
		$this->_anyPolicyInhibit = false;
99 48
	}
100
	
101
	/**
102
	 * Get default configuration.
103
	 *
104
	 * @return self
105
	 */
106 23
	public static function defaultConfig() {
107 23
		return new self(new \DateTimeImmutable(), 3);
108
	}
109
	
110
	/**
111
	 * Get self with maximum path lenght.
112
	 *
113
	 * @param int $length
114
	 * @return self
115
	 */
116 14
	public function withMaxLength($length) {
117 14
		$obj = clone $this;
118 14
		$obj->_maxLength = $length;
119 14
		return $obj;
120
	}
121
	
122
	/**
123
	 * Get self with reference date and time.
124
	 *
125
	 * @param \DateTimeImmutable $dt
126
	 * @return self
127
	 */
128 4
	public function withDateTime(\DateTimeImmutable $dt) {
129 4
		$obj = clone $this;
130 4
		$obj->_dateTime = $dt;
131 4
		return $obj;
132
	}
133
	
134
	/**
135
	 * Get self with trust anchor certificate.
136
	 *
137
	 * @param Certificate $ca
138
	 * @return self
139
	 */
140 2
	public function withTrustAnchor(Certificate $ca) {
141 2
		$obj = clone $this;
142 2
		$obj->_trustAnchor = $ca;
143 2
		return $obj;
144
	}
145
	
146
	/**
147
	 * Get self with initial-policy-mapping-inhibit set.
148
	 *
149
	 * @param bool $flag
150
	 * @return self
151
	 */
152 1
	public function withPolicyMappingInhibit($flag) {
153 1
		$obj = clone $this;
154 1
		$obj->_policyMappingInhibit = (bool) $flag;
155 1
		return $obj;
156
	}
157
	
158
	/**
159
	 * Get self with initial-explicit-policy set.
160
	 *
161
	 * @param bool $flag
162
	 * @return self
163
	 */
164 7
	public function withExplicitPolicy($flag) {
165 7
		$obj = clone $this;
166 7
		$obj->_explicitPolicy = (bool) $flag;
167 7
		return $obj;
168
	}
169
	
170
	/**
171
	 * Get self with initial-any-policy-inhibit set.
172
	 *
173
	 * @param bool $flag
174
	 * @return self
175
	 */
176 1
	public function withAnyPolicyInhibit($flag) {
177 1
		$obj = clone $this;
178 1
		$obj->_anyPolicyInhibit = (bool) $flag;
179 1
		return $obj;
180
	}
181
	
182
	/**
183
	 * Get self with user-initial-policy-set set to policy OIDs.
184
	 *
185
	 * @param string ...$policies List of policy OIDs
186
	 * @return self
187
	 */
188 6
	public function withPolicySet(...$policies) {
189 6
		$obj = clone $this;
190 6
		$obj->_policySet = $policies;
191 6
		return $obj;
192
	}
193
	
194
	/**
195
	 * Get maximum certification path length.
196
	 *
197
	 * @return int
198
	 */
199 47
	public function maxLength() {
200 47
		return $this->_maxLength;
201
	}
202
	
203
	/**
204
	 * Get reference date and time.
205
	 *
206
	 * @return \DateTimeImmutable
207
	 */
208 45
	public function dateTime() {
209 45
		return $this->_dateTime;
210
	}
211
	
212
	/**
213
	 * Get user-initial-policy-set.
214
	 *
215
	 * @return string[] Array of OID's
216
	 */
217 10
	public function policySet() {
218 10
		return $this->_policySet;
219
	}
220
	
221
	/**
222
	 * Check whether trust anchor certificate is set.
223
	 *
224
	 * @return bool
225
	 */
226 47
	public function hasTrustAnchor() {
227 47
		return isset($this->_trustAnchor);
228
	}
229
	
230
	/**
231
	 * Get trust anchor certificate.
232
	 *
233
	 * @throws \LogicException
234
	 * @return Certificate
235
	 */
236 3
	public function trustAnchor() {
237 3
		if (!$this->hasTrustAnchor()) {
238 1
			throw new \LogicException("No trust anchor.");
239
		}
240 2
		return $this->_trustAnchor;
241
	}
242
	
243
	/**
244
	 * Get initial-policy-mapping-inhibit.
245
	 *
246
	 * @return bool
247
	 */
248 47
	public function policyMappingInhibit() {
249 47
		return $this->_policyMappingInhibit;
250
	}
251
	
252
	/**
253
	 * Get initial-explicit-policy.
254
	 *
255
	 * @return bool
256
	 */
257 47
	public function explicitPolicy() {
258 47
		return $this->_explicitPolicy;
259
	}
260
	
261
	/**
262
	 * Get initial-any-policy-inhibit.
263
	 *
264
	 * @return bool
265
	 */
266 47
	public function anyPolicyInhibit() {
267 47
		return $this->_anyPolicyInhibit;
268
	}
269
}
270