ArrayStopwordAnalyzerTest::testCanConstruct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 0
1
<?php
2
3
namespace Onoi\Tesa\Tests\StopwordAnalyzer;
4
5
use Onoi\Tesa\StopwordAnalyzer\ArrayStopwordAnalyzer;
6
7
/**
8
 * @covers \Onoi\Tesa\StopwordAnalyzer\ArrayStopwordAnalyzer
9
 * @group onoi-tesa
10
 *
11
 * @license GNU GPL v2+
12
 * @since 0.1
13
 *
14
 * @author mwjames
15
 */
16
class ArrayStopwordAnalyzerTest extends \PHPUnit_Framework_TestCase {
17
18
	public function testCanConstruct() {
19
20
		$this->assertInstanceOf(
21
			'\Onoi\Tesa\StopwordAnalyzer\ArrayStopwordAnalyzer',
22
			new ArrayStopwordAnalyzer()
23
		);
24
	}
25
26
	/**
27
	 * @dataProvider stopWordsProvider
28
	 */
29
	public function testIsStopWord( $defaultList, $word, $expected ) {
30
31
		$instance = new ArrayStopwordAnalyzer( $defaultList );
32
33
		$this->assertEquals(
34
			$expected,
35
			$instance->isStopWord( $word )
36
		);
37
	}
38
39
	public function stopWordsProvider() {
40
41
		$defaultList = array( 'Foo', 'かつて', 'bAR' );
42
43
		$provider[] = array(
0 ignored issues
show
Coding Style Comprehensibility introduced by
$provider was never initialized. Although not strictly required by PHP, it is generally a good practice to add $provider = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
44
			$defaultList,
45
			'Foo',
46
			true
47
		);
48
49
		$provider[] = array(
50
			$defaultList,
51
			'かつて',
52
			true
53
		);
54
55
		$provider[] = array(
56
			$defaultList,
57
			'bar',
58
			false
59
		);
60
61
		return $provider;
62
	}
63
64
}
65