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

SlideshowContext   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 35
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 4
dl 35
loc 35
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 9 9 1
A theFollowingContentLists() 13 13 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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 Doctrine\ORM\EntityManagerInterface;
10
use SWP\Bundle\CoreBundle\Repository\ArticleRepositoryInterface;
11
use SWP\Component\Storage\Factory\FactoryInterface;
12
13 View Code Duplication
final class SlideshowContext extends AbstractContext implements Context
14
{
15
    private $slideshowFactory;
16
17
    private $entityManager;
18
19
    private $articleRepository;
20
21
    public function __construct(
22
        FactoryInterface $slideshowFactory,
23
        EntityManagerInterface $entityManager,
24
        ArticleRepositoryInterface $articleRepository
25
    ) {
26
        $this->slideshowFactory = $slideshowFactory;
27
        $this->entityManager = $entityManager;
28
        $this->articleRepository = $articleRepository;
29
    }
30
31
    /**
32
     * @Given the following Slideshows:
33
     */
34
    public function theFollowingContentLists(TableNode $table)
35
    {
36
        foreach ($table as $row => $columns) {
37
            $slideshow = $this->slideshowFactory->create();
38
39
            $columns['article'] = $this->articleRepository->findOneBy(['title' => $columns['article']]);
40
41
            $this->fillObject($slideshow, $columns);
42
            $this->entityManager->persist($slideshow);
43
        }
44
45
        $this->entityManager->flush();
46
    }
47
}
48