Completed
Push — master ( a3c7a7...bd72ff )
by Carlos
02:47
created

ProductTest::testGetProperty()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 8
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 8
loc 8
rs 9.4286
cc 1
eloc 5
nc 1
nop 0
1
<?php
2
3
/**
4
 * Created by PhpStorm.
5
 * User: pjxh
6
 * Date: 15-11-1
7
 * Time: 下午5:10
8
 */
9
namespace Overtrue\Wechat\Test\Shop;
10
11
12
use Overtrue\Wechat\Image;
13
use Overtrue\Wechat\Shop\Product;
14
use Overtrue\Wechat\Test\TestBase;
15
use Symfony\Component\Yaml\Yaml;
16
use Overtrue\Wechat\Shop\Data\Product as ProductData;
17
use Overtrue\Wechat\Media;
18
19
class ProductTest extends TestBase
20
{
21
22 View Code Duplication
    public function testCreate()
23
    {
24
25
        $image = new Image($this->config->appId,$this->config->appSecret);
0 ignored issues
show
Documentation introduced by
The property appId does not exist on object<Overtrue\Wechat\Shop\Config>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
Documentation introduced by
The property appSecret does not exist on object<Overtrue\Wechat\Shop\Config>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
26
        $images = $image->upload(__DIR__.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'Image'.DIRECTORY_SEPARATOR.'aa.jpg');
27
28
        $product = new Product($this->http);
29
        $response = $product->create(function(ProductData $product) use ($images)  {
30
31
32
            $product->setBaseAttr($images,array($images,$images),null,'商品名',536891949)
0 ignored issues
show
Documentation introduced by
'商品名' is of type string, but the function expects a null.

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...
Documentation introduced by
536891949 is of type integer, but the function expects a null.

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...
33
                ->setDetail('text','text')
34
                ->setDetail('img',$images);
35
36
            $testData = Yaml::parse(file_get_contents(__DIR__.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'Config'.DIRECTORY_SEPARATOR.'Data.yml'));
37
38
            foreach ($testData['Overtrue\Wechat\Test\Shop\ProductTest']['testGetProperty'] as $value) {
39
                $product->setProperty($value['id'],$value['property_value'][0]['id']);
40
            }
41
42
            foreach ($testData['Overtrue\Wechat\Test\Shop\ProductTest']['testGetSku'] as $value) {
43
                foreach ($value['value_list'] as $key => $valueList) {
44
                    //此判断仅是为了 让子序列少点,实际程序按照自身的逻辑来
45
                    if ($key % 5 == 0 && $key % 2 == 0) {
46
                        $skuList[] = $valueList['id'];
0 ignored issues
show
Coding Style Comprehensibility introduced by
$skuList was never initialized. Although not strictly required by PHP, it is generally a good practice to add $skuList = 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...
47
                    }
48
49
                }
50
                $skuInfo[] = array('id'=>$value['id'],'vid'=>$skuList);
0 ignored issues
show
Coding Style Comprehensibility introduced by
$skuInfo was never initialized. Although not strictly required by PHP, it is generally a good practice to add $skuInfo = 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...
Bug introduced by
The variable $skuList does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
51
                $product->setSkuInfo($value['id'],$skuList);
52
            }
53
54
            foreach ($skuInfo[0]['vid'] as $vid) {
55
                foreach ($skuInfo[1]['vid'] as $vid1) {
56
                    $product->setSkuList(100, 20, $images, 100, array(array($skuInfo[0]['id'], $vid), array($skuInfo[1]['id'], $vid1)));
0 ignored issues
show
Bug introduced by
The variable $skuInfo does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
Documentation introduced by
array(array($skuInfo[0][...uInfo[1]['id'], $vid1)) is of type array<integer,array<inte...:\"?\",\"1\":\"?\"}>"}>, but the function expects a null.

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...
57
                }
58
            }
59
60
            $product->setAttrext(0,1,1,1)
61
                ->setLocation('浙江省','杭州市','滨江区阿里园')
62
                ->setDeliveryInfo(1,'400184224');
0 ignored issues
show
Documentation introduced by
'400184224' is of type string, but the function expects a null.

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...
63
64
            return $product;
65
        });
66
67
        $this->assertTrue(is_string($response));
68
69
        return $response;
70
    }
71
72
    /**
73
     * @depends testCreate
74
     */
75 View Code Duplication
    public function testUpdate($productId)
76
    {
77
        $image = new Image($this->config->appId,$this->config->appSecret);
0 ignored issues
show
Documentation introduced by
The property appId does not exist on object<Overtrue\Wechat\Shop\Config>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
Documentation introduced by
The property appSecret does not exist on object<Overtrue\Wechat\Shop\Config>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
78
        $images = $image->upload(__DIR__.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'Image'.DIRECTORY_SEPARATOR.'aa.jpg');
79
80
        //未上架的
81
        $product = new Product($this->http);
82
        $response = $product->update(function(ProductData $product) use ($images)  {
83
84
            $product->setBaseAttr($images,array($images,$images),null,'商品名',536891949)
0 ignored issues
show
Documentation introduced by
'商品名' is of type string, but the function expects a null.

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...
Documentation introduced by
536891949 is of type integer, but the function expects a null.

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...
85
                ->setDetail('text','text')
86
                ->setDetail('img',$images);
87
88
            $testData = Yaml::parse(file_get_contents(__DIR__.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'Config'.DIRECTORY_SEPARATOR.'Data.yml'));
89
90
            foreach ($testData['Overtrue\Wechat\Test\Shop\ProductTest']['testGetProperty'] as $value) {
91
                $product->setProperty($value['id'],$value['property_value'][0]['id']);
92
            }
93
94
            foreach ($testData['Overtrue\Wechat\Test\Shop\ProductTest']['testGetSku'] as $value) {
95
                foreach ($value['value_list'] as $key => $valueList) {
96
                    //此判断仅是为了 让子序列少点,实际程序按照自身的逻辑来
97
                    if ($key % 5 == 0 && $key % 2 == 0) {
98
                        $skuList[] = $valueList['id'];
0 ignored issues
show
Coding Style Comprehensibility introduced by
$skuList was never initialized. Although not strictly required by PHP, it is generally a good practice to add $skuList = 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...
99
                    }
100
101
                }
102
                $skuInfo[] = array('id'=>$value['id'],'vid'=>$skuList);
0 ignored issues
show
Coding Style Comprehensibility introduced by
$skuInfo was never initialized. Although not strictly required by PHP, it is generally a good practice to add $skuInfo = 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...
Bug introduced by
The variable $skuList does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
103
                $product->setSkuInfo($value['id'],$skuList);
104
            }
105
106
            foreach ($skuInfo[0]['vid'] as $vid) {
107
                foreach ($skuInfo[1]['vid'] as $vid1) {
108
                    $product->setSkuList(100, 20, $images, 100, array(array($skuInfo[0]['id'], $vid), array($skuInfo[1]['id'], $vid1)));
0 ignored issues
show
Bug introduced by
The variable $skuInfo does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
Documentation introduced by
array(array($skuInfo[0][...uInfo[1]['id'], $vid1)) is of type array<integer,array<inte...:\"?\",\"1\":\"?\"}>"}>, but the function expects a null.

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...
109
                }
110
            }
111
112
            $product->setAttrext(0,1,1,1)
113
                ->setLocation('浙江省','杭州市','滨江区阿里园')
114
                ->setDeliveryInfo(1,'400184224');
0 ignored issues
show
Documentation introduced by
'400184224' is of type string, but the function expects a null.

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...
115
116
            return $product;
117
118
        },$productId);
119
120
        $this->assertTrue(is_string($response));
121
122
    }
123
124
    /**
125
     * @depends testCreate
126
     */
127
    public function testGet($productId)
128
    {
129
        
130
        $product = new Product($this->http);
131
        $response = $product->get($productId);
132
        $this->assertTrue(is_array($response));
133
    }
134
135
    public function testGetByStatus()
136
    {
137
        
138
        $product = new Product($this->http);
139
        $response = $product->getByStatus();
140
        $this->assertTrue(is_array($response));
141
    }
142
143
    /**
144
     * @depends testCreate
145
     */
146
    public function testUpdateStatus($productId)
147
    {
148
        
149
        $product = new Product($this->http);
150
        $response = $product->updateStatus($productId,0);
151
        $this->assertTrue($response);
152
    }
153
154
    public function testGetSub()
155
    {
156
        
157
        $product = new Product($this->http);
158
        $response = $product->getSub();
159
160
        $this->assertTrue(is_array($response));
161
162
        foreach ($response as $value) {
0 ignored issues
show
Bug introduced by
The expression $response of type boolean|array is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
163
            $this->assertArrayHasKey('id',$value);
164
            $this->assertArrayHasKey('name',$value);
165
        }
166
167
168
        $product = new Product($this->http);
169
        $response = $product->getSub(537891948);
170
171
        $this->assertTrue(is_array($response));
172
173
        foreach ($response as $value) {
0 ignored issues
show
Bug introduced by
The expression $response of type boolean|array is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
174
            $this->assertArrayHasKey('id',$value);
175
            $this->assertArrayHasKey('name',$value);
176
        }
177
178
    }
179
180
181 View Code Duplication
    public function testGetSku()
182
    {
183
        $cateId = '536891949';
184
185
        $product = new Product($this->http);
186
        $response = $product->getSku($cateId);
187
        $this->assertTrue(is_array($response));
188
    }
189
190 View Code Duplication
    public function testGetProperty()
191
    {
192
        $cateId = '536891949';
193
194
        $product = new Product($this->http);
195
        $response = $product->getProperty($cateId);
196
        $this->assertTrue(is_array($response));
197
    }
198
199
    /**
200
     * @depends testCreate
201
     */
202
    public function testDelete($productId)
203
    {
204
205
        $product = new Product($this->http);
206
        $response = $product->delete($productId);
207
        $this->assertTrue($response);
208
    }
209
}
210