Completed
Pull Request — master (#78)
by Alex
02:15
created

Weather   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 3
c 2
b 0
f 1
lcom 1
cbo 0
dl 0
loc 60
ccs 0
cts 14
cp 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __toString() 0 4 1
A getIconUrl() 0 4 1
A __construct() 0 6 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 $iconUrl = "http://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
    public function __construct($id, $description, $icon)
57
    {
58
        $this->id = (int)$id;
59
        $this->description = (string)$description;
60
        $this->icon = (string)$icon;
61
    }
62
63
    /**
64
     * Get the weather description.
65
     *
66
     * @return string
67
     */
68
    public function __toString()
69
    {
70
        return $this->description;
71
    }
72
73
    /**
74
     * Get the icon url.
75
     *
76
     * @return string The icon url.
77
     */
78
    public function getIconUrl()
79
    {
80
        return str_replace("%s", $this->icon, $this->iconUrl);
81
    }
82
}
83