Completed
Push — master ( a13c2f...df1c7f )
by Kamil
9s
created

StringBlockContext   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 63
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 9 9 1
A theStoreHasStringBlock() 11 11 1
A theStoreHasStringBlockWithBody() 12 12 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\SyliusCmsBundle\Behat\Context\Setup;
4
5
use Behat\Behat\Context\Context;
6
use Doctrine\Common\Persistence\ObjectManager;
7
use Lakion\SyliusCmsBundle\Document\StringBlock;
8
use Sylius\Behat\Service\SharedStorageInterface;
9
use Sylius\Bundle\CoreBundle\Fixture\Factory\ExampleFactoryInterface;
10
use Sylius\Component\Resource\Factory\FactoryInterface;
11
12 View Code Duplication
final class StringBlockContext 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...
13
{
14
    /**
15
     * @var SharedStorageInterface
16
     */
17
    private $sharedStorage;
18
19
    /**
20
     * @var ExampleFactoryInterface
21
     */
22
    private $stringBlockExampleFactory;
23
24
    /**
25
     * @var ObjectManager
26
     */
27
    private $stringBlockManager;
28
29
    /**
30
     * @param SharedStorageInterface $sharedStorage
31
     * @param ExampleFactoryInterface $stringBlockExampleFactory
32
     * @param ObjectManager $stringBlockManager
33
     */
34
    public function __construct(
35
        SharedStorageInterface $sharedStorage,
36
        ExampleFactoryInterface $stringBlockExampleFactory,
37
        ObjectManager $stringBlockManager
38
    ) {
39
        $this->sharedStorage = $sharedStorage;
40
        $this->stringBlockExampleFactory = $stringBlockExampleFactory;
41
        $this->stringBlockManager = $stringBlockManager;
42
    }
43
44
    /**
45
     * @Given the store has string block :name
46
     */
47
    public function theStoreHasStringBlock($name)
48
    {
49
        $stringBlock = $this->stringBlockExampleFactory->create([
50
            'name' => $name,
51
        ]);
52
53
        $this->stringBlockManager->persist($stringBlock);
54
        $this->stringBlockManager->flush();
55
56
        $this->sharedStorage->set('string_block', $stringBlock);
57
    }
58
59
    /**
60
     * @Given the store has string block :name with body :body
61
     */
62
    public function theStoreHasStringBlockWithBody($name, $body)
63
    {
64
        $stringBlock = $this->stringBlockExampleFactory->create([
65
            'name' => $name,
66
            'body' => $body,
67
        ]);
68
69
        $this->stringBlockManager->persist($stringBlock);
70
        $this->stringBlockManager->flush();
71
72
        $this->sharedStorage->set('string_block', $stringBlock);
73
    }
74
}
75