Passed
Push — master ( 11d34c...33485b )
by US
13:49 queued 06:53
created

OrderProductsListener::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 4
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file has been created by developers from BitBag.
7
 * Feel free to contact us once you face any issues or want to start
8
 * another great project.
9
 * You can find more information about us on https://bitbag.shop and write us
10
 * an email on [email protected].
11
 */
12
13
namespace BitBag\SyliusElasticsearchPlugin\EventListener;
14
15
use BitBag\SyliusElasticsearchPlugin\Refresher\ResourceRefresherInterface;
16
use Sylius\Component\Core\Model\Order;
17
use Sylius\Component\Core\Model\OrderInterface;
18
use Sylius\Component\Core\Model\OrderItem;
19
use Sylius\Component\Core\Model\OrderItemInterface;
20
21
final class OrderProductsListener
22
{
23
    /** @var ResourceRefresherInterface */
24
    private $resourceRefresher;
25
26
    /** @var string */
27
    private $productPersister;
28
29
    public function __construct(ResourceRefresherInterface $resourceRefresher, string $productPersister)
30
    {
31
        $this->resourceRefresher = $resourceRefresher;
32
        $this->productPersister = $productPersister;
33
    }
34
35
    public function updateOrderProducts(OrderInterface $order): void
36
    {
37
        /** @var OrderItemInterface $orderItem */
38
        foreach ($order->getItems() as $orderItem) {
39
            $this->resourceRefresher->refresh($orderItem->getProduct(), $this->productPersister);
40
        }
41
    }
42
}
43