Completed
Push — master ( 4240ac...17e210 )
by Michał
14s
created

TaxonBlockContext   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 71
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 9 9 1
A theStoreHasTaxonBlock() 9 9 1
A theStoreHasTaxonBlockWithField() 9 9 1
A theStoreHasTaxonBlockWithTaxon() 9 9 1

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
namespace Tests\Lakion\CmsPlugin\Behat\Context\Setup;
4
5
use Behat\Behat\Context\Context;
6
use Doctrine\Common\Persistence\ObjectManager;
7
use Sylius\Behat\Service\SharedStorageInterface;
8
use Sylius\Bundle\CoreBundle\Fixture\Factory\ExampleFactoryInterface;
9
use Sylius\Component\Core\Model\TaxonInterface;
10
11 View Code Duplication
final class TaxonBlockContext implements Context
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
12
{
13
    /**
14
     * @var SharedStorageInterface
15
     */
16
    private $sharedStorage;
17
18
    /**
19
     * @var ExampleFactoryInterface
20
     */
21
    private $taxonBlockExampleFactory;
22
23
    /**
24
     * @var ObjectManager
25
     */
26
    private $taxonBlockManager;
27
28
    /**
29
     * @param SharedStorageInterface $sharedStorage
30
     * @param ExampleFactoryInterface $taxonBlockExampleFactory
31
     * @param ObjectManager $taxonBlockManager
32
     */
33
    public function __construct(
34
        SharedStorageInterface $sharedStorage,
35
        ExampleFactoryInterface $taxonBlockExampleFactory,
36
        ObjectManager $taxonBlockManager
37
    ) {
38
        $this->sharedStorage = $sharedStorage;
39
        $this->taxonBlockExampleFactory = $taxonBlockExampleFactory;
40
        $this->taxonBlockManager = $taxonBlockManager;
41
    }
42
43
    /**
44
     * @Given the store has taxon block :name
45
     */
46
    public function theStoreHasTaxonBlock($name)
47
    {
48
        $taxonBlock = $this->taxonBlockExampleFactory->create(['name' => $name]);
49
50
        $this->taxonBlockManager->persist($taxonBlock);
51
        $this->taxonBlockManager->flush();
52
53
        $this->sharedStorage->set('taxon_block', $taxonBlock);
54
    }
55
56
    /**
57
     * @Given /^the store has taxon block "([^"]+)" with (body|title|link) "([^"]+)"$/
58
     */
59
    public function theStoreHasTaxonBlockWithField($name, $field, $value)
60
    {
61
        $taxonBlock = $this->taxonBlockExampleFactory->create(['name' => $name, $field => $value]);
62
63
        $this->taxonBlockManager->persist($taxonBlock);
64
        $this->taxonBlockManager->flush();
65
66
        $this->sharedStorage->set('taxon_block', $taxonBlock);
67
    }
68
69
    /**
70
     * @Given /^the store has taxon block "([^"]+)" with (taxon "[^"]+")$/
71
     */
72
    public function theStoreHasTaxonBlockWithTaxon($name, TaxonInterface $taxon)
73
    {
74
        $taxonBlock = $this->taxonBlockExampleFactory->create(['name' => $name, 'taxon' => $taxon]);
75
76
        $this->taxonBlockManager->persist($taxonBlock);
77
        $this->taxonBlockManager->flush();
78
79
        $this->sharedStorage->set('taxon_block', $taxonBlock);
80
    }
81
}
82