Noaa::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
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