UtilsTest::testReturnSectorAno()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 9

Duplication

Lines 14
Ratio 100 %

Code Coverage

Tests 10
CRAP Score 1

Importance

Changes 0
Metric Value
dl 14
loc 14
ccs 10
cts 10
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 9
nc 1
nop 0
crap 1
1
<?php
2
3
namespace ApiTest\Helper;
4
5
use Api\Helper\Utils;
6
use Zend\Stdlib\ArrayUtils;
7
use Zend\Test\PHPUnit\Controller\AbstractHttpControllerTestCase;
8
9
class UtilsTest extends AbstractHttpControllerTestCase
10
{
11 2
    public function setUp()
12
    {
13 2
        $configOverrides = [];
14
15 2
        $this->setApplicationConfig(ArrayUtils::merge(
16 2
            include __DIR__.'/../../../../config/application.config.php',
17
            $configOverrides
18
        ));
19
20 2
        $services = $this->getApplicationServiceLocator();
21 2
        $config = $services->get('config');
22 2
        unset($config['db']);
23 2
        $services->setAllowOverride(true);
24 2
        $services->setService('config', $config);
25 2
        $services->setAllowOverride(false);
26
27 2
        parent::setUp();
28 2
    }
29
30 1 View Code Duplication
    public function testReturnSectorGas()
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 1
        $sectore = 'Energía';
33 1
        $gas = 'CO₂';
34 1
        $total = 888;
35
36 1
        $inputArray[] = [
0 ignored issues
show
Coding Style Comprehensibility introduced by
$inputArray was never initialized. Although not strictly required by PHP, it is generally a good practice to add $inputArray = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
37 1
            'sector' => $sectore,
38 1
            'gas' => $gas,
39 1
            'total' => $total,
40
        ];
41
42 1
        $this->assertEquals(Utils::ReturnSectorGas($inputArray, $sectore, $gas), $total); 
43
44 1
    }
45
46 1 View Code Duplication
    public function testReturnSectorAno()
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...
47
    {
48 1
        $sectore = 'Energía';
49 1
        $year = 2014;
50 1
        $total = 888;
51
52 1
        $inputArray[] = [
0 ignored issues
show
Coding Style Comprehensibility introduced by
$inputArray was never initialized. Although not strictly required by PHP, it is generally a good practice to add $inputArray = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
53 1
            'sector' => $sectore,
54 1
            'year' => $year,
55 1
            'total' => $total,
56
        ];
57
58 1
        $this->assertEquals(Utils::ReturnSectorAno($inputArray, $sectore, $year), $total);     
59 1
    }
60
}
61