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

V2Form::_fromASN1()   B

Complexity

Conditions 4
Paths 8

Size

Total Lines 24
Code Lines 20

Duplication

Lines 24
Ratio 100 %

Code Coverage

Tests 23
CRAP Score 4

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 24
loc 24
ccs 23
cts 23
cp 1
rs 8.6845
cc 4
eloc 20
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 X501\ASN1\Name;
9
use X509\GeneralName\GeneralNames;
10
11
12
/**
13
 * Implements <i>V2Form</i> ASN.1 type used as a attribute certificate issuer.
14
 *
15
 * @link https://tools.ietf.org/html/rfc5755#section-4.1
16
 */
17
class V2Form extends AttCertIssuer
18
{
19
	/**
20
	 * Issuer name.
21
	 *
22
	 * @var GeneralNames $_issuerName
23
	 */
24
	protected $_issuerName;
25
	
26
	/**
27
	 * Issuer PKC's issuer and serial.
28
	 *
29
	 * @var IssuerSerial $_baseCertificateID
30
	 */
31
	protected $_baseCertificateID;
32
	
33
	/**
34
	 * Linked object.
35
	 *
36
	 * @var ObjectDigestInfo $_objectDigestInfo
37
	 */
38
	protected $_objectDigestInfo;
39
	
40
	/**
41
	 * Constructor
42
	 *
43
	 * @param GeneralNames|null $names
44
	 */
45 9
	public function __construct(GeneralNames $names = null) {
46 9
		$this->_issuerName = $names;
47 9
		$this->_baseCertificateID = null;
48 9
		$this->_objectDigestInfo = null;
49 9
	}
50
	
51
	/**
52
	 * Initialize from ASN.1.
53
	 *
54
	 * @param Sequence $seq
55
	 * @return self
56
	 */
57 6 View Code Duplication
	protected 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...
58 6
		$issuer = null;
59 6
		$cert_id = null;
60 6
		$digest_info = null;
61 6
		if ($seq->has(0, Element::TYPE_SEQUENCE)) {
62 6
			$issuer = GeneralNames::fromASN1($seq->at(0)->asSequence());
63 6
		}
64 6
		if ($seq->hasTagged(0)) {
65 1
			$cert_id = IssuerSerial::fromASN1(
66 1
				$seq->getTagged(0)
67 1
					->asImplicit(Element::TYPE_SEQUENCE)
68 1
					->asSequence());
69 1
		}
70 6
		if ($seq->hasTagged(1)) {
71 1
			$digest_info = ObjectDigestInfo::fromASN1(
72 1
				$seq->getTagged(1)
73 1
					->asImplicit(Element::TYPE_SEQUENCE)
74 1
					->asSequence());
75 1
		}
76 6
		$obj = new self($issuer);
77 6
		$obj->_baseCertificateID = $cert_id;
78 6
		$obj->_objectDigestInfo = $digest_info;
79 6
		return $obj;
80
	}
81
	
82
	/**
83
	 * Check whether issuer name is set.
84
	 *
85
	 * @return bool
86
	 */
87 3
	public function hasIssuerName() {
88 3
		return isset($this->_issuerName);
89
	}
90
	
91
	/**
92
	 * Get issuer name.
93
	 *
94
	 * @throws \LogicException
95
	 * @return GeneralNames
96
	 */
97 3
	public function issuerName() {
98 3
		if (!$this->hasIssuerName()) {
99 1
			throw new \LogicException("issuerName not set.");
100
		}
101 2
		return $this->_issuerName;
102
	}
103
	
104
	/**
105
	 * Get DN of the issuer.
106
	 *
107
	 * This is a convenience method conforming to RFC 5755, which states
108
	 * that Issuer must contain only one non-empty distinguished name.
109
	 *
110
	 * @return Name
111
	 */
112 1
	public function name() {
113 1
		return $this->issuerName()->firstDN();
114
	}
115
	
116
	/**
117
	 *
118
	 * @see \X509\AttributeCertificate\AttCertIssuer::ASN1()
119
	 * @return ImplicitlyTaggedType Tagged Sequence
120
	 */
121 11 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...
122 11
		$elements = array();
123 11
		if (isset($this->_issuerName)) {
124 11
			$elements[] = $this->_issuerName->toASN1();
125 11
		}
126 11
		if (isset($this->_baseCertificateID)) {
127 1
			$elements[] = new ImplicitlyTaggedType(0, 
128 1
				$this->_baseCertificateID->toASN1());
129 1
		}
130 11
		if (isset($this->_objectDigestInfo)) {
131 1
			$elements[] = new ImplicitlyTaggedType(1, 
132 1
				$this->_objectDigestInfo->toASN1());
133 1
		}
134 11
		return new ImplicitlyTaggedType(0, new Sequence(...$elements));
135
	}
136
}
137