Completed
Pull Request — master (#93)
by lee
12:27
created

TemperatureTest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 70
Duplicated Lines 54.29 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 2
dl 38
loc 70
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 11 1
A test__toString() 10 10 1
A testGetUnit() 9 9 1
A testGetValue() 0 8 1
A testGetDescription() 9 9 1
A testGetFormatted() 10 10 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
 * Copyright Zikula Foundation 2014 - Zikula Application Framework
4
 *
5
 * This work is contributed to the Zikula Foundation under one or more
6
 * Contributor Agreements and licensed to You under the following license:
7
 *
8
 * @license GNU/LGPv3 (or at your option any later version).
9
 * @package OpenWeatherMap-PHP-Api
10
 *
11
 * Please see the NOTICE file distributed with this source code for further
12
 * information regarding copyright and licensing.
13
 */
14
15
namespace Cmfcmf\OpenWeatherMap\Tests\Util;
16
17
use \Cmfcmf\OpenWeatherMap\Util\Unit;
18
use \Cmfcmf\OpenWeatherMap\Util\Temperature;
19
20
class TemperatureTest extends \PHPUnit_Framework_TestCase
21
{
22
    protected $unit = 'Berlin';
23
    protected $temperature;
24
    protected $nowTemp = '298.77';
25
    protected $description = 'This is a description';
26
27
    protected function setUp()
28
    {
29
        $units = 'Berlin';
30
        $fakeTempNow = 298.77;
31
        $fakeTempMin = 298.77;
32
        $fakeTempMax = 298.774;
33
        $tempNowUnit = new Unit($fakeTempNow, $units, $this->description);
34
        $tempMinUnit = new Unit($fakeTempMin, $units, $this->description);
35
        $tempMaxUnit = new Unit($fakeTempMax, $units, $this->description);
36
        $this->temperature = new Temperature($tempNowUnit, $tempMinUnit, $tempMaxUnit);
37
    }
38
39 View Code Duplication
    public function test__toString()
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...
40
    {
41
        $expectStr = $this->nowTemp;
42
        $expectStr .= ' ' . $this->unit;
43
        $temp = $this->temperature;
44
        $str = $temp->__toString();
45
46
        $this->assertSame($expectStr, $str);
47
        $this->assertInternalType('string', $str);
48
    }
49
50 View Code Duplication
    public function testGetUnit()
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...
51
    {
52
        $expectUnit = $this->unit;
53
        $temp = $this->temperature;
54
        $unit = $temp->getUnit();
55
56
        $this->assertSame($expectUnit, $unit);
57
        $this->assertInternalType('string', $unit);
58
    }
59
60
    public function testGetValue()
61
    {
62
        $expectValue = $this->nowTemp;
0 ignored issues
show
Unused Code introduced by
$expectValue 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...
63
        $temp = $this->temperature;
64
        $value = $temp->getValue();
65
66
        $this->assertInternalType('double', $value);
67
    }
68
69 View Code Duplication
    public function testGetDescription()
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...
70
    {
71
        $expectDescription = $this->description;
72
        $temp = $this->temperature;
73
        $description = $temp->getDescription();
74
75
        $this->assertSame($expectDescription, $description);
76
        $this->assertInternalType('string', $description);
77
    }
78
79 View Code Duplication
    public function testGetFormatted()
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...
80
    {
81
        $expectFormattedString = $this->nowTemp;
82
        $expectFormattedString .= ' ' . $this->unit;
83
        $temp = $this->temperature;
84
        $formattedString = $temp->getFormatted();
85
86
        $this->assertSame($expectFormattedString, $formattedString);
87
        $this->assertInternalType('string', $formattedString);
88
    }
89
}
90