Completed
Push — master ( 8f8c2e...dcaee8 )
by Max
01:08
created

MetadataTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 60
Duplicated Lines 93.33 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 2
dl 56
loc 60
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testDirect() 28 28 1
A testExtended() 28 28 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 (c) 2020 Mendel <[email protected]>
4
 * @license see license.txt
5
 */
6
namespace drycart\data\tests;
7
use drycart\data\MetaData;
8
9
/**
10
 * @author mendel
11
 */
12
class MetadataTest extends \PHPUnit\Framework\TestCase
13
{
14 View Code Duplication
    public function testDirect()
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...
15
    {
16
        $helper = new MetaData(
17
            dummy\DummyModel::class,
18
            ['@var'=>'var','@param'=>'param', '@return'=>'return']);
19
        $fields = $helper->fields();
20
        $this->assertIsArray($fields);
21
        $this->assertCount(2, $fields);
0 ignored issues
show
Documentation introduced by
$fields is of type array, but the function expects a object<Countable>|object...nit\Framework\iterable>.

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...
22
        $this->assertArrayHasKey('name', $fields);
23
        $this->assertArrayHasKey('age', $fields);
24
        
25
        $this->assertIsArray($fields['name']);
26
        $this->assertCount(1, $fields['name']);
27
        $this->assertArrayHasKey('var', $fields['name']);
28
        $this->assertEquals([['string','name']],$fields['name']['var']);
29
        
30
        $this->assertIsArray($fields['age']);
31
        $this->assertCount(1, $fields['age']);
32
        $this->assertArrayHasKey('var', $fields['age']);
33
        $this->assertEquals([['int','age']],$fields['age']['var']);
34
        
35
        $this->assertEquals(
36
            $helper->methods(),
37
            [
38
                'hydrate'=>['return'=>[['void']],'param'=>[['array', '$data']]],
39
            ]
40
        );
41
    }
42
    
43 View Code Duplication
    public function testExtended()
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...
44
    {
45
        $helper = new MetaData(
46
            dummy\DummyExtendedModel::class,
47
            ['@var'=>'var','@param'=>'param', '@return'=>'return']);
48
        $fields = $helper->fields();
49
        $this->assertIsArray($fields);
50
        $this->assertCount(2, $fields);
0 ignored issues
show
Documentation introduced by
$fields is of type array, but the function expects a object<Countable>|object...nit\Framework\iterable>.

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...
51
        $this->assertArrayHasKey('name', $fields);
52
        $this->assertArrayHasKey('age', $fields);
53
        
54
        $this->assertIsArray($fields['name']);
55
        $this->assertCount(1, $fields['name']);
56
        $this->assertArrayHasKey('var', $fields['name']);
57
        $this->assertEquals([['string','name']],$fields['name']['var']);
58
        
59
        $this->assertIsArray($fields['age']);
60
        $this->assertCount(1, $fields['age']);
61
        $this->assertArrayHasKey('var', $fields['age']);
62
        $this->assertEquals([['int','age']],$fields['age']['var']);
63
        
64
        $this->assertEquals(
65
            $helper->methods(),
66
            [
67
                'hydrate'=>['return'=>[['void']],'param'=>[['array', '$data']]],
68
            ]
69
        );
70
    }
71
}
72