Completed
Push — master ( c3530d...654211 )
by Christian
02:38
created

CurrentWeatherGroup::valid()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
/**
3
 * OpenWeatherMap-PHP-API — A php api to parse weather data from http://www.OpenWeatherMap.org .
4
 *
5
 * @license MIT
6
 *
7
 * Please see the LICENSE file distributed with this source code for further
8
 * information regarding copyright and licensing.
9
 *
10
 * Please visit the following links to read about the usage policies and the license of
11
 * OpenWeatherMap before using this class:
12
 *
13
 * @see http://www.OpenWeatherMap.org
14
 * @see http://www.OpenWeatherMap.org/terms
15
 * @see http://openweathermap.org/appid
16
 */
17
18
namespace Cmfcmf\OpenWeatherMap;
19
20
use Cmfcmf\OpenWeatherMap;
21
22
/**
23
 * Class CurrentWeatherGroup used to hold the current weather data for a group of cities.
24
 */
25
class CurrentWeatherGroup implements \Iterator
26
{
27
    /**
28
     * An array of {@link CurrentWeather} objects.
29
     *
30
     * @var CurrentWeather[]
31
     *
32
     * @see CurrentWeather The CurrentWeather class.
33
     */
34
    private $currentWeathers;
35
36
    /**
37
     * @internal
38
     */
39
    private $position = 0;
40
41
    /**
42
     * Create a new current weathers group object.
43
     *
44
     * @param \stdClass $json  The current weathers group json.
45
     * @param string    $units The units used.
46
     *
47
     * @internal
48
     */
49
    public function __construct(\stdClass $json, $units)
50
    {
51
        foreach ($json->list as $currentWeather) {
52
            $this->currentWeathers[] = new CurrentWeather($currentWeather, $units);
53
        }
54
    }
55
56
    /**
57
     * @internal
58
     */
59
    public function rewind()
60
    {
61
        $this->position = 0;
62
    }
63
64
    /**
65
     * @internal
66
     */
67
    public function current()
68
    {
69
        return $this->currentWeathers[$this->position];
70
    }
71
72
    /**
73
     * @internal
74
     */
75
    public function key()
76
    {
77
        return $this->current()->city->id;
78
    }
79
80
    /**
81
     * @internal
82
     */
83
    public function next()
84
    {
85
        ++$this->position;
86
    }
87
88
    /**
89
     * @internal
90
     */
91
    public function valid()
92
    {
93
        return isset($this->currentWeathers[$this->position]);
94
    }
95
}
96