Completed
Push β€” master ( a3c7a7...bd72ff )
by Carlos
02:47
created

StockTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 47
Duplicated Lines 57.45 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 1
cbo 2
dl 27
loc 47
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testAdd() 13 13 1
A testReduce() 14 14 1
A testGetSkuInfo() 0 7 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
/**
4
 * Created by PhpStorm.
5
 * User: pjxh
6
 * Date: 15-11-1
7
 * Time: δΈ‹εˆ5:11
8
 */
9
namespace Overtrue\Wechat\Test\Shop;
10
11
12
use Overtrue\Wechat\Shop\Stock;
13
use Overtrue\Wechat\Test\TestBase;
14
15
class StockTest extends TestBase
16
{
17
//    /**
18
//     * @depends ProductTest::testCreate
19
//     * @depends testGetSkuInfo
20
//     */
21 View Code Duplication
    public function testAdd()
22
    {
23
        $productId = 'pe4OowbHVULEWICFN1t6iy2BPWXA';
24
        $skuInfo = '';
0 ignored issues
show
Unused Code introduced by
$skuInfo 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...
25
        
26
        $stock = new Stock($this->http);
27
        $response = $stock->add($productId,100);
0 ignored issues
show
Documentation introduced by
100 is of type integer, but the function expects a array.

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...
28
        $this->assertTrue($response);
29
30
        $stock = new Stock($this->http);
31
        $response = $stock->add($productId,'100');
0 ignored issues
show
Documentation introduced by
'100' is of type string, but the function expects a array.

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
        $this->assertTrue($response);
33
    }
34
35
//    /**
36
//     * @depends ProductTest::testCreate
37
//     * @depends testGetSkuInfo
38
//     */
39 View Code Duplication
    public function testReduce()
40
    {
41
42
        $productId = 'pe4OowbHVULEWICFN1t6iy2BPWXA';
43
        $skuInfo = '';
0 ignored issues
show
Unused Code introduced by
$skuInfo 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...
44
        
45
        $stock = new Stock($this->http);
46
        $response = $stock->reduce($productId,100);
0 ignored issues
show
Documentation introduced by
$productId is of type string, but the function expects a array.

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...
47
        $this->assertTrue($response);
48
49
        $stock = new Stock($this->http);
50
        $response = $stock->reduce($productId,100);
0 ignored issues
show
Documentation introduced by
$productId is of type string, but the function expects a array.

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->assertTrue($response);
52
    }
53
54
    public function testGetSkuInfo()
55
    {
56
        
57
        $stock = new Stock($this->http);
58
        $data = $stock->getSkuInfo(array(array('a','a1'),array('b','b1')));
59
        $this->assertEquals('a:a1;b:b1',$data);
60
    }
61
}
62