Completed
Push — master ( 09c22d...214c5a )
by Damian
08:47 queued 06:04
created

HunSpellProviderTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 35
Duplicated Lines 57.14 %

Coupling/Cohesion

Components 0
Dependencies 2
Metric Value
wmc 3
lcom 0
cbo 2
dl 20
loc 35
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A assertArrayContains() 0 4 1
A testCheckWords() 10 10 1
A testGetSuggestions() 10 10 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
 * Tests the {@see HunSpellProvider} class
5
 */
6
class HunSpellProviderTest extends SapphireTest {
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
7
8
	/**
9
	 * Assert that all needles are in the haystack
10
	 *
11
	 * @param array $needles
12
	 * @param array $haystack
13
	 */
14
	protected function assertArrayContains($needles, $haystack) {
15
		$overlap = array_intersect($needles, $haystack);
16
		$this->assertEquals($overlap, $needles, "Assert that array contains all values specified");
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<HunSpellProviderTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
17
	}
18
19 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...
20
		$provider = new HunSpellProvider();
21
		$result = $provider->checkWords('en_US', array('collor', 'one', 'twoo', 'three'));
22
		$this->assertArrayContains(
23
			array('collor', 'twoo'),
24
			$result
25
		);
26
		$result = $provider->checkWords('en_US', array('basketball'));
27
		$this->assertEmpty($result);
0 ignored issues
show
Bug introduced by
The method assertEmpty() does not seem to exist on object<HunSpellProviderTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
28
	}
29
30 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...
31
		$provider = new HunSpellProvider();
32
		$result = $provider->getSuggestions('en_US', 'collor');
33
		$this->assertArrayContains(
34
			array('color', 'collar', 'coll or', 'coll-or', 'collator'),
35
			$result
36
		);
37
		$result = $provider->getSuggestions('en_US', 'basketball');
38
		$this->assertEmpty($result);
0 ignored issues
show
Bug introduced by
The method assertEmpty() does not seem to exist on object<HunSpellProviderTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
39
	}
40
}
41