Completed
Push — master ( dadc12...75c176 )
by Christian
03:18 queued 01:17
created

TemperatureTest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 81
Duplicated Lines 41.98 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 3
dl 34
loc 81
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 11 1
A test__toString() 9 9 1
A testGetUnit() 8 8 1
A testGetValue() 0 8 1
A testGetDescription() 8 8 1
A testGetFormatted() 9 9 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
    /**
23
     * @var string
24
     */
25
    protected $unit = 'Berlin';
26
27
    /**
28
     * @var Temperature
29
     */
30
    protected $temperature;
31
32
    /**
33
     * @var string
34
     */
35
    protected $nowTemp = '298.77';
36
37
    /**
38
     * @var string
39
     */
40
    protected $description = 'This is a description';
41
42
    protected function setUp()
43
    {
44
        $units = 'Berlin';
45
        $fakeTempNow = 298.77;
46
        $fakeTempMin = 298.77;
47
        $fakeTempMax = 298.774;
48
        $tempNowUnit = new Unit($fakeTempNow, $units, $this->description);
49
        $tempMinUnit = new Unit($fakeTempMin, $units, $this->description);
50
        $tempMaxUnit = new Unit($fakeTempMax, $units, $this->description);
51
        $this->temperature = new Temperature($tempNowUnit, $tempMinUnit, $tempMaxUnit);
52
    }
53
54 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...
55
    {
56
        $expectStr = $this->nowTemp;
57
        $expectStr .= ' ' . $this->unit;
58
        $str = $this->temperature->__toString();
59
60
        $this->assertSame($expectStr, $str);
61
        $this->assertInternalType('string', $str);
62
    }
63
64 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...
65
    {
66
        $expectUnit = $this->unit;
67
        $unit = $this->temperature->getUnit();
68
69
        $this->assertSame($expectUnit, $unit);
70
        $this->assertInternalType('string', $unit);
71
    }
72
73
    public function testGetValue()
74
    {
75
        $expectValue = round($this->nowTemp, 2);
76
        $value = $this->temperature->getValue();
77
78
        $this->assertSame($expectValue, $value);
79
        $this->assertInternalType('double', $value);
80
    }
81
82 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...
83
    {
84
        $expectDescription = $this->description;
85
        $description = $this->temperature->getDescription();
86
87
        $this->assertSame($expectDescription, $description);
88
        $this->assertInternalType('string', $description);
89
    }
90
91 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...
92
    {
93
        $expectFormattedString = $this->nowTemp;
94
        $expectFormattedString .= ' ' . $this->unit;
95
        $formattedString = $this->temperature->getFormatted();
96
97
        $this->assertSame($expectFormattedString, $formattedString);
98
        $this->assertInternalType('string', $formattedString);
99
    }
100
}
101