Completed
Push — master ( 5ca964...bf9a0c )
by Mikołaj
09:05
created

ResourceRefresher   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
c 1
b 0
f 0
dl 0
loc 17
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A refresh() 0 7 1
A __construct() 0 3 1
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\Refresher;
14
15
use FOS\ElasticaBundle\Persister\ObjectPersisterInterface;
16
use Sylius\Component\Resource\Model\ResourceInterface;
17
use Symfony\Component\DependencyInjection\ContainerInterface;
18
use Webmozart\Assert\Assert;
19
20
final class ResourceRefresher implements ResourceRefresherInterface
21
{
22
    /** @var ContainerInterface */
23
    private $container;
24
25
    public function __construct(ContainerInterface $container)
26
    {
27
        $this->container = $container;
28
    }
29
30
    public function refresh(ResourceInterface $resource, string $objectPersisterId): void
31
    {
32
        /** @var ObjectPersisterInterface $objectPersister */
33
        $objectPersister = $this->container->get($objectPersisterId);
34
        Assert::isInstanceOf($objectPersister, ObjectPersisterInterface::class);
35
36
        $objectPersister->replaceOne($resource);
37
    }
38
}
39