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 |
||
| 18 | class GeneralNames implements |
||
| 19 | \Countable, \IteratorAggregate |
||
| 20 | { |
||
| 21 | /** |
||
| 22 | * GeneralName objects. |
||
| 23 | * |
||
| 24 | * @var GeneralName[] $_names |
||
| 25 | */ |
||
| 26 | protected $_names; |
||
| 27 | |||
| 28 | /** |
||
| 29 | * Constructor |
||
| 30 | * |
||
| 31 | * @param GeneralName ...$names One or more GeneralName objects |
||
| 32 | */ |
||
| 33 | 43 | public function __construct(GeneralName ...$names) { |
|
| 36 | |||
| 37 | /** |
||
| 38 | * Initialize from ASN.1. |
||
| 39 | * |
||
| 40 | * @param Sequence $seq |
||
| 41 | * @throws \UnexpectedValueException |
||
| 42 | * @return self |
||
| 43 | */ |
||
| 44 | 28 | View Code Duplication | public static function fromASN1(Sequence $seq) { |
| 55 | |||
| 56 | /** |
||
| 57 | * Find first GeneralName by given tag. |
||
| 58 | * |
||
| 59 | * @param int $tag |
||
| 60 | * @return GeneralName|null |
||
| 61 | */ |
||
| 62 | 27 | protected function _findFirst($tag) { |
|
| 70 | |||
| 71 | /** |
||
| 72 | * Check whether GeneralNames contains a GeneralName of given type. |
||
| 73 | * |
||
| 74 | * @param int $tag One of <code>GeneralName::TAG_*</code> enumerations |
||
| 75 | * @return bool |
||
| 76 | */ |
||
| 77 | 2 | public function has($tag) { |
|
| 80 | |||
| 81 | /** |
||
| 82 | * Get first GeneralName of given type. |
||
| 83 | * |
||
| 84 | * @param int $tag One of <code>GeneralName::TAG_*</code> enumerations |
||
| 85 | * @throws \OutOfBoundsException |
||
| 86 | * @return GeneralName |
||
| 87 | */ |
||
| 88 | 25 | public function firstOf($tag) { |
|
| 95 | |||
| 96 | /** |
||
| 97 | * Get all GeneralName objects of given type. |
||
| 98 | * |
||
| 99 | * @param int $tag One of <code>GeneralName::TAG_*</code> enumerations |
||
| 100 | * @return GeneralName[] |
||
| 101 | */ |
||
| 102 | 3 | public function allOf($tag) { |
|
| 109 | |||
| 110 | /** |
||
| 111 | * Get value of the first 'dNSName' type. |
||
| 112 | * |
||
| 113 | * @return string |
||
| 114 | */ |
||
| 115 | 1 | View Code Duplication | public function firstDNS() { |
| 123 | |||
| 124 | /** |
||
| 125 | * Get value of the first 'directoryName' type. |
||
| 126 | * |
||
| 127 | * @return Name |
||
| 128 | */ |
||
| 129 | 10 | View Code Duplication | public function firstDN() { |
| 137 | |||
| 138 | /** |
||
| 139 | * Get value of the first 'uniformResourceIdentifier' type. |
||
| 140 | * |
||
| 141 | * @return string |
||
| 142 | */ |
||
| 143 | 2 | View Code Duplication | public function firstURI() { |
| 152 | |||
| 153 | /** |
||
| 154 | * Generate ASN.1 structure. |
||
| 155 | * |
||
| 156 | * @return Sequence |
||
| 157 | */ |
||
| 158 | 37 | View Code Duplication | public function toASN1() { |
| 169 | |||
| 170 | /** |
||
| 171 | * |
||
| 172 | * @see Countable::count() |
||
| 173 | * @return int |
||
| 174 | */ |
||
| 175 | 1 | public function count() { |
|
| 178 | |||
| 179 | /** |
||
| 180 | * Get iterator for GeneralName objects. |
||
| 181 | * |
||
| 182 | * @see IteratorAggregate::getIterator() |
||
| 183 | * @return \ArrayIterator |
||
| 184 | */ |
||
| 185 | 1 | public function getIterator() { |
|
| 188 | } |
||
| 189 |