AttachmentPanel::modifyMeta()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 17
rs 9.7
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
declare(strict_types = 1);
4
5
/**
6
 * File: AttachmentPanel.php
7
 *
8
 * @author Bartosz Kubicki [email protected]>
9
 * @copyright Copyright (C) 2018 Lizard Media (http://lizardmedia.pl)
10
 */
11
12
namespace LizardMedia\ProductAttachment\Ui\DataProvider\Product\Form\Modifier;
13
14
use Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\AbstractModifier;
15
use Magento\Framework\Stdlib\ArrayManager;
16
use Magento\Ui\Component\Form;
17
18
/**
19
 * Class AttachmentPanel
20
 * @package LizardMedia\ProductAttachment\Ui\DataProvider\Product\Form\Modifier
21
 */
22
class AttachmentPanel extends AbstractModifier
23
{
24
    /**
25
     * @var ArrayManager
26
     */
27
    private $arrayManager;
28
29
    /**
30
     * @var array
31
     */
32
    private $meta = [];
33
34
    /**
35
     * @param ArrayManager $arrayManager
36
     */
37
    public function __construct(ArrayManager $arrayManager)
38
    {
39
        $this->arrayManager = $arrayManager;
40
    }
41
42
    /**
43
     * @param array $data
44
     * @return array $data
45
     */
46
    public function modifyData(array $data) : array
47
    {
48
        return $data;
49
    }
50
51
    /**
52
     * @param array $meta
53
     * @return array $meta
54
     */
55
    public function modifyMeta(array $meta) : array
56
    {
57
        $this->meta = $meta;
58
59
        $panelConfig['arguments']['data']['config'] = [
0 ignored issues
show
Coding Style Comprehensibility introduced by
$panelConfig was never initialized. Although not strictly required by PHP, it is generally a good practice to add $panelConfig = 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...
60
            'componentType' => Form\Fieldset::NAME,
61
            'label' => __('Product attachments'),
62
            'collapsible' => true,
63
            'opened' => true,
64
            'sortOrder' => '900',
65
            'dataScope' => 'data'
66
        ];
67
68
        $this->meta = $this->arrayManager->set('product_attachment', $this->meta, $panelConfig);
69
70
        return $this->meta;
71
    }
72
}
73