| Total Complexity | 10 |
| Total Lines | 50 |
| Duplicated Lines | 0 % |
| Coverage | 0% |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 8 | class BasicNetworkResolver implements NetworkResolverInterface |
||
| 9 | { |
||
| 10 | /** |
||
| 11 | * @var ServerRequestInterface|null |
||
| 12 | */ |
||
| 13 | private $serverRequest; |
||
| 14 | |||
| 15 | public function getRemoteIp(): string |
||
| 16 | { |
||
| 17 | $ip = $this->getServerRequest()->getServerParams()['REMOTE_ADDR'] ?? null; |
||
| 18 | if ($ip === null) { |
||
| 19 | throw new \RuntimeException('Remote IP is not available!'); |
||
| 20 | } |
||
| 21 | return (string)$ip; |
||
| 22 | } |
||
| 23 | |||
| 24 | public function getUserIp(): string |
||
| 25 | { |
||
| 26 | return $this->getRemoteIp(); |
||
| 27 | } |
||
| 28 | |||
| 29 | public function getRequestScheme(): string |
||
| 30 | { |
||
| 31 | return $this->getServerRequest()->getUri()->getScheme(); |
||
| 32 | } |
||
| 33 | |||
| 34 | public function isSecureConnection(): bool |
||
| 35 | { |
||
| 36 | return $this->getRequestScheme() === 'https'; |
||
| 37 | } |
||
| 38 | |||
| 39 | public function setServerRequest(ServerRequestInterface $serverRequest) |
||
| 40 | { |
||
| 41 | $this->serverRequest = $serverRequest; |
||
| 42 | return $this; |
||
| 43 | } |
||
| 44 | |||
| 45 | public function withServerRequest(ServerRequestInterface $serverRequest) |
||
| 46 | { |
||
| 47 | $new = clone $this; |
||
| 48 | $new->setServerRequest($serverRequest); |
||
| 49 | return $new; |
||
| 50 | } |
||
| 51 | |||
| 52 | protected function getServerRequest(bool $throwIfNull = true): ?ServerRequestInterface |
||
| 58 | } |
||
| 59 | } |
||
| 60 |