BundleSelectionsIterator   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
c 1
b 0
f 0
lcom 1
cbo 0
dl 0
loc 37
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setBundleProducts() 0 4 1
A traverse() 0 9 4
A apply() 0 7 1
1
<?php
2
3
namespace Magefix\Fixture\Builder\Helper;
4
5
/**
6
 * Class BundleSelectionsIterator
7
 * @package Magefix\Fixture\Builder\Helper
8
 * @author  Carlo Tasca <[email protected]>
9
 */
10
class BundleSelectionsIterator extends \ArrayIterator
11
{
12
    private $_bundleProducts = [];
13
14
    /**
15
     * @param array $bundleProducts
16
     */
17
    public function setBundleProducts($bundleProducts)
18
    {
19
        $this->_bundleProducts = $bundleProducts;
20
    }
21
22
23
24
    public function apply()
25
    {
26
        $data = $this->getArrayCopy();
27
        array_walk_recursive($data, [$this, 'traverse']);
28
29
        return $data;
30
    }
31
32
    /**
33
     * array_walk_recursive callback
34
     *
35
     * @param $value
36
     */
37
    public function traverse(&$value, $index)
38
    {
39
        if ($index == 'product_id') {
40
            $productId = trim($value, '#');
41
            if (is_numeric($productId) && isset($this->_bundleProducts[$productId])) {
42
                $value = $this->_bundleProducts[$productId]->getId();
43
            }
44
        }
45
    }
46
}
47