Completed
Pull Request — master (#67)
by Alex
03:14
created

ForecastDailyTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 58
Duplicated Lines 17.24 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 2
Bugs 1 Features 0
Metric Value
wmc 2
c 2
b 1
f 0
lcom 1
cbo 0
dl 10
loc 58
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 10 10 1
B testByCity() 0 39 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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\IntegTests;
19
20
use Cmfcmf\OpenWeatherMap;
21
use Cmfcmf\OpenWeatherMap\Exception as OWMException;
22
23
class ForecastDailyTest extends \PHPUnit_Framework_TestCase
24
{
25
    /**
26
     * @var \OpenWeatherMap
27
     */
28
    protected $owm;
29
30 View Code Duplication
    protected function setUp()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
31
    {
32
33
        // Load the app configuration
34
        $ini = parse_ini_file(__DIR__ . '/ApiKey.ini');
35
        $apiKey = $ini['api_key'];
36
37
        $this->owm = new OpenWeatherMap();
0 ignored issues
show
Documentation Bug introduced by
It seems like new \Cmfcmf\OpenWeatherMap() of type object<Cmfcmf\OpenWeatherMap> is incompatible with the declared type object<OpenWeatherMap> of property $owm.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
38
        $this->owm->setApiKey($apiKey);
39
    }
40
41
    public function testByCity()
42
    {
43
        // Default units (imperial) and language (English)
0 ignored issues
show
Unused Code Comprehensibility introduced by
38% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
44
        $forecast = $this->owm->getWeatherForecast('Berlin', 'metric', 'de', '', 10);
45
46
        $now = new \DateTime();
47
        $this->assertEquals($now->format('d.m.Y H:i'), $forecast->lastUpdate->format('d.m.Y H:i'));
48
49
        $this->assertEquals('Berlin', $forecast->city->name);
50
        $this->assertEquals('05:00:53', $forecast->sun->rise->format("H:i:s"));
51
        $this->assertEquals('17:25:40', $forecast->sun->set->format("H:i:s"));
52
53
        $this->assertEquals(10, iterator_count($forecast));
54
55
        $forecast_arr = iterator_to_array($forecast);
56
57
        $this->assertEquals('4.59 &deg;C', $forecast_arr[0]->temperature);
58
        $this->assertEquals('7.34 &deg;C', $forecast_arr[1]->temperature);
59
        $this->assertEquals('5.58 &deg;C', $forecast_arr[2]->temperature->now);
60
        $this->assertEquals('6.14 &deg;C', $forecast_arr[3]->temperature);
61
        $this->assertEquals('7.56 &deg;C', $forecast_arr[4]->temperature);
62
        $this->assertEquals('10.24 &deg;C', $forecast_arr[5]->temperature);
63
        $this->assertEquals('9.34 &deg;C', $forecast_arr[6]->temperature);
64
        $this->assertEquals('10.93 &deg;C', $forecast_arr[7]->temperature->now);
65
        $this->assertEquals('8.8 &deg;C', $forecast_arr[8]->temperature);
66
        $this->assertEquals('8.02 &deg;C', $forecast_arr[9]->temperature);
67
68
        $this->assertEquals('2.71 &deg;C', $forecast_arr[0]->temperature->min);
69
        $this->assertEquals('9.07 &deg;C', $forecast_arr[1]->temperature->max);
70
        $this->assertEquals('8.31 &deg;C', $forecast_arr[2]->temperature->day);
71
        $this->assertEquals('2.93 &deg;C', $forecast_arr[3]->temperature->morning);
72
        $this->assertEquals('8.99 &deg;C', $forecast_arr[4]->temperature->evening);
73
        $this->assertEquals('8.91 &deg;C', $forecast_arr[5]->temperature->night);
74
75
        $this->assertEquals('&deg;C', $forecast_arr[6]->temperature->getUnit());
76
        $this->assertEquals('10.93', $forecast_arr[7]->temperature->getValue());
77
        $this->assertEmpty($forecast_arr[8]->temperature->getDescription());
78
        $this->assertEquals('8.02 &deg;C', $forecast_arr[9]->temperature->getFormatted());
79
    }
80
}
81