Passed
Push — master ( 96610e...18fd6e )
by Radosław
02:18
created

FieldTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 80
Duplicated Lines 17.5 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 2
dl 14
loc 80
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A testNonIntegerFid() 0 4 1
B testReturnedArray() 0 27 1
A testIntegerValue() 7 7 1
A testFloatValue() 7 7 1
A testDateValue() 0 8 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
use PHPUnit\Framework\TestCase;
4
use Radowoj\Yaah\Field;
5
6
class FieldTest extends TestCase
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
7
{
8
9
    /**
10
     * @expectedException Radowoj\Yaah\Exception
11
     * @expectedExceptionMessage fid must be an integer
12
     */
13
    public function testNonIntegerFid()
14
    {
15
        $field = new Field('some string');
0 ignored issues
show
Unused Code introduced by
$field 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...
16
    }
17
18
19
    /**
20
     * Tests that output of Field->toArray() has the exact keys expected by WebAPI
21
     * @return void
22
     */
23
    public function testReturnedArray()
24
    {
25
        $field = new Field(1, 'some string');
26
27
        $this->assertEquals([
28
            'fid' => 1,
29
            'fvalueString' => 'some string',
30
            'fvalueInt' => 0,
31
            'fvalueFloat' => 0,
32
            'fvalueImage' => 0,
33
            'fvalueDatetime' => 0,
34
            'fvalueDate' => '',
35
            'fvalueRangeInt' => [
36
                'fvalueRangeIntMin' => 0,
37
                'fvalueRangeIntMax' => 0,
38
            ],
39
            'fvalueRangeFloat' => [
40
                'fvalueRangeFloatMin' => 0,
41
                'fvalueRangeFloatMax' => 0,
42
            ],
43
            'fvalueRangeDate' => [
44
                'fvalueRangeDateMin' => '',
45
                'fvalueRangeDateMax' => '',
46
            ],
47
48
        ], $field->toArray());
49
    }
50
51
    /**
52
     * Tests integer value representation
53
     * @return void
54
     */
55 View Code Duplication
    public function testIntegerValue()
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...
56
    {
57
        $int = 10;
58
        $array = (new Field(1, $int))->toArray();
59
        $this->assertArrayHasKey('fvalueInt', $array);
60
        $this->assertSame($array['fvalueInt'], $int);
61
    }
62
63
64
    /**
65
     * Tests float value representation
66
     * @return void
67
     */
68 View Code Duplication
    public function testFloatValue()
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...
69
    {
70
        $float = 13.5;
71
        $array = (new Field(1, $float))->toArray();
72
        $this->assertArrayHasKey('fvalueFloat', $array);
73
        $this->assertSame($array['fvalueFloat'], $float);
74
    }
75
76
77
    public function testDateValue()
78
    {
79
        $date = '01-03-2017';
80
        $array = (new Field(1, $date))->toArray();
81
        $this->assertArrayHasKey('fvalueDate', $array);
82
        $this->assertSame($array['fvalueDate'], $date);
83
84
    }
85
}
86