Failed Conditions
Branch master (215e8c)
by Johannes
04:26
created

TopicsTest   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 77
Duplicated Lines 36.36 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 28
loc 77
rs 10
c 0
b 0
f 0
wmc 11
lcom 1
cbo 1

11 Methods

Rating   Name   Duplication   Size   Complexity  
A getDataSet() 0 4 1
A fetch_topics_page() 0 4 1
A fetch_topic_page() 0 4 1
A testTopicsPage() 0 6 1
A testTopicsOnFrontPage() 0 5 1
A testTopicPage() 8 8 1
A testTopicPageWithSearch() 6 6 1
A testTopicPageWithMP() 8 8 1
A testTopicPageWithMPAndPolicy() 6 6 1
A testTopicPageRecentVotes() 0 5 1
A testTopicPageContent() 0 4 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
/**
4
 * Provides test methods for topics functionality.
5
 */
6
class TopicsTest extends FetchPageTestCase
7
{
8
9
    /**
10
     * Loads the topics testing fixture.
11
     */
12
    public function getDataSet()
13
    {
14
        return $this->createMySQLXMLDataSet(dirname(__FILE__).'/_fixtures/topics.xml');
15
    }
16
17
    private function fetch_topics_page($vars)
18
    {
19
        return $this->base_fetch_page($vars, 'topic', 'index.php', '/topic/index.php');
20
    }
21
22
    private function fetch_topic_page($vars)
23
    {
24
        return $this->base_fetch_page($vars, 'topic', 'topic.php', '/topic/topic.php');
25
    }
26
27
    public function testTopicsPage() {
28
        $page = $this->fetch_topics_page(array('url' => '/topic/'));
29
        $this->assertContains('Topics', $page);
30
        $this->assertContains('NHS', $page);
31
        $this->assertContains('Welfare', $page);
32
    }
33
34
    public function testTopicsOnFrontPage() {
35
        return $this->base_fetch_page(array('url' => '/'), '/');
36
        $this->assertContains('NHS', $page);
0 ignored issues
show
Unused Code introduced by
$this->assertContains('NHS', $page); does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
37
        $this->assertNotContains('Welfare', $page);
38
    }
39
40 View Code Duplication
    public function testTopicPage() {
41
        $page = $this->fetch_topic_page(array('topic' => 'nhs', 'url' => '/topic/nhs'));
42
        $this->assertContains('NHS', $page);
43
        $this->assertNotContains('Welfare', $page);
44
        $this->assertContains('Test Hansard Section', $page);
45
        $this->assertNotContains('foundation hospitals', $page);
46
        $this->assertNotContains('Sign up for email alerts', $page);
47
    }
48
49 View Code Duplication
    public function testTopicPageWithSearch() {
50
        $page = $this->fetch_topic_page(array('topic' => 'welfare', 'url' => '/topic/welfare'));
51
        $this->assertContains('Welfare', $page);
52
        $this->assertNotContains('NHS', $page);
53
        $this->assertNotContains('Test Hansard Section', $page);
54
    }
55
56 View Code Duplication
    public function testTopicPageWithMP() {
57
        $page = $this->fetch_topic_page(array('pc' => 'SW1 1AA', 'topic' => 'nhs', 'url' => '/topic/nhs'));
58
        $this->assertContains('NHS', $page);
59
        $this->assertNotContains('Welfare', $page);
60
        $this->assertContains('Test Current-MP', $page);
61
        $this->assertContains('Test Hansard Section', $page);
62
        $this->assertContains('foundation hospitals', $page);
63
    }
64
65 View Code Duplication
    public function testTopicPageWithMPAndPolicy() {
66
        $page = $this->fetch_topic_page(array('pc' => 'SW1 1AA', 'topic' => 'welfare', 'url' => '/topic/welfare'));
67
        $this->assertContains('Welfare', $page);
68
        $this->assertContains('Test Current-MP', $page);
69
        $this->assertContains('foundation hospitals', $page);
70
    }
71
72
    public function testTopicPageRecentVotes() {
73
        $page = $this->fetch_topic_page(array('topic' => 'nhs', 'url' => '/topic/nhs'));
74
        $this->assertContains('pw-2013-01-01-1-commons">', $page);
75
        $this->assertContains('The majority of MPs  voted Agreed', $page);
76
    }
77
78
    public function testTopicPageContent() {
79
        $page = $this->fetch_topic_page(array('topic' => 'nhs', 'url' => '/topic/nhs'));
80
        $this->assertContains('Test Hansard Section', $page);
81
    }
82
}
83