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

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