OpenWeatherMap::doFetchCurrent()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 22
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 22
ccs 0
cts 14
cp 0
rs 9.2
cc 1
eloc 14
nc 1
nop 1
crap 2
1
<?php
2
/**
3
 *
4
 * PHP version 5.5
5
 *
6
 * @package Forecast
7
 * @author  Sergey V.Kuzin <[email protected]>
8
 * @license MIT
9
 */
10
11
namespace Forecast;
12
13
14
use Forecast\Helper\Point;
15
16
//API key: e83f31c8164f8f7ba48ce24a40e26512
17
class OpenWeatherMap extends WeatherAbstract
18
{
19
20
    public function doFetchCurrent(Point $point)
21
    {
22
        $content = file_get_contents('http://api.openweathermap.org/data/2.5/weather?q=Ulyanovsk,%20RU&units=metric&lang=ru');
23
24
        $result = json_decode($content, true);
25
26
        $cur = new Current();
27
        $cur->setData([
28
            'summary'   => $result['weather'][0]['description'],
29
            'temperature' => [
30
                'current'   => $result['main']['temp'],
31
                'min'   => $result['main']['temp_min'],
32
                'max'  => $result['main']['temp_max'],
33
            ],
34
            'wind'  => [
35
                'speed'  => $result['wind']['speed'],
36
                'degree' => $result['wind']['deg'],
37
            ]
38
        ]);
39
40
        return $cur;
41
    }
42
43
    /**
44
     * @return string
45
     */
46
    protected function getCacheKeyCurrent(Point $point)
47
    {
48
        return 'owm-current-';
49
    }
50
51
    protected function getCacheExpirationCurrent()
52
    {
53
        return new \DateTime('now + 5 minuts');
54
    }
55
56
    /**
57
     * @param Point $point
58
     * @return Hourly
59
     */
60
    protected function doFetchHourly(Point $point)
61
    {
62
        // TODO: Implement doFetchHourly() method.
63
    }
64
65
    /**
66
     * @param Point $point
67
     *
68
     * @internal
69
     * @return string
70
     */
71
    protected function getCacheKeyHourly(Point $point)
72
    {
73
        // TODO: Implement getCacheKeyHourly() method.
74
    }
75
76
    /**
77
     *
78
     * @internal
79
     * @return \DateTime
80
     */
81
    protected function getCacheExpirationHourly()
82
    {
83
        // TODO: Implement getCacheExpirationHourly() method.
84
    }
85
}
86