Code Duplication    Length = 41-47 lines in 2 locations

src/Component/Translation/Repository/Doctrine/MongoDB/TranslatableRepositoryFactory.php 1 location

@@ 24-70 (lines=47) @@
21
/**
22
 * @author GeLo <[email protected]>
23
 */
24
class TranslatableRepositoryFactory extends RepositoryFactory
25
{
26
    /**
27
     * @var ContainerInterface
28
     */
29
    private $container;
30
31
    /**
32
     * @param ContainerInterface $container
33
     */
34
    public function __construct(ContainerInterface $container)
35
    {
36
        parent::__construct($container->get('lug.resource.registry'));
37
38
        $this->container = $container;
39
    }
40
41
    /**
42
     * {@inheritdoc}
43
     */
44
    protected function createResourceRepository(
45
        $class,
46
        DocumentManager $documentManager,
47
        ClassMetadata $metadata,
48
        ResourceInterface $resource = null
49
    ) {
50
        if ($resource !== null && is_a($class, TranslatableRepository::class, true)) {
51
            return new $class(
52
                $documentManager,
53
                $documentManager->getUnitOfWork(),
54
                $metadata,
55
                $resource,
56
                $this->getLocaleContext()
57
            );
58
        }
59
60
        return parent::createResourceRepository($class, $documentManager, $metadata, $resource);
61
    }
62
63
    /**
64
     * @return LocaleContextInterface
65
     */
66
    private function getLocaleContext()
67
    {
68
        return $this->container->get('lug.translation.context.locale');
69
    }
70
}
71

src/Component/Translation/Repository/Doctrine/ORM/TranslatableRepositoryFactory.php 1 location

@@ 24-64 (lines=41) @@
21
/**
22
 * @author GeLo <[email protected]>
23
 */
24
class TranslatableRepositoryFactory extends RepositoryFactory
25
{
26
    /**
27
     * @var ContainerInterface
28
     */
29
    private $container;
30
31
    /**
32
     * @param ContainerInterface $container
33
     */
34
    public function __construct(ContainerInterface $container)
35
    {
36
        parent::__construct($container->get('lug.resource.registry'));
37
38
        $this->container = $container;
39
    }
40
41
    /**
42
     * {@inheritdoc}
43
     */
44
    protected function createResourceRepository(
45
        $class,
46
        EntityManagerInterface $entityManager,
47
        ClassMetadata $metadata,
48
        ResourceInterface $resource = null
49
    ) {
50
        if ($resource !== null && is_a($class, TranslatableRepository::class, true)) {
51
            return new $class($entityManager, $metadata, $resource, $this->getLocaleContext());
52
        }
53
54
        return parent::createResourceRepository($class, $entityManager, $metadata, $resource);
55
    }
56
57
    /**
58
     * @return LocaleContextInterface
59
     */
60
    private function getLocaleContext()
61
    {
62
        return $this->container->get('lug.translation.context.locale');
63
    }
64
}
65