Completed
Push — master ( 6c75f8...8616ea )
by Bobby
01:47
created

MetarHTTPClient   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 4
Bugs 0 Features 3
Metric Value
wmc 3
c 4
b 0
f 3
lcom 1
cbo 2
dl 0
loc 34
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getMetarAPIResponse() 0 9 2
1
<?php
2
3
namespace Ballen\Metar\Helpers;
4
5
use GuzzleHttp\Client as HttpClient;
6
use \Exception;
7
8
/**
9
 * Metar
10
 *
11
 * Metar is a PHP library for retrieveing weather reports (METAR infomation),
12
 * the library supports multiple 'METAR prodivers' including NOAA and VATSIM.
13
 *
14
 * @author Bobby Allen <[email protected]>
15
 * @license http://www.gnu.org/licenses/gpl-3.0.html
16
 * @link https://github.com/bobsta63/metar
17
 * @link http://www.bobbyallen.me
18
 *
19
 */
20
class MetarHTTPClient
21
{
22
23
    /**
24
     * Optional Guzzle Client configuration.
25
     * @var array
26
     */
27
    protected $guzzle_conf;
28
29
    /**
30
     * HTTP Client
31
     * @param array $config Optional Guzzle configuration.
32
     */
33
    public function __construct($config = [])
34
    {
35
        $this->guzzle_conf = $config;
36
    }
37
38
    /**
39
     * Make a HTTP request and retrieve the body.
40
     * @param string $url The URL to request
41
     * @return string
42
     * @throws Exception
43
     */
44
    public function getMetarAPIResponse($url)
45
    {
46
        $client = new HttpClient($this->guzzle_conf);
47
        $response = $client->get($url);
48
        if ($response->getStatusCode() != 200) {
49
            throw new Exception('An error occured when attempting to access the remote webservice, please try again shortly!');
50
        }
51
        return $response->getBody();
52
    }
53
}
54