Failed Conditions
Push — v7 ( 722dd5...1e67af )
by Florent
03:17
created

UrlKeySetFactory   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 3
dl 0
loc 44
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getContent() 0 11 2
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * The MIT License (MIT)
7
 *
8
 * Copyright (c) 2014-2017 Spomky-Labs
9
 *
10
 * This software may be modified and distributed under the terms
11
 * of the MIT license.  See the LICENSE file for details.
12
 */
13
14
namespace Jose\Component\KeyManagement;
15
16
use Http\Client\HttpClient;
17
use Http\Message\RequestFactory;
18
19
abstract class UrlKeySetFactory
20
{
21
    /**
22
     * @var HttpClient
23
     */
24
    private $client;
25
26
    /**
27
     * @var RequestFactory
28
     */
29
    private $requestFactory;
30
31
    /**
32
     * JKUManager constructor.
33
     *
34
     * @param HttpClient     $client
35
     * @param RequestFactory $requestFactory
36
     */
37
    public function __construct(HttpClient $client, RequestFactory $requestFactory)
38
    {
39
        $this->client = $client;
40
        $this->requestFactory = $requestFactory;
41
    }
42
43
    /**
44
     * @param string $url
45
     * @param array  $headers
46
     *
47
     * @throws \HttpRuntimeException
48
     *
49
     * @return string
50
     */
51
    protected function getContent(string $url, array $headers = []): string
52
    {
53
        $request = $this->requestFactory->createRequest('GET', $url, $headers);
54
        $response = $this->client->sendRequest($request);
55
56
        if (200 !== $response->getStatusCode()) {
57
            throw new \HttpRuntimeException('Unable to get the key set.', $response->getStatusCode());
58
        }
59
60
        return $response->getBody()->getContents();
61
    }
62
}
63