Completed
Pull Request — master (#94)
by
unknown
05:41
created

ResourceRefresher::remove()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 2
dl 0
loc 7
rs 10
c 0
b 0
f 0
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