StringBlockContext   A
last analyzed

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\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
10 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...
11
{
12
    /**
13
     * @var SharedStorageInterface
14
     */
15
    private $sharedStorage;
16
17
    /**
18
     * @var ExampleFactoryInterface
19
     */
20
    private $stringBlockExampleFactory;
21
22
    /**
23
     * @var ObjectManager
24
     */
25
    private $stringBlockManager;
26
27
    /**
28
     * @param SharedStorageInterface $sharedStorage
29
     * @param ExampleFactoryInterface $stringBlockExampleFactory
30
     * @param ObjectManager $stringBlockManager
31
     */
32
    public function __construct(
33
        SharedStorageInterface $sharedStorage,
34
        ExampleFactoryInterface $stringBlockExampleFactory,
35
        ObjectManager $stringBlockManager
36
    ) {
37
        $this->sharedStorage = $sharedStorage;
38
        $this->stringBlockExampleFactory = $stringBlockExampleFactory;
39
        $this->stringBlockManager = $stringBlockManager;
40
    }
41
42
    /**
43
     * @Given the store has string block :name
44
     */
45
    public function theStoreHasStringBlock($name)
46
    {
47
        $stringBlock = $this->stringBlockExampleFactory->create([
48
            'name' => $name,
49
        ]);
50
51
        $this->stringBlockManager->persist($stringBlock);
52
        $this->stringBlockManager->flush();
53
54
        $this->sharedStorage->set('string_block', $stringBlock);
55
    }
56
57
    /**
58
     * @Given the store has string block :name with body :body
59
     */
60
    public function theStoreHasStringBlockWithBody($name, $body)
61
    {
62
        $stringBlock = $this->stringBlockExampleFactory->create([
63
            'name' => $name,
64
            'body' => $body,
65
        ]);
66
67
        $this->stringBlockManager->persist($stringBlock);
68
        $this->stringBlockManager->flush();
69
70
        $this->sharedStorage->set('string_block', $stringBlock);
71
    }
72
}
73