Code Duplication    Length = 40-43 lines in 2 locations

src/Factory/DocumentFactory.php 1 location

@@ 8-47 (lines=40) @@
5
use Doctrine\ODM\PHPCR\DocumentManagerInterface;
6
use Sylius\Component\Resource\Factory\FactoryInterface;
7
8
final class DocumentFactory implements FactoryInterface
9
{
10
    /**
11
     * @var FactoryInterface
12
     */
13
    private $decoratedFactory;
14
15
    /**
16
     * @var DocumentManagerInterface
17
     */
18
    private $documentManager;
19
20
    /**
21
     * @var string
22
     */
23
    private $parentPath;
24
25
    /**
26
     * @param FactoryInterface $decoratedFactory
27
     * @param DocumentManagerInterface $documentManager
28
     * @param string $parentPath
29
     */
30
    public function __construct(FactoryInterface $decoratedFactory, DocumentManagerInterface $documentManager, $parentPath)
31
    {
32
        $this->decoratedFactory = $decoratedFactory;
33
        $this->documentManager = $documentManager;
34
        $this->parentPath = $parentPath;
35
    }
36
37
    /**
38
     * {@inheritdoc}
39
     */
40
    public function createNew()
41
    {
42
        $document = $this->decoratedFactory->createNew();
43
        $document->setParentDocument($this->documentManager->find(null, $this->parentPath));
44
45
        return $document;
46
    }
47
}
48

src/Factory/RouteFactory.php 1 location

@@ 11-53 (lines=43) @@
8
use Sylius\Component\Resource\Factory\FactoryInterface;
9
use Webmozart\Assert\Assert;
10
11
final class RouteFactory implements FactoryInterface
12
{
13
    /**
14
     * @var FactoryInterface
15
     */
16
    private $decoratedFactory;
17
18
    /**
19
     * @var DocumentManagerInterface
20
     */
21
    private $documentManager;
22
23
    /**
24
     * @var string
25
     */
26
    private $routeParentPath;
27
28
    /**
29
     * @param FactoryInterface $decoratedFactory
30
     * @param DocumentManagerInterface $documentManager
31
     * @param array $routeParentsPaths
32
     */
33
    public function __construct(FactoryInterface $decoratedFactory, DocumentManagerInterface $documentManager, array $routeParentsPaths)
34
    {
35
        $this->decoratedFactory = $decoratedFactory;
36
        $this->documentManager = $documentManager;
37
38
        Assert::notEmpty($routeParentsPaths);
39
        $this->routeParentPath = current($routeParentsPaths);
40
    }
41
42
    /**
43
     * {@inheritdoc}
44
     */
45
    public function createNew()
46
    {
47
        /** @var Route $route */
48
        $route = $this->decoratedFactory->createNew();
49
        $route->setParentDocument($this->documentManager->find(null, $this->routeParentPath));
50
51
        return $route;
52
    }
53
}
54