Passed
Push — master ( 3d16e3...2ad042 )
by Alex
05:12
created

TTypeRefTypeTest   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 58
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 8
c 1
b 0
f 0
lcom 1
cbo 2
dl 58
loc 58
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A testSetDefaultValueNullString() 6 6 1
A testSetDefaultValueActualString() 6 6 1
A testSetDefaultValueEmptyArrayAsString() 13 13 2
A testSetDefaultValueNonEmptyArrayAsString() 13 13 2
A testSetDefaultValueObjectAsString() 13 13 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
namespace AlgoWeb\ODataMetadata\Tests\v3\edm;
4
5
use AlgoWeb\ODataMetadata\MetadataV3\edm\TTypeRefType;
6
use AlgoWeb\ODataMetadata\Tests\TestCase;
7
8 View Code Duplication
class TTypeRefTypeTest extends TestCase
0 ignored issues
show
Duplication introduced by
This class 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...
9
{
10
    public function testSetDefaultValueNullString()
11
    {
12
        $foo = new TTypeRefType();
13
        $foo->setDefaultValue(null);
14
        $this->assertEquals(null, $foo->getDefaultValue());
15
    }
16
17
    public function testSetDefaultValueActualString()
18
    {
19
        $foo = new TTypeRefType();
20
        $foo->setDefaultValue("string");
21
        $this->assertEquals('string', $foo->getDefaultValue());
22
    }
23
24
    public function testSetDefaultValueEmptyArrayAsString()
25
    {
26
        $expected = "Default value must be a string";
27
        $actual = null;
28
29
        $foo = new TTypeRefType();
30
        try {
31
            $foo->setDefaultValue([]);
1 ignored issue
show
Documentation introduced by
array() is of type array, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
32
        } catch (\InvalidArgumentException $e) {
33
            $actual = $e->getMessage();
34
        }
35
        $this->assertEquals($expected, $actual);
36
    }
37
38
    public function testSetDefaultValueNonEmptyArrayAsString()
39
    {
40
        $expected = "Default value must be a string";
41
        $actual = null;
42
43
        $foo = new TTypeRefType();
44
        try {
45
            $foo->setDefaultValue(['a']);
1 ignored issue
show
Documentation introduced by
array('a') is of type array<integer,string,{"0":"string"}>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
46
        } catch (\InvalidArgumentException $e) {
47
            $actual = $e->getMessage();
48
        }
49
        $this->assertEquals($expected, $actual);
50
    }
51
52
    public function testSetDefaultValueObjectAsString()
53
    {
54
        $expected = "Default value must be a string";
55
        $actual = null;
56
57
        $foo = new TTypeRefType();
58
        try {
59
            $foo->setDefaultValue(new \DateTime());
1 ignored issue
show
Documentation introduced by
new \DateTime() is of type object<DateTime>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
60
        } catch (\InvalidArgumentException $e) {
61
            $actual = $e->getMessage();
62
        }
63
        $this->assertEquals($expected, $actual);
64
    }
65
}
66