Completed
Pull Request — master (#65)
by Alex
02:11
created

ConnectionTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 27
Duplicated Lines 33.33 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 9 9 1
A testUnauthorizedAccess() 0 9 2

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 ConnectionTest 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'];
0 ignored issues
show
Unused Code introduced by
$apiKey is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
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
    }
39
40
    public function testUnauthorizedAccess()
41
    {
42
        try {
43
            $weather = $this->owm->getWeather('Paris');
0 ignored issues
show
Unused Code introduced by
$weather is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
44
        } catch (OWMException $e) {
45
            $this->assertEquals(401, $e->getCode());
46
            $this->assertRegExp('/^Invalid API key/', $e->getMessage());
47
        }
48
    }
49
}
50