| Conditions | 4 |
| Paths | 4 |
| Total Lines | 19 |
| Code Lines | 11 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 12 |
| CRAP Score | 4 |
| Changes | 0 | ||
| 1 | <?php |
||
| 29 | 15 | public function __construct(string $onionHost) |
|
| 30 | 15 | { |
|
| 31 | 3 | $array = explode(".", $onionHost); |
|
| 32 | if (count($array) !== 2) { |
||
| 33 | throw new \InvalidArgumentException('Malformed onion address'); |
||
| 34 | 12 | } |
|
| 35 | 12 | ||
| 36 | 3 | list ($ident, $onion) = $array; |
|
| 37 | if ($onion !== 'onion') { |
||
| 38 | throw new \InvalidArgumentException('Malformed onion address'); |
||
| 39 | 9 | } |
|
| 40 | 9 | ||
| 41 | 3 | $decoded = Base32::decode($ident); |
|
| 42 | if (strlen($decoded) !== 10) { |
||
| 43 | throw new \InvalidArgumentException('Malformed onion address'); |
||
| 44 | 6 | } |
|
| 45 | 6 | ||
| 46 | 6 | $this->identifier = $decoded; |
|
| 47 | $this->host = $onionHost; |
||
| 48 | } |
||
| 66 |