| Total Complexity | 10 |
| Total Lines | 101 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 18 | class ClientData |
||
| 19 | { |
||
| 20 | /** |
||
| 21 | * @var string |
||
| 22 | */ |
||
| 23 | private $rawData; |
||
| 24 | |||
| 25 | /** |
||
| 26 | * @var string |
||
| 27 | */ |
||
| 28 | private $typ; |
||
| 29 | |||
| 30 | /** |
||
| 31 | * @var string |
||
| 32 | */ |
||
| 33 | private $challenge; |
||
| 34 | |||
| 35 | /** |
||
| 36 | * @var string |
||
| 37 | */ |
||
| 38 | private $origin; |
||
| 39 | |||
| 40 | /** |
||
| 41 | * @var string |
||
| 42 | */ |
||
| 43 | private $cid_pubkey; |
||
| 44 | |||
| 45 | /** |
||
| 46 | * ClientData constructor. |
||
| 47 | * |
||
| 48 | * @param string $rawData |
||
| 49 | * @param array $clientData |
||
| 50 | */ |
||
| 51 | private function __construct(string $rawData, array $clientData) |
||
| 52 | { |
||
| 53 | $this->rawData = $rawData; |
||
| 54 | foreach ($clientData as $k => $v) { |
||
| 55 | $this->$k = $v; |
||
| 56 | } |
||
| 57 | } |
||
| 58 | |||
| 59 | /** |
||
| 60 | * @param string $clientData |
||
| 61 | * |
||
| 62 | * @return ClientData |
||
| 63 | */ |
||
| 64 | public static function create(string $clientData): self |
||
| 65 | { |
||
| 66 | $rawData = Base64Url::decode($clientData); |
||
| 67 | $clientData = json_decode($rawData, true); |
||
| 68 | if (!is_array($clientData)) { |
||
| 69 | throw new \InvalidArgumentException('Invalid client data.'); |
||
| 70 | } |
||
| 71 | |||
| 72 | $diff = array_diff_key(get_class_vars(self::class), $clientData); |
||
| 73 | unset($diff['rawData']); |
||
| 74 | if (!empty($diff)) { |
||
| 75 | throw new \InvalidArgumentException('Invalid client data.'); |
||
| 76 | } |
||
| 77 | |||
| 78 | return new self($rawData, $clientData); |
||
| 79 | } |
||
| 80 | |||
| 81 | /** |
||
| 82 | * @return string |
||
| 83 | */ |
||
| 84 | public function getRawData(): string |
||
| 85 | { |
||
| 86 | return $this->rawData; |
||
| 87 | } |
||
| 88 | |||
| 89 | /** |
||
| 90 | * @return string |
||
| 91 | */ |
||
| 92 | public function getType(): string |
||
| 93 | { |
||
| 94 | return $this->typ; |
||
| 95 | } |
||
| 96 | |||
| 97 | /** |
||
| 98 | * @return string |
||
| 99 | */ |
||
| 100 | public function getChallenge(): string |
||
| 103 | } |
||
| 104 | |||
| 105 | /** |
||
| 106 | * @return string |
||
| 107 | */ |
||
| 108 | public function getOrigin(): string |
||
| 111 | } |
||
| 112 | |||
| 113 | /** |
||
| 114 | * @return string |
||
| 115 | */ |
||
| 116 | public function getChannelIdPublicKey(): string |
||
| 119 | } |
||
| 120 | } |
||
| 121 |