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 ( ec3172...fb818e )
by Joni
06:18
created

RoleAttributeValue   A

Complexity

Total Complexity 14

Size/Duplication

Total Lines 143
Duplicated Lines 16.78 %

Coupling/Cohesion

Components 1
Dependencies 10

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 14
lcom 1
cbo 10
dl 24
loc 143
ccs 45
cts 45
cp 1
rs 10
c 0
b 0
f 0

11 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A fromString() 0 3 1
A fromASN1() 15 15 2
A hasRoleAuthority() 0 3 1
A roleAuthority() 0 6 2
A roleName() 0 3 1
A toASN1() 9 9 2
A stringValue() 0 3 1
A equalityMatchingRule() 0 3 1
A rfc2253String() 0 3 1
A _transcodedString() 0 3 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace X509\AttributeCertificate\Attribute;
4
5
use ASN1\Element;
6
use ASN1\Type\Constructed\Sequence;
7
use ASN1\Type\Tagged\ExplicitlyTaggedType;
8
use ASN1\Type\Tagged\ImplicitlyTaggedType;
9
use ASN1\Type\UnspecifiedType;
10
use X501\ASN1\AttributeType;
11
use X501\ASN1\AttributeValue\AttributeValue;
12
use X501\MatchingRule\BinaryMatch;
13
use X509\GeneralName\GeneralName;
14
use X509\GeneralName\GeneralNames;
15
use X509\GeneralName\UniformResourceIdentifier;
16
17
18
/**
19
 * Implements value for 'Role' attribute.
20
 *
21
 * @link https://tools.ietf.org/html/rfc5755#section-4.4.5
22
 */
23
class RoleAttributeValue extends AttributeValue
24
{
25
	/**
26
	 * Issuing authority.
27
	 *
28
	 * @var GeneralNames $_roleAuthority
29
	 */
30
	protected $_roleAuthority;
31
	
32
	/**
33
	 * Role name.
34
	 *
35
	 * @var GeneralName $_roleName
36
	 */
37
	protected $_roleName;
38
	
39
	/**
40
	 * Constructor.
41
	 *
42
	 * @param GeneralName $name Role name
43
	 * @param GeneralNames|null $authority Issuing authority
44
	 */
45 15
	public function __construct(GeneralName $name, 
46
			GeneralNames $authority = null) {
47 15
		$this->_roleAuthority = $authority;
48 15
		$this->_roleName = $name;
49 15
		$this->_oid = AttributeType::OID_ROLE;
50 15
	}
51
	
52
	/**
53
	 * Initialize from a role string.
54
	 *
55
	 * @param string $role_name Role name in URI format
56
	 * @param GeneralNames|null $authority Issuing authority
57
	 * @return self
58
	 */
59 2
	public static function fromString($role_name, GeneralNames $authority = null) {
60 2
		return new self(new UniformResourceIdentifier($role_name), $authority);
61
	}
62
	
63
	/**
64
	 *
65
	 * @param UnspecifiedType $el
66
	 * @return self
67
	 */
68 8 View Code Duplication
	public static function fromASN1(UnspecifiedType $el) {
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...
69 8
		$seq = $el->asSequence();
70 8
		$authority = null;
71 8
		if ($seq->hasTagged(0)) {
72 1
			$authority = GeneralNames::fromASN1(
73 1
				$seq->getTagged(0)
74 1
					->asImplicit(Element::TYPE_SEQUENCE)
75 1
					->asSequence());
76 1
		}
77 8
		$name = GeneralName::fromASN1(
78 8
			$seq->getTagged(1)
79 8
				->asExplicit()
80 8
				->asTagged());
81 8
		return new self($name, $authority);
82
	}
83
	
84
	/**
85
	 * Check whether issuing authority is present.
86
	 *
87
	 * @return bool
88
	 */
89 2
	public function hasRoleAuthority() {
90 2
		return isset($this->_roleAuthority);
91
	}
92
	
93
	/**
94
	 * Get issuing authority.
95
	 *
96
	 * @throws \LogicException
97
	 * @return GeneralNames
98
	 */
99 2
	public function roleAuthority() {
100 2
		if (!$this->hasRoleAuthority()) {
101 1
			throw new \LogicException("roleAuthority not set.");
102
		}
103 1
		return $this->_roleAuthority;
104
	}
105
	
106
	/**
107
	 * Get role name.
108
	 *
109
	 * @return GeneralName
110
	 */
111 2
	public function roleName() {
112 2
		return $this->_roleName;
113
	}
114
	
115
	/**
116
	 *
117
	 * @see \X501\ASN1\AttributeValue\AttributeValue::toASN1()
118
	 * @return Sequence
119
	 */
120 17 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...
121 17
		$elements = array();
122 17
		if (isset($this->_roleAuthority)) {
123 4
			$elements[] = new ImplicitlyTaggedType(0, 
124 4
				$this->_roleAuthority->toASN1());
125 4
		}
126 17
		$elements[] = new ExplicitlyTaggedType(1, $this->_roleName->toASN1());
127 17
		return new Sequence(...$elements);
128
	}
129
	
130
	/**
131
	 *
132
	 * @see \X501\ASN1\AttributeValue\AttributeValue::stringValue()
133
	 * @return string
134
	 */
135 3
	public function stringValue() {
136 3
		return "#" . bin2hex($this->toASN1()->toDER());
137
	}
138
	
139
	/**
140
	 *
141
	 * @see \X501\ASN1\AttributeValue\AttributeValue::equalityMatchingRule()
142
	 * @return BinaryMatch
143
	 */
144 1
	public function equalityMatchingRule() {
145 1
		return new BinaryMatch();
146
	}
147
	
148
	/**
149
	 *
150
	 * @see \X501\ASN1\AttributeValue\AttributeValue::rfc2253String()
151
	 * @return string
152
	 */
153 1
	public function rfc2253String() {
154 1
		return $this->stringValue();
155
	}
156
	
157
	/**
158
	 *
159
	 * @see \X501\ASN1\AttributeValue\AttributeValue::_transcodedString()
160
	 * @return string
161
	 */
162 1
	protected function _transcodedString() {
163 1
		return $this->stringValue();
164
	}
165
}
166