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

PolicyMappingsExtension::issuerDomainPolicies()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 7
ccs 6
cts 6
cp 1
rs 9.4285
cc 1
eloc 6
nc 1
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
use X509\Certificate\Extension\PolicyMappings\PolicyMapping;
9
10
11
/**
12
 * Implements 'Policy Mappings' certificate extension.
13
 *
14
 * @link https://tools.ietf.org/html/rfc5280#section-4.2.1.5
15
 */
16
class PolicyMappingsExtension extends Extension implements 
17
	\Countable, 
0 ignored issues
show
Coding Style introduced by
Expected 4 spaces before interface name; 1 found
Loading history...
18
	\IteratorAggregate
0 ignored issues
show
Coding Style introduced by
Expected 4 spaces before interface name; 1 found
Loading history...
19
{
20
	/**
21
	 * Policy mappings.
22
	 *
23
	 * @var PolicyMapping[] $_mappings
24
	 */
25
	protected $_mappings;
26
	
27
	/**
28
	 * Constructor
29
	 *
30
	 * @param bool $critical
31
	 * @param PolicyMapping ...$mappings One or more PolicyMapping objects
32
	 */
33 5
	public function __construct($critical, PolicyMapping ...$mappings) {
34 5
		parent::__construct(self::OID_POLICY_MAPPINGS, $critical);
35 5
		$this->_mappings = $mappings;
36 5
	}
37
	
38 2 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...
39 2
		$mappings = array_map(
40
			function (UnspecifiedType $el) {
41 1
				return PolicyMapping::fromASN1($el->asSequence());
42 2
			}, Sequence::fromDER($data)->elements());
43 2
		if (!count($mappings)) {
44 1
			throw new \UnexpectedValueException(
45 1
				"PolicyMappings must have at least one mapping.");
46
		}
47 1
		return new self($critical, ...$mappings);
48
	}
49
	
50 6 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...
51 6
		if (!count($this->_mappings)) {
52 1
			throw new \LogicException("No mappings.");
53
		}
54 5
		$elements = array_map(
55
			function (PolicyMapping $mapping) {
56 5
				return $mapping->toASN1();
57 5
			}, $this->_mappings);
58 5
		return new Sequence(...$elements);
59
	}
60
	
61
	/**
62
	 * Get all mappings.
63
	 *
64
	 * @return PolicyMapping[]
65
	 */
66 2
	public function mappings() {
67 2
		return $this->_mappings;
68
	}
69
	
70
	/**
71
	 * Get mappings flattened into a single array of arrays of subject domains
72
	 * keyed by issuer domain.
73
	 *
74
	 * Eg. if policy mappings contains multiple mappings with the same issuer
75
	 * domain policy, their corresponding subject domain policies are placed
76
	 * under the same key.
77
	 *
78
	 * @return (string[])[]
79
	 */
80 2
	public function flattenedMappings() {
81 2
		$mappings = array();
82 2
		foreach ($this->_mappings as $mapping) {
83 2
			$idp = $mapping->issuerDomainPolicy();
84 2
			if (!isset($mappings[$idp])) {
85 2
				$mappings[$idp] = array();
86 2
			}
87 2
			array_push($mappings[$idp], $mapping->subjectDomainPolicy());
88 2
		}
89 2
		return $mappings;
90
	}
91
	
92
	/**
93
	 * Get all subject domain policy OIDs that are mapped to given issuer
94
	 * domain policy OID.
95
	 *
96
	 * @param string $oid Issuer domain policy
97
	 * @return string[] List of OIDs in dotted format
98
	 */
99 1
	public function issuerMappings($oid) {
100 1
		$oids = array();
101 1
		foreach ($this->_mappings as $mapping) {
102 1
			if ($mapping->issuerDomainPolicy() == $oid) {
103 1
				$oids[] = $mapping->subjectDomainPolicy();
104 1
			}
105 1
		}
106 1
		return $oids;
107
	}
108
	
109
	/**
110
	 * Get all mapped issuer domain policy OIDs.
111
	 *
112
	 * @return string[]
113
	 */
114 1
	public function issuerDomainPolicies() {
115 1
		$idps = array_map(
116 1
			function (PolicyMapping $mapping) {
117 1
				return $mapping->issuerDomainPolicy();
118 1
			}, $this->_mappings);
119 1
		return array_values(array_unique($idps));
120
	}
121
	
122
	/**
123
	 * Check whether policy mappings have anyPolicy mapped.
124
	 *
125
	 * RFC 5280 section 4.2.1.5 states that "Policies MUST NOT be mapped either
126
	 * to or from the special value anyPolicy".
127
	 *
128
	 * @return bool
129
	 */
130 7
	public function hasAnyPolicyMapping() {
131 7
		foreach ($this->_mappings as $mapping) {
132 7
			if ($mapping->issuerDomainPolicy() ==
133 7
				 PolicyInformation::OID_ANY_POLICY) {
134 1
				return true;
135
			}
136 6
			if ($mapping->subjectDomainPolicy() ==
137 6
				 PolicyInformation::OID_ANY_POLICY) {
138 2
				return true;
139
			}
140 4
		}
141 4
		return false;
142
	}
143
	
144
	/**
145
	 * Get the number of mappings.
146
	 *
147
	 * @see Countable::count()
148
	 * @return int
149
	 */
150 1
	public function count() {
151 1
		return count($this->_mappings);
152
	}
153
	
154
	/**
155
	 * Get iterator for policy mappings.
156
	 *
157
	 * @see IteratorAggregate::getIterator()
158
	 * @return \ArrayIterator
159
	 */
160 1
	public function getIterator() {
161 1
		return new \ArrayIterator($this->_mappings);
162
	}
163
}
164