DeltaProductReader::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 11
rs 9.4285
cc 1
eloc 8
nc 1
nop 5
1
<?php
2
3
namespace Actualys\Bundle\DrupalCommerceConnectorBundle\Reader\ORM;
4
5
use Pim\Bundle\BaseConnectorBundle\Reader\Doctrine\ObsoleteProductReader as PimProductReader;
6
use Pim\Bundle\BaseConnectorBundle\Reader\Doctrine\Reader;
7
use Akeneo\Bundle\BatchBundle\Entity\StepExecution;
8
use Pim\Bundle\TransformBundle\Converter\MetricConverter;
9
use Pim\Bundle\CatalogBundle\Manager\ChannelManager;
10
use Pim\Bundle\CatalogBundle\Manager\CompletenessManager;
11
use Pim\Bundle\CatalogBundle\Repository\ProductRepositoryInterface;
12
use Pim\Bundle\CatalogBundle\Model\AbstractProduct;
13
use Actualys\Bundle\DrupalCommerceConnectorBundle\Manager\ProductExportManager;
14
15
class DeltaProductReader extends PimProductReader
0 ignored issues
show
Deprecated Code introduced by
The class Pim\Bundle\BaseConnector...e\ObsoleteProductReader has been deprecated with message: , will be removed in 1.4

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...
16
{
17
    protected $productExportManager;
18
19
    /**
20
     * Constructor
21
     *
22
     * @param ProductRepositoryInterface $repository
23
     * @param ChannelManager             $channelManager
24
     * @param CompletenessManager        $completenessManager
25
     * @param MetricConverter            $metricConverter
26
     * @param ProductExportManager       $productExportManager
27
     */
28
    public function __construct(
29
        ProductRepositoryInterface $repository,
30
        ChannelManager $channelManager,
31
        CompletenessManager $completenessManager,
32
        MetricConverter $metricConverter,
33
        ProductExportManager $productExportManager
34
    ) {
35
        parent::__construct($repository, $channelManager, $completenessManager, $metricConverter);
36
37
        $this->productExportManager = $productExportManager;
38
    }
39
40
    /**
41
     * {@inheritdoc}
42
     */
43
    public function read()
44
    {
45
        $product = $this->filterProduct(parent::read());
46
47
        return $product;
48
    }
49
50
    /**
51
     * Filter products and return only products that got updated since the last export
52
     * @param AbstractProduct $readProduct
53
     *
54
     * @return AbstractProduct|null
55
     */
56
    protected function filterProduct(AbstractProduct $readProduct = null)
57
    {
58
        if (null !== $readProduct) {
59
            $filteredProduct = $this->productExportManager->filterProduct($readProduct, $this->jobInstance);
0 ignored issues
show
Bug introduced by
The property jobInstance does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
60
61
            if ($filteredProduct === null) {
62
                return $this->filterProduct(parent::read());
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (read() instead of filterProduct()). Are you sure this is correct? If so, you might want to change this to $this->read().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
63
            } else {
64
                return $filteredProduct;
65
            }
66
        }
67
68
        return null;
69
    }
70
71
    /**
72
     * Update the product export date (will be removed later)
73
     * @param AbstractProduct $product
74
     */
75
    protected function updateProductExport(AbstractProduct $product)
76
    {
77
        $this->productExportManager->updateProductExport($product->getIdentifier(), $this->jobInstance);
78
    }
79
80
    /**
81
     * {@inheritdoc}
82
     */
83
    public function setStepExecution(StepExecution $stepExecution)
84
    {
85
        parent::setStepExecution($stepExecution);
86
87
        $this->jobInstance = $this->stepExecution->getJobExecution()->getJobInstance();
88
    }
89
}
90