Completed
Pull Request — master (#7)
by Rafael
03:49
created

Stock::assign()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 12
rs 9.4286
cc 2
eloc 7
nc 2
nop 1
1
<?php
2
3
namespace Iris\Mapping;
4
5
class Stock extends Base
6
{
7
    /**
8
     * {@inheritdoc}
9
     */
10
    public function assign(array $externalData)
11
    {
12
        $stockCollection = new \Iris\Transfer\Catalog\StockCollection;
0 ignored issues
show
Unused Code introduced by
$stockCollection 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...
13
        foreach ($externalData as $s) {
14
            $stock = new \Iris\Transfer\Catalog\Stock([
0 ignored issues
show
Unused Code introduced by
$stock 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...
15
                'sku'      => $s['sku'],
16
                'quantity' => $s['quantity']
17
            ]);
18
        }
19
20
        return $price;
0 ignored issues
show
Bug introduced by
The variable $price does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
21
    }
22
23
    /**
24
     * {@inheritdoc}
25
     */
26
    public function map($internalData)
27
    {
28
        $externalData = array();
29
30
        foreach ($internalData->getItemCollection() as $stock) {
31
            $externalData[] = [
32
                'sku'   => $stock->getSku(),
33
                'quantity' => $stock->getQuantity(),
34
            ];  
35
        }
36
37
        return $externalData;
38
    }
39
}
40