Completed
Pull Request — master (#94)
by
unknown
06:01
created

ResourceRefresher   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A refresh() 0 7 1
A __construct() 0 3 1
A remove() 0 7 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
    public function remove(ResourceInterface $resource, string $objectPersisterId): void
40
    {
41
        /** @var ObjectPersisterInterface $objectPersister */
42
        $objectPersister = $this->container->get($objectPersisterId);
43
        Assert::isInstanceOf($objectPersister, ObjectPersisterInterface::class);
44
45
        $objectPersister->deleteOne($resource);
46
    }
47
}
48