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 ( eb5c8e...f4ded9 )
by Joni
06:39
created

Holder::fromASN1()   B

Complexity

Conditions 4
Paths 8

Size

Total Lines 26
Code Lines 22

Duplication

Lines 26
Ratio 100 %

Code Coverage

Tests 25
CRAP Score 4

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 26
loc 26
ccs 25
cts 25
cp 1
rs 8.5806
cc 4
eloc 22
nc 8
nop 1
crap 4
1
<?php
2
3
namespace X509\AttributeCertificate;
4
5
use ASN1\Element;
6
use ASN1\Type\Constructed\Sequence;
7
use ASN1\Type\Tagged\ImplicitlyTaggedType;
8
use X509\GeneralName\GeneralNames;
9
10
11
/**
12
 * Implements <i>Holder</i> ASN.1 type.
13
 *
14
 * @link https://tools.ietf.org/html/rfc5755#section-4.1
15
 */
16
class Holder
17
{
18
	/**
19
	 * Holder PKC's issuer and serial.
20
	 *
21
	 * @var IssuerSerial|null $_baseCertificateID
22
	 */
23
	protected $_baseCertificateID;
24
	
25
	/**
26
	 * Holder PKC's subject.
27
	 *
28
	 * @var GeneralNames|null $_entityName
29
	 */
30
	protected $_entityName;
31
	
32
	/**
33
	 * Linked object.
34
	 *
35
	 * @var ObjectDigestInfo|null $_objectDigestInfo
36
	 */
37
	protected $_objectDigestInfo;
38
	
39
	/**
40
	 * Constructor
41
	 *
42
	 * @param IssuerSerial|null $issuer_serial
43
	 * @param GeneralNames|null $entity_name
44
	 */
45 13
	public function __construct(IssuerSerial $issuer_serial = null, 
46
			GeneralNames $entity_name = null) {
47 13
		$this->_baseCertificateID = $issuer_serial;
48 13
		$this->_entityName = $entity_name;
49 13
	}
50
	
51
	/**
52
	 * Initialize from ASN.1.
53
	 *
54
	 * @param Sequence $seq
55
	 */
56 5 View Code Duplication
	public static function fromASN1(Sequence $seq) {
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...
57 5
		$cert_id = null;
58 5
		$entity_name = null;
59 5
		$digest_info = null;
60 5
		if ($seq->hasTagged(0)) {
61 5
			$cert_id = IssuerSerial::fromASN1(
62 5
				$seq->getTagged(0)
63 5
					->asImplicit(Element::TYPE_SEQUENCE)
64 5
					->asSequence());
65 5
		}
66 5
		if ($seq->hasTagged(1)) {
67 3
			$entity_name = GeneralNames::fromASN1(
68 3
				$seq->getTagged(1)
69 3
					->asImplicit(Element::TYPE_SEQUENCE)
70 3
					->asSequence());
71 3
		}
72 5
		if ($seq->hasTagged(2)) {
73 1
			$digest_info = ObjectDigestInfo::fromASN1(
74 1
				$seq->getTagged(2)
75 1
					->asImplicit(Element::TYPE_SEQUENCE)
76 1
					->asSequence());
77 1
		}
78 5
		$obj = new self($cert_id, $entity_name);
79 5
		$obj->_objectDigestInfo = $digest_info;
80 5
		return $obj;
81
	}
82
	
83
	/**
84
	 * Get self with base certificate ID.
85
	 *
86
	 * @param IssuerSerial $issuer
87
	 * @return self
88
	 */
89 1
	public function withBaseCertificateID(IssuerSerial $issuer) {
90 1
		$obj = clone $this;
91 1
		$obj->_baseCertificateID = $issuer;
92 1
		return $obj;
93
	}
94
	
95
	/**
96
	 * Get self with entity name.
97
	 *
98
	 * @param GeneralNames $names
99
	 * @return self
100
	 */
101 1
	public function withEntityName(GeneralNames $names) {
102 1
		$obj = clone $this;
103 1
		$obj->_entityName = $names;
104 1
		return $obj;
105
	}
106
	
107
	/**
108
	 * Get self with object digest info.
109
	 *
110
	 * @param ObjectDigestInfo $odi
111
	 * @return self
112
	 */
113 2
	public function withObjectDigestInfo(ObjectDigestInfo $odi) {
114 2
		$obj = clone $this;
115 2
		$obj->_objectDigestInfo = $odi;
116 2
		return $obj;
117
	}
118
	
119
	/**
120
	 * Check whether base certificate ID is present.
121
	 *
122
	 * @return bool
123
	 */
124 2
	public function hasBaseCertificateID() {
125 2
		return isset($this->_baseCertificateID);
126
	}
127
	
128
	/**
129
	 * Get base certificate ID.
130
	 *
131
	 * @throws \LogicException
132
	 * @return IssuerSerial
133
	 */
134 2
	public function baseCertificateID() {
135 2
		if (!$this->hasBaseCertificateID()) {
136 1
			throw new \LogicException("baseCertificateID not set.");
137
		}
138 1
		return $this->_baseCertificateID;
139
	}
140
	
141
	/**
142
	 * Check whether entity name is present.
143
	 *
144
	 * @return bool
145
	 */
146 2
	public function hasEntityName() {
147 2
		return isset($this->_entityName);
148
	}
149
	
150
	/**
151
	 * Get entity name
152
	 *
153
	 * @throws \LogicException
154
	 * @return GeneralNames
155
	 */
156 2
	public function entityName() {
157 2
		if (!$this->hasEntityName()) {
158 1
			throw new \LogicException("entityName not set.");
159
		}
160 1
		return $this->_entityName;
161
	}
162
	
163
	/**
164
	 * Check whether object digest info is present.
165
	 *
166
	 * @return bool
167
	 */
168 2
	public function hasObjectDigestInfo() {
169 2
		return isset($this->_objectDigestInfo);
170
	}
171
	
172
	/**
173
	 * Get object digest info
174
	 *
175
	 * @throws \LogicException
176
	 * @return ObjectDigestInfo
177
	 */
178 2
	public function objectDigestInfo() {
179 2
		if (!$this->hasObjectDigestInfo()) {
180 1
			throw new \LogicException("objectDigestInfo not set.");
181
		}
182 1
		return $this->_objectDigestInfo;
183
	}
184
	
185
	/**
186
	 * Generate ASN.1 structure.
187
	 *
188
	 * @return Sequence
189
	 */
190 10 View Code Duplication
	public function toASN1() {
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...
191 10
		$elements = array();
192 10
		if (isset($this->_baseCertificateID)) {
193 10
			$elements[] = new ImplicitlyTaggedType(0, 
194 10
				$this->_baseCertificateID->toASN1());
195 10
		}
196 10
		if (isset($this->_entityName)) {
197 4
			$elements[] = new ImplicitlyTaggedType(1, 
198 4
				$this->_entityName->toASN1());
199 4
		}
200 10
		if (isset($this->_objectDigestInfo)) {
201 1
			$elements[] = new ImplicitlyTaggedType(2, 
202 1
				$this->_objectDigestInfo->toASN1());
203 1
		}
204 10
		return new Sequence(...$elements);
205
	}
206
}
207