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 ( 73a8c5...275dd7 )
by Joni
04:16
created

CertificatePoliciesExtension::getIterator()   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 0
Metric Value
c 0
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\Certificate\Extension;
4
5
use ASN1\Type\Constructed\Sequence;
6
use ASN1\Type\UnspecifiedType;
7
use X509\Certificate\Extension\CertificatePolicy\PolicyInformation;
8
9
10
/**
11
 * Implements 'Certificate Policies' certificate extension.
12
 *
13
 * @link https://tools.ietf.org/html/rfc5280#section-4.2.1.4
14
 */
15
class CertificatePoliciesExtension extends Extension implements 
16
	\Countable, 
0 ignored issues
show
Coding Style introduced by
Expected 4 spaces before interface name; 1 found
Loading history...
17
	\IteratorAggregate
0 ignored issues
show
Coding Style introduced by
Expected 4 spaces before interface name; 1 found
Loading history...
18
{
19
	/**
20
	 * Policy information terms.
21
	 *
22
	 * @var PolicyInformation[] $_policies
23
	 */
24
	protected $_policies;
25
	
26
	/**
27
	 * Constructor
28
	 *
29
	 * @param bool $critical
30
	 * @param PolicyInformation ...$policies
31
	 */
32 10
	public function __construct($critical, PolicyInformation ...$policies) {
33 10
		parent::__construct(Extension::OID_CERTIFICATE_POLICIES, $critical);
34 10
		$this->_policies = array();
35 10
		foreach ($policies as $policy) {
36 9
			$this->_policies[$policy->oid()] = $policy;
37 10
		}
38 10
	}
39
	
40 8 View Code Duplication
	protected static function _fromDER($data, $critical) {
0 ignored issues
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...
41 8
		$policies = array_map(
42
			function (UnspecifiedType $el) {
43 7
				return PolicyInformation::fromASN1($el->asSequence());
44 8
			}, Sequence::fromDER($data)->elements());
45 8
		if (!count($policies)) {
46 1
			throw new \UnexpectedValueException(
47
				"certificatePolicies must contain" .
48 1
					 " at least one PolicyInformation.");
49
		}
50 7
		return new self($critical, ...$policies);
51
	}
52
	
53
	/**
54
	 * Check whether policy information by OID is present.
55
	 *
56
	 * @param string $oid
57
	 * @return boolean
58
	 */
59 3
	public function has($oid) {
60 3
		return isset($this->_policies[$oid]);
61
	}
62
	
63
	/**
64
	 * Check whether anyPolicy is present.
65
	 *
66
	 * @return bool
67
	 */
68 1
	public function hasAnyPolicy() {
69 1
		return isset($this->_policies[PolicyInformation::OID_ANY_POLICY]);
70
	}
71
	
72
	/**
73
	 * Get policy information by OID.
74
	 *
75
	 * @param string $oid
76
	 * @throws \LogicException
77
	 * @return PolicyInformation
78
	 */
79 3
	public function get($oid) {
80 3
		if (!$this->has($oid)) {
81 1
			throw new \LogicException("Not certificate policy by OID $oid.");
82
		}
83 2
		return $this->_policies[$oid];
84
	}
85
	
86 21 View Code Duplication
	protected function _valueASN1() {
0 ignored issues
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...
87 21
		if (!count($this->_policies)) {
88 1
			throw new \LogicException("No policies.");
89
		}
90 20
		$elements = array_map(
91 20
			function (PolicyInformation $pi) {
92 20
				return $pi->toASN1();
93 20
			}, array_values($this->_policies));
94 20
		return new Sequence(...$elements);
95
	}
96
	
97
	/**
98
	 * Get the number of policies.
99
	 *
100
	 * @see Countable::count()
101
	 * @return int
102
	 */
103 1
	public function count() {
104 1
		return count($this->_policies);
105
	}
106
	
107
	/**
108
	 * Get iterator for policy information terms.
109
	 *
110
	 * @see IteratorAggregate::getIterator()
111
	 * @return \ArrayIterator
112
	 */
113 1
	public function getIterator() {
114 1
		return new \ArrayIterator($this->_policies);
115
	}
116
}
117