Completed
Pull Request — master (#97)
by lee
02:08
created

Weather   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 71
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A __toString() 0 4 1
A getIconUrl() 0 4 1
A setIconUrlTemplate() 0 4 1
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\Util;
19
20
/**
21
 * The weather class representing a weather object.
22
 */
23
class Weather
24
{
25
    /**
26
     * @var int The weather id.
27
     */
28
    public $id;
29
30
    /**
31
     * @var string The weather description.
32
     */
33
    public $description;
34
35
    /**
36
     * @var string the icon name.
37
     */
38
    public $icon;
39
40
    /**
41
     * @var string The url for icons.
42
     *
43
     * @see self::getIconUrl() to see how it is used.
44
     */
45
    private static $iconUrl = "//openweathermap.org/img/w/%s.png";
46
47
    /**
48
     * Create a new weather object.
49
     *
50
     * @param int    $id          The icon id.
51
     * @param string $description The weather description.
52
     * @param string $icon        The icon name.
53
     *
54
     * @internal
55
     */
56 22
    public function __construct($id, $description, $icon)
57
    {
58 22
        $this->id = (int)$id;
59 22
        $this->description = (string)$description;
60 22
        $this->icon = (string)$icon;
61 22
    }
62
63
    /**
64
     * Get the weather description.
65
     *
66
     * @return string
67
     */
68 1
    public function __toString()
69
    {
70 1
        return $this->description;
71
    }
72
73
    /**
74
     * Get the icon url.
75
     *
76
     * @return string The icon url.
77
     */
78 2
    public function getIconUrl()
79
    {
80 2
        return sprintf(self::$iconUrl, $this->icon);
81
    }
82
83
    /**
84
     * Change the url template for icon urls. Please note: This will change the url template for
85
     * all instances of this library.
86
     *
87
     * @param string $iconUrl The url template to build the icon urls.
88
     */
89 1
    public static function setIconUrlTemplate($iconUrl)
90
    {
91 1
        self::$iconUrl = $iconUrl;
92 1
    }
93
}
94