Completed
Push — master ( f2eb62...168624 )
by Joni
03:13
created

PrintableStringValue::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 3
ccs 3
cts 3
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
namespace X501\ASN1\AttributeValue\Feature;
4
5
use ASN1\Element;
6
use ASN1\Feature\ElementBase;
7
use ASN1\Type\Primitive\PrintableString;
8
use ASN1\Type\UnspecifiedType;
9
use X501\ASN1\AttributeValue\AttributeValue;
10
use X501\DN\DNParser;
11
use X501\MatchingRule\CaseIgnoreMatch;
12
13
14
/**
15
 * Base class for attribute values having <i>PrintableString</i> syntax.
16
 */
17
abstract class PrintableStringValue extends AttributeValue
18
{
19
	/**
20
	 * String value.
21
	 *
22
	 * @var string $_string
23
	 */
24
	protected $_string;
25
	
26
	/**
27
	 * Constructor
28
	 *
29
	 * @param string $string String value
0 ignored issues
show
Bug introduced by
There is no parameter named $string. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
30
	 */
31 6
	public function __construct($value) {
32 6
		$this->_string = $value;
33 6
	}
34
	
35
	/**
36
	 *
37
	 * @see AttributeValue::fromASN1
38
	 * @param ElementBase $el
39
	 * @return self
40
	 */
41 4
	public static function fromASN1(ElementBase $el) {
42 4
		$type = new UnspecifiedType($el->asElement());
43 4
		return new static($type->asPrintableString()->string());
44
	}
45
	
46
	/**
47
	 *
48
	 * @see AttributeValue::toASN1
49
	 * @return PrintableString
50
	 */
51 2
	public function toASN1() {
52 2
		return new PrintableString($this->_string);
53
	}
54
	
55
	/**
56
	 *
57
	 * @see AttributeValue::stringValue
58
	 * @return string
59
	 */
60 1
	public function stringValue() {
61 1
		return $this->_string;
62
	}
63
	
64
	/**
65
	 *
66
	 * @see AttributeValue::equalityMatchingRule
67
	 * @return CaseIgnoreMatch
68
	 */
69 1
	public function equalityMatchingRule() {
70
		// default to caseIgnoreMatch
71 1
		return new CaseIgnoreMatch(Element::TYPE_PRINTABLE_STRING);
72
	}
73
	
74
	/**
75
	 *
76
	 * @see AttributeValue::rfc2253String
77
	 * @return string
78
	 */
79 1
	public function rfc2253String() {
80 1
		return DNParser::escapeString($this->_transcodedString());
81
	}
82
	
83
	/**
84
	 *
85
	 * @see AttributeValue::_transcodedString
86
	 * @return string
87
	 */
88 1
	protected function _transcodedString() {
89
		// PrintableString maps directly to UTF-8
90 1
		return $this->_string;
91
	}
92
}
93