Passed
Push — PAC-344-eval-clean-up ( 8c8af6 )
by
unknown
18:58 queued 14:34
created

CleanUpGroupedProductRelationsObserver::process()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 18
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 12
c 1
b 0
f 0
dl 0
loc 18
rs 9.8666
cc 4
nc 3
nop 0
1
<?php
2
/**
3
 * Copyright (c) 2024 TechDivision GmbH
4
 * All rights reserved
5
 *
6
 * This product includes proprietary software developed at TechDivision GmbH, Germany
7
 * For more information see https://www.techdivision.com/
8
 *
9
 * To obtain a valid license for using this software please contact us at
10
 * [email protected]
11
 */
12
declare(strict_types=1);
13
14
namespace TechDivision\Import\Product\Grouped\Observers;
15
16
use Exception;
17
use Magento\GroupedProduct\Model\Product\Type\Grouped;
0 ignored issues
show
Bug introduced by
The type Magento\GroupedProduct\Model\Product\Type\Grouped was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
18
use TechDivision\Import\Observers\StateDetectorInterface;
19
use TechDivision\Import\Product\Grouped\Services\ProductGroupedProcessorInterface;
20
use TechDivision\Import\Product\Grouped\Utils\ColumnKeys;
21
use TechDivision\Import\Product\Grouped\Utils\ConfigurationKeys;
22
use TechDivision\Import\Product\Observers\AbstractProductImportObserver;
23
24
/**
25
 * @copyright Copyright (c) 2024 TechDivision GmbH <[email protected]> - TechDivision GmbH
26
 * @link      https://www.techdivision.com/
27
 * @author    MET <[email protected]>
28
 */
29
class CleanUpGroupedProductRelationsObserver extends AbstractProductImportObserver
30
{
31
    /** @var ProductGroupedProcessorInterface */
32
    protected $productGroupedProcessor;
33
34
    /**
35
     * @param ProductGroupedProcessorInterface $productGroupedProcessor
36
     * @param StateDetectorInterface|null $stateDetector
37
     */
38
    public function __construct(
39
        ProductGroupedProcessorInterface $productGroupedProcessor,
40
        StateDetectorInterface $stateDetector = null
41
    ) {
42
        parent::__construct($stateDetector);
43
        $this->productGroupedProcessor = $productGroupedProcessor;
44
    }
45
46
    /**
47
     * @return void
48
     * @throws Exception
49
     */
50
    protected function process()
51
    {
52
        if ($this->getValue(ColumnKeys::PRODUCT_TYPE) !== Grouped::TYPE_CODE) {
53
            return;
54
        }
55
56
        if ($this->getSubject()->getConfiguration()->hasParam(ConfigurationKeys::CLEAN_UP_GROUPED) &&
57
            $this->getSubject()->getConfiguration()->getParam(ConfigurationKeys::CLEAN_UP_GROUPED)
58
        ) {
59
            $this->cleanUpGrouped();
60
61
            $this->getSubject()
62
                ->getSystemLogger()
63
                ->debug(
64
                    $this->getSubject()->appendExceptionSuffix(
65
                        sprintf(
66
                            'Successfully clean up variants for product with SKU "%s"',
67
                            $this->getValue(ColumnKeys::SKU)
68
                        )
69
                    )
70
                );
71
        }
72
    }
73
74
    /**
75
     * Search for grouped products in the artefacts and check for differences in
76
     * the database. Remove entries in DB that not exist in artefact.
77
     *
78
     * @return void
79
     * @throws Exception Is thrown, if either the grouped children or attributes can not be deleted
80
     */
81
    protected function cleanUpGrouped()
82
    {
83
        // TODO herausfinden wie
84
    }
85
86
    /**
87
     * Return's the PK to create the product => variant relation.
88
     *
89
     * @return int The PK to create the relation with
90
     */
91
    protected function getLastPrimaryKey()
92
    {
93
        return $this->getLastEntityId();
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->getLastEntityId() returns the type string which is incompatible with the documented return type integer.
Loading history...
94
    }
95
96
    /**
97
     * @param int $parentProductId The ID of the parent product
98
     * @param array $childData The array of variants
99
     *
100
     * @return void
101
     * @throws Exception
102
     */
103
    protected function cleanUpGroupedChildren($parentProductId, array $childData)
0 ignored issues
show
Unused Code introduced by
The parameter $parentProductId is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

103
    protected function cleanUpGroupedChildren(/** @scrutinizer ignore-unused */ $parentProductId, array $childData)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
104
    {
105
106
        // we don't want to delete everything
107
        if (empty($childData)) {
108
            return;
109
        }
110
111
        // load the SKU of the parent product
112
        $parentSku = $this->getValue(ColumnKeys::SKU);
0 ignored issues
show
Unused Code introduced by
The assignment to $parentSku is dead and can be removed.
Loading history...
113
114
        // TODO remove the old links
115
    }
116
117
    /**
118
     * Return's the product variant processor instance.
119
     *
120
     * @return ProductGroupedProcessorInterface
121
     */
122
    protected function getProductGroupedProcessor()
123
    {
124
        return $this->productGroupedProcessor;
125
    }
126
}
127