| Total Complexity | 6 |
| Total Lines | 53 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 0 | ||
| 1 | <?php |
||
| 11 | class Onion implements IpInterface |
||
| 12 | { |
||
| 13 | const MAGIC = "\xFD\x87\xD8\x7E\xEB\x43"; |
||
| 14 | |||
| 15 | /** |
||
| 16 | * @var string |
||
| 17 | */ |
||
| 18 | private $host; |
||
| 19 | |||
| 20 | /** |
||
| 21 | * @var string |
||
| 22 | */ |
||
| 23 | private $identifier; |
||
| 24 | |||
| 25 | /** |
||
| 26 | * Onion constructor. |
||
| 27 | 15 | * @param string $onionHost |
|
| 28 | */ |
||
| 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 | } |
||
| 49 | |||
| 50 | /** |
||
| 51 | 6 | * @return string |
|
| 52 | */ |
||
| 53 | 6 | public function getHost(): string |
|
| 56 | } |
||
| 57 | |||
| 58 | /** |
||
| 59 | 6 | * @return BufferInterface |
|
| 60 | */ |
||
| 61 | 6 | public function getBuffer() |
|
| 64 | } |
||
| 65 | } |
||
| 66 |