Product::extract()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 11
ccs 0
cts 10
cp 0
rs 9.4285
cc 1
eloc 8
nc 1
nop 1
crap 2
1
<?php
2
3
namespace SpeckCatalog\Mapper\Hydrator;
4
5
use SpeckCatalog\Model\Product as ProductModel;
6
use Zend\Stdlib\Hydrator\ClassMethods;
7
8
class Product extends ClassMethods
0 ignored issues
show
Deprecated Code introduced by
The class Zend\Stdlib\Hydrator\ClassMethods has been deprecated with message: Use Zend\Hydrator\ClassMethods from zendframework/zend-hydrator instead.

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
9
{
10
    public function extract(ProductModel $product)
11
    {
12
        $data['product_id']      = $product->getProductId();
0 ignored issues
show
Coding Style Comprehensibility introduced by
$data was never initialized. Although not strictly required by PHP, it is generally a good practice to add $data = 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...
13
        $data['name']            = $product->getName();
14
        $data['description']     = $product->getDescription();
15
        $data['product_type_id'] = $product->getProductTypeId();
16
        $data['item_number']     = $product->getItemNumber();
17
        $data['manufacturer_id'] = $product->getManufacturerId();
18
19
        return $data;
20
    }
21
}
22