Completed
Push — uv-index ( 9af66d )
by Christian
02:24
created

CurrentWeatherGroup   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 71
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 7
lcom 1
cbo 2
dl 0
loc 71
ccs 17
cts 17
cp 1
rs 10
c 1
b 0
f 1

6 Methods

Rating   Name   Duplication   Size   Complexity  
A rewind() 0 4 1
A current() 0 4 1
A key() 0 4 1
A next() 0 4 1
A valid() 0 4 1
A __construct() 0 6 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 5
    public function __construct(\stdClass $json, $units)
50
    {
51 5
        foreach ($json->list as $currentWeather) {
52 5
            $this->currentWeathers[] = new CurrentWeather($currentWeather, $units);
53 5
        }
54 5
    }
55
56
    /**
57
     * @internal
58
     */
59 3
    public function rewind()
60
    {
61 3
        $this->position = 0;
62 3
    }
63
64
    /**
65
     * @internal
66
     */
67 3
    public function current()
68
    {
69 3
        return $this->currentWeathers[$this->position];
70
    }
71
72
    /**
73
     * @internal
74
     */
75 2
    public function key()
76
    {
77 2
        return $this->current()->city->id;
78
    }
79
80
    /**
81
     * @internal
82
     */
83 2
    public function next()
84
    {
85 2
        ++$this->position;
86 2
    }
87
88
    /**
89
     * @internal
90
     */
91 1
    public function valid()
92
    {
93 1
        return isset($this->currentWeathers[$this->position]);
94
    }
95
}
96