Noaa   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 24
ccs 9
cts 9
cp 1
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getMetarDataString() 0 8 1
A __toString() 0 3 1
A __construct() 0 3 1
1
<?php
2
namespace Ballen\Metar\Providers;
3
4
/**
5
 * Metar
6
 *
7
 * Metar is a PHP library for retrieveing weather reports (METAR infomation),
8
 * the library supports multiple 'METAR prodivers' including NOAA, VATSIM and IVAO.
9
 *
10
 * @author Bobby Allen <[email protected]>
11
 * @license http://www.gnu.org/licenses/gpl-3.0.html
12
 * @link https://github.com/allebb/metar
13
 * @link http://www.bobbyallen.me
14
 *
15
 */
16
use \Ballen\Metar\Helpers\MetarHTTPClient;
17
18
/**
19
 * METAR service provided by the US NOAA (National Oceanic and Atmospheric Administration)
20
 * @link http://www.noaa.gov/
21
 */
22
class Noaa extends MetarHTTPClient implements MetarProviderInterface
23
{
24
25
    private $serviceUrl = 'http://tgftp.nws.noaa.gov/data/observations/metar/stations/{{_ICAO_}}.TXT';
26
    private $icao;
27
28 2
    public function __construct($icao)
29
    {
30 2
        $this->icao = $icao;
31 2
    }
32
33 2
    private function getMetarDataString()
34
    {
35
36 2
        $data = $this->getMetarAPIResponse(str_replace('{{_ICAO_}}', $this->icao, $this->serviceUrl));
37
38
        // The NOAA web service provides a human readable timestamp of when the report was last generated but we don't care about that so we'll jump to the next line (the actual METAR string)
39 2
        $lines = explode($this->icao, $data);
40 2
        return trim($this->icao . $lines[1]);
41
    }
42
43 2
    public function __toString()
44
    {
45 2
        return $this->getMetarDataString();
46
    }
47
}
48