Completed
Push — master ( d01ad3...6b97e6 )
by Paweł
21s queued 10s
created

SlideshowItemContext::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9

Duplication

Lines 9
Ratio 100 %

Importance

Changes 0
Metric Value
dl 9
loc 9
rs 9.9666
c 0
b 0
f 0
cc 1
nc 1
nop 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SWP\Behat\Contexts;
6
7
use Behat\Behat\Context\Context;
8
use Behat\Gherkin\Node\TableNode;
9
use SWP\Bundle\ContentBundle\Doctrine\ArticleMediaRepositoryInterface;
10
use SWP\Bundle\ContentBundle\Doctrine\SlideshowRepositoryInterface;
11
use SWP\Bundle\ContentBundle\Model\SlideshowItemInterface;
12
use SWP\Component\Storage\Factory\FactoryInterface;
13
14 View Code Duplication
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