| Total Complexity | 6 |
| Total Lines | 50 |
| Duplicated Lines | 0 % |
| Coverage | 92.86% |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 14 | class WebhookFetcher implements WebhookFetcherInterface |
||
| 15 | { |
||
| 16 | /** |
||
| 17 | * @var NormalizerInterface |
||
| 18 | */ |
||
| 19 | private $normalizer; |
||
| 20 | |||
| 21 | /** |
||
| 22 | * WebhookFetcher constructor. |
||
| 23 | * |
||
| 24 | * @param NormalizerInterface $normalizer |
||
| 25 | */ |
||
| 26 | 3 | public function __construct(NormalizerInterface $normalizer) |
|
| 27 | { |
||
| 28 | 3 | $this->normalizer = $normalizer; |
|
| 29 | 3 | } |
|
| 30 | |||
| 31 | /** |
||
| 32 | * @param RequestInterface|string $request |
||
| 33 | * |
||
| 34 | * @throws BadRequestException |
||
| 35 | * |
||
| 36 | * @return UpdateType |
||
| 37 | */ |
||
| 38 | 3 | public function fetch($request): UpdateType |
|
| 39 | { |
||
| 40 | 3 | $input = \json_decode($this->getContents($request)); |
|
| 41 | 3 | if (!($input instanceof \stdClass)) { |
|
| 42 | 1 | throw new BadRequestException('Request content must be valid JSON object.'); |
|
| 43 | } |
||
| 44 | |||
| 45 | 2 | return $this->normalizer->denormalize($input, UpdateType::class); |
|
| 46 | } |
||
| 47 | |||
| 48 | /** |
||
| 49 | * @param $request |
||
| 50 | * |
||
| 51 | * @throws BadRequestException |
||
| 52 | * |
||
| 53 | * @return string |
||
| 54 | */ |
||
| 55 | 3 | private function getContents($request): string |
|
| 64 | } |
||
| 65 | } |
||
| 66 |