HunSpellProviderTest   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 39
Duplicated Lines 56.41 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A assertArrayContains() 0 5 1
A testCheckWords() 11 11 1
A testGetSuggestions() 11 11 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\SpellCheck\Tests;
4
5
use SilverStripe\SpellCheck\Providers\HunSpellProvider;
6
use SilverStripe\Dev\SapphireTest;
7
8
/**
9
 * Tests the {@see HunSpellProvider} class
10
 */
11
class HunSpellProviderTest extends SapphireTest
12
{
13
14
    /**
15
     * Assert that all needles are in the haystack
16
     *
17
     * @param array $needles
18
     * @param array $haystack
19
     */
20
    protected function assertArrayContains($needles, $haystack)
21
    {
22
        $overlap = array_intersect($needles, $haystack);
23
        $this->assertEquals($overlap, $needles, "Assert that array contains all values specified");
24
    }
25
26 View Code Duplication
    public function testCheckWords()
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...
27
    {
28
        $provider = new HunSpellProvider();
29
        $result = $provider->checkWords('en_US', array('collor', 'one', 'twoo', 'three'));
30
        $this->assertArrayContains(
31
            array('collor', 'twoo'),
32
            $result
33
        );
34
        $result = $provider->checkWords('en_US', array('basketball'));
35
        $this->assertEmpty($result);
36
    }
37
38 View Code Duplication
    public function testGetSuggestions()
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...
39
    {
40
        $provider = new HunSpellProvider();
41
        $result = $provider->getSuggestions('en_US', 'collor');
42
        $this->assertArrayContains(
43
            array('color', 'collar', 'coll or', 'coll-or', 'collator'),
44
            $result
45
        );
46
        $result = $provider->getSuggestions('en_US', 'basketball');
47
        $this->assertEmpty($result);
48
    }
49
}
50