Completed
Pull Request — master (#307)
by Damian
01:45
created

FixtureContext   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 32
Duplicated Lines 50 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 1
dl 16
loc 32
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A stepISelectGalleryItem() 9 9 1
A iShouldSeeTheForm() 7 7 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 SilverStripe\AssetAdmin\Tests\Behat\Context;
4
5
use Behat\Behat\Exception\PendingException;
6
use SilverStripe\BehatExtension\Context\FixtureContext as BaseFixtureContext;
7
8
/**
9
 * Context used to create fixtures in the SilverStripe ORM.
10
 */
11
class FixtureContext extends BaseFixtureContext
12
{
13
14
    /**
15
     * Select a gallery item by type and name
16
     *
17
     * @Given /^I (?:(?:click on)|(?:select)) the "([^"]+)" named "([^"]+)" in the gallery$/
18
     * @param string $type
19
     * @param string $name
20
     */
21 View Code Duplication
    public function stepISelectGalleryItem($type, $name) {
0 ignored issues
show
Duplication introduced by
This method 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...
22
        $page = $this->getSession()->getPage();
23
        $gallery = $page->find(
24
            'xpath',
25
            "//div[contains(@class, 'gallery-item--{$type}')]//div[contains(text(), '{$name}')]"
26
        );
27
        assertNotNull($gallery, ucfirst($type) . " named $name could not be found");
28
        $gallery->click();
29
    }
30
31
    /**
32
     * @Then /^I should see the "([^"]*)" form$/
33
     * @param string $id HTML ID of form
34
     */
35 View Code Duplication
    public function iShouldSeeTheForm($id)
0 ignored issues
show
Duplication introduced by
This method 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...
36
    {
37
        $page = $this->getSession()->getPage();
38
        $form = $page->find('css', "form#{$id}");
39
        assertNotNull($form, "form with id $id could not be found");
40
        assertTrue($form->isVisible(), "form with id $id is not visible");
41
    }
42
}
43