Code Duplication    Length = 24-27 lines in 2 locations

src/Observers/LastEntityIdObserver.php 1 location

@@ 72-98 (lines=27) @@
69
     * @return array The processed row
70
     * @throws \Exception Is thrown, if the product with the SKU can not be loaded
71
     */
72
    protected function process()
73
    {
74
75
        // query whether or not, we've found a new SKU => means we've found a new product
76
        if ($this->isLastSku($sku = $this->getValue(ColumnKeys::SKU))) {
77
            return;
78
        }
79
80
        // set the entity ID for the product with the passed SKU
81
        if ($product = $this->loadProduct($sku)) {
82
            $this->setIds($product);
83
        } else {
84
            // initialize the error message
85
            $message = sprintf('Can\'t load entity ID for product with SKU %s', $sku);
86
            // load the subject
87
            $subject = $this->getSubject();
88
            // query whether or not debug mode has been enabled
89
            if ($subject->isDebugMode()) {
90
                // log a warning, that the product with the given SKU can not be loaded
91
                $subject->getSystemLogger()->warning($subject->appendExceptionSuffix($message));
92
                // skip processing the actual row
93
                $subject->skipRow();
94
            } else {
95
                throw new \Exception($message);
96
            }
97
        }
98
    }
99
100
    /**
101
     * Temporarily persist's the IDs of the passed product.

src/Observers/PreLoadEntityIdObserver.php 1 location

@@ 71-94 (lines=24) @@
68
     * @return array The processed row
69
     * @throws \Exception Is thrown, if the product with the SKU can not be loaded
70
     */
71
    protected function process()
72
    {
73
74
        // query whether or not, we've found a new SKU => means we've found a new product
75
        if ($this->isLastSku($sku = $this->getValue(ColumnKeys::SKU))) {
76
            return;
77
        }
78
79
        // preserve the entity ID for the product with the passed SKU
80
        if ($product = $this->loadProduct($sku)) {
81
            $this->preLoadEntityId($product);
82
        } else {
83
            // initialize the error message
84
            $message = sprintf('Can\'t pre-load product with SKU %s', $sku);
85
            // load the subject
86
            $subject = $this->getSubject();
87
            // query whether or not debug mode has been enabled
88
            if ($subject->isDebugMode()) {
89
                $subject->getSystemLogger()->warning($subject->appendExceptionSuffix($message));
90
            } else {
91
                throw new \Exception($message);
92
            }
93
        }
94
    }
95
96
    /**
97
     * Pre-load the entity ID for the passed product.