Code Duplication    Length = 38-38 lines in 2 locations

src/SWP/Behat/Contexts/ContentListItemContext.php 1 location

@@ 14-51 (lines=38) @@
11
use SWP\Component\ContentList\Repository\ContentListRepositoryInterface;
12
use SWP\Component\Storage\Factory\FactoryInterface;
13
14
final class ContentListItemContext extends AbstractContext implements Context
15
{
16
    private $contentListItemFactory;
17
18
    private $contentListRepository;
19
20
    private $articleRepository;
21
22
    public function __construct(
23
        FactoryInterface $contentListItemFactory,
24
        ContentListRepositoryInterface $contentListRepository,
25
        ArticleRepositoryInterface $articleRepository
26
    ) {
27
        $this->contentListItemFactory = $contentListItemFactory;
28
        $this->contentListRepository = $contentListRepository;
29
        $this->articleRepository = $articleRepository;
30
    }
31
32
    /**
33
     * @Given the following Content List Items:
34
     */
35
    public function theFollowingContentListItems(TableNode $table)
36
    {
37
        foreach ($table as $row => $columns) {
38
            /** @var ContentListItemInterface $contentListItem */
39
            $contentListItem = $this->contentListItemFactory->create();
40
            $contentListItem->setPosition(0);
41
42
            $columns['content_list'] = $this->contentListRepository->findOneBy(['name' => $columns['content_list']]);
43
            $columns['content'] = $this->articleRepository->findOneBy(['title' => $columns['article']]);
44
            unset($columns['article']);
45
46
            $this->fillObject($contentListItem, $columns);
47
            $this->contentListRepository->persist($contentListItem);
48
            $this->contentListRepository->flush();
49
        }
50
    }
51
}
52

src/SWP/Behat/Contexts/SlideshowItemContext.php 1 location

@@ 14-51 (lines=38) @@
11
use SWP\Bundle\ContentBundle\Model\SlideshowItemInterface;
12
use SWP\Component\Storage\Factory\FactoryInterface;
13
14
final class SlideshowItemContext extends AbstractContext implements Context
15
{
16
    private $slideshowItemFactory;
17
18
    private $slideshowRepository;
19
20
    private $articleMediaRepository;
21
22
    public function __construct(
23
        FactoryInterface $slideshowItemFactory,
24
        SlideshowRepositoryInterface $slideshowRepository,
25
        ArticleMediaRepositoryInterface $articleRepository
26
    ) {
27
        $this->slideshowItemFactory = $slideshowItemFactory;
28
        $this->slideshowRepository = $slideshowRepository;
29
        $this->articleMediaRepository = $articleRepository;
30
    }
31
32
    /**
33
     * @Given the following Slideshow Items:
34
     */
35
    public function theFollowingSlideshowItems(TableNode $table)
36
    {
37
        foreach ($table as $row => $columns) {
38
            /** @var SlideshowItemInterface $slideshowItem */
39
            $slideshowItem = $this->slideshowItemFactory->create();
40
            $slideshow = $this->slideshowRepository->findOneBy(['code' => $columns['slideshow']]);
41
            $columns['article_media'] = $this->articleMediaRepository->findOneBy(['key' => $columns['media']]);
42
            unset($columns['slideshow'], $columns['media']);
43
44
            $this->fillObject($slideshowItem, $columns);
45
46
            $slideshow->addItem($slideshowItem);
47
        }
48
49
        $this->slideshowRepository->flush();
50
    }
51
}
52