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

OrderProductsListener   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 19
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A updateOrderProducts() 0 5 2
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