Completed
Push — dev2 ( aa5ccf...7e2fa1 )
by Gordon
03:08
created

testMoreLikeThisSinglePhoto()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 43
Code Lines 27

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 43
rs 8.8571
cc 2
eloc 27
nc 2
nop 0
1
<?php
2
use SilverStripe\Elastica\ElasticSearcher;
3
use Elastica\Type;
4
class ElasticSearcherUnitTest extends ElasticsearchBaseTest {
5
	public static $fixture_file = 'elastica/tests/lotsOfPhotos.yml';
6
7
	public static $ignoreFixtureFileFor = array('testResultsForEmptySearch');
8
9
	public function setUp() {
10
		parent::setUp();
11
	}
12
13
	public function tearDown() {
14
		parent::tearDown();
15
	}
16
17
18
	public function testSuggested() {
19
		$es = new ElasticSearcher();
20
		$locale = \i18n::default_locale();
21
		$es->setLocale($locale);
22
		$es->setClasses('FlickrPhotoTO');
23
		$fields = array('Description' => 1,'Title' => 1);
0 ignored issues
show
Unused Code introduced by
$fields is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
24
		$this->assertEquals('New Zealand', $es->getSuggestedQuery());
25
	}
26
27
28
	public function testResultsForEmptySearch() {
29
		$es = new ElasticSearcher();
30
31
		$es->hideResultsForEmptySearch();
32
		$this->assertFalse($es->getShowResultsForEmptySearch());
33
34
		$es->showResultsForEmptySearch();
35
		$this->assertTrue($es->getShowResultsForEmptySearch());
36
	}
37
38
39
	public function testMoreLikeThisSinglePhoto() {
40
		$fp = $this->objFromFixture('FlickrPhotoTO', 'photo0076');
41
42
		echo "FP: Original title: {$fp->Title}\n";
43
		$es = new ElasticSearcher();
44
		$locale = \i18n::default_locale();
45
		$es->setLocale($locale);
46
		$es->setClasses('FlickrPhotoTO');
47
48
		$fields = array('Description.standard' => 1,'Title.standard' => 1);
49
		$results = $es->moreLikeThis($fp, $fields, true);
0 ignored issues
show
Documentation introduced by
$fp is of type object<DataObject>, but the function expects a object<SilverStripe\Elastica\DataObject>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
50
51
		echo "RESULTS:\n";
52
		foreach ($results as $result) {
53
			echo "-\t{$result->Title}\n";
54
		}
55
56
		$terms = $results->getList()->MoreLikeThisTerms;
0 ignored issues
show
Bug introduced by
Accessing MoreLikeThisTerms on the interface SS_List suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
57
58
		$fieldNamesReturned = array_keys($terms);
59
		$fieldNames = array_keys($fields);
60
		sort($fieldNames);
61
		sort($fieldNamesReturned);
62
63
		$this->assertEquals($fieldNames, $fieldNamesReturned);
64
65
		//FIXME - this seems anomolyous, check in more detail
66
		$expected = array('texas');
67
		$this->assertEquals($expected, $terms['Title.standard']);
68
69
		$expected = array('collection', 'company', 'degolyer', 'everett', 'file', 'high',
70
			'information', 'new', 'orleans', 'pacific', 'photographs', 'railroad', 'resolution',
71
			'see', 'southern', 'texas', 'view');
72
73
74
75
		$actual = $terms['Description.standard'];
76
		sort($expected);
77
		sort($actual);
78
79
80
		$this->assertEquals($expected, $actual);
81
	}
82
83
84
85 View Code Duplication
	public function testSimilarNoWeighting() {
1 ignored issue
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...
86
		$fp = $this->objFromFixture('FlickrPhotoTO', 'photo0076');
87
		$es = new ElasticSearcher();
88
		$es->setClasses('FlickrPhotoTO');
89
		$fields = array('Title.standard', 'Description.standard');
90
		try {
91
			$paginated = $es->moreLikeThis($fp, $fields, true);
0 ignored issues
show
Documentation introduced by
$fp is of type object<DataObject>|null, but the function expects a object<SilverStripe\Elastica\DataObject>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Unused Code introduced by
$paginated is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
92
			$this->fail('Query has no weight and thus should have failed');
1 ignored issue
show
Bug introduced by
The method fail() does not seem to exist on object<ElasticSearcherUnitTest>.

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...
93
		} catch (InvalidArgumentException $e) {
94
			$this->assertEquals('Fields must be of the form fieldname => weight', $e->getMessage());
95
		}
96
	}
97
98
99 View Code Duplication
	public function testSimilarWeightingNotNumeric() {
1 ignored issue
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...
100
		$fp = $this->objFromFixture('FlickrPhotoTO', 'photo0076');
101
		$es = new ElasticSearcher();
102
		$es->setClasses('FlickrPhotoTO');
103
		$fields = array('Title.standard' => 4, 'Description.standard' => 'not numeric');
104
		try {
105
			$paginated = $es->moreLikeThis($fp, $fields, true);
0 ignored issues
show
Documentation introduced by
$fp is of type object<DataObject>|null, but the function expects a object<SilverStripe\Elastica\DataObject>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Unused Code introduced by
$paginated is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
106
			$this->fail('Query has non numeric weight and thus should have failed');
1 ignored issue
show
Bug introduced by
The method fail() does not seem to exist on object<ElasticSearcherUnitTest>.

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...
107
		} catch (InvalidArgumentException $e) {
108
			$this->assertEquals('Fields must be of the form fieldname => weight', $e->getMessage());
109
		}
110
	}
111
112
113 View Code Duplication
	public function testSimilarToNonSearchable() {
1 ignored issue
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...
114
		$m = Member::get()->first(); // this is not by default Searchable
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $m. Configured minimum length is 2.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
115
		$es = new ElasticSearcher();
116
		$es->setClasses('FlickrPhotoTO');
117
		$fields = array('Title.standard' => 4, 'Description.standard' => 2);
118
		try {
119
			$paginated = $es->moreLikeThis($m, $fields, true);
0 ignored issues
show
Documentation introduced by
$m is of type object<DataObject>|null, but the function expects a object<SilverStripe\Elastica\DataObject>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Unused Code introduced by
$paginated is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
120
			$this->fail('Querying for a non searchable object, thus should have failed');
1 ignored issue
show
Bug introduced by
The method fail() does not seem to exist on object<ElasticSearcherUnitTest>.

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...
121
		} catch (InvalidArgumentException $e) {
122
			$this->assertEquals('Objects of class Member are not searchable', $e->getMessage());
123
		}
124
	}
125
126 View Code Duplication
	public function testSimilarGood() {
1 ignored issue
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...
127
		$fp = $this->objFromFixture('FlickrPhotoTO', 'photo0076');
128
		$es = new ElasticSearcher();
129
		$es->setClasses('FlickrPhotoTO');
130
		$fields = array('Title.standard' => 1, 'Description.standard' => 1);
131
		$paginated = $es->moreLikeThis($fp, $fields, true);
0 ignored issues
show
Documentation introduced by
$fp is of type object<DataObject>|null, but the function expects a object<SilverStripe\Elastica\DataObject>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
132
		foreach ($paginated->getList() as $result) {
133
			echo $result->ID. ' : '.$result->Title."\n";
134
		}
135
		$this->assertEquals(32, $paginated->getTotalItems());
136
		$results = $paginated->getList()->toArray();
137
		$this->assertEquals("[Texas and New Orleans, Southern Pacific Railroad Station, Stockdale, Texas]", $results[0]->Title);
138
		$this->assertEquals("[Texas and New Orleans, Southern Pacific Railroad Station, Taft, Texas]", $results[1]->Title);
139
		$this->assertEquals("[Texas and New Orleans, Southern Pacific Railroad Station, Sierra Blanca, Texas]", $results[2]->Title);
140
		$this->assertEquals("[Texas and New Orleans, Southern Pacific Freight Station, Waxahachie, Texas]", $results[3]->Title);
141
		$this->assertEquals("[Texas and New Orleans, Southern Pacific Passenger Station, Waxahachie, Texas]", $results[4]->Title);
142
		$this->assertEquals("[Texas and New Orleans, Southern Pacific, Tower No. 63, Mexia, Texas]", $results[5]->Title);
143
		$this->assertEquals("[Texas and New Orleans, Southern Pacific, Eakin Street Yard Office, Dallas, Texas]", $results[6]->Title);
144
		$this->assertEquals("[Texas and New Orleans, Southern Pacific Locomotive Scrap Line, Englewood Yards, Houston, Texas]", $results[7]->Title);
145
		$this->assertEquals("[Texas and New Orleans, Southern Pacific, Switchman's Tower, San Antonio, Texas]", $results[8]->Title);
146
		$this->assertEquals("Flash Light view in new Subterranean", $results[9]->Title);
147
	}
148
149
150
	// if this is not set to unbounded, zero, a conditional is triggered to add max doc freq to the request
151 View Code Duplication
	public function testSimilarChangeMaxDocFreq() {
1 ignored issue
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...
152
		$fp = $this->objFromFixture('FlickrPhotoTO', 'photo0076');
153
		$es = new ElasticSearcher();
154
		$es->setMaxDocFreq(4);
155
		$es->setClasses('FlickrPhotoTO');
156
		$fields = array('Title.standard' => 1, 'Description.standard' => 1);
157
		$paginated = $es->moreLikeThis($fp, $fields, true);
0 ignored issues
show
Documentation introduced by
$fp is of type object<DataObject>|null, but the function expects a object<SilverStripe\Elastica\DataObject>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
158
		foreach ($paginated->getList() as $result) {
159
			echo $result->ID. ' : '.$result->Title."\n";
160
		}
161
		$this->assertEquals(14, $paginated->getTotalItems());
162
		$results = $paginated->getList()->toArray();
0 ignored issues
show
Unused Code introduced by
$results is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
163
		$this->makeCode($paginated);
164
	}
165
166
167 View Code Duplication
	public function testSimilarNullFields() {
1 ignored issue
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...
168
		$fp = $this->objFromFixture('FlickrPhotoTO', 'photo0076');
169
		$es = new ElasticSearcher();
170
		$es->setClasses('FlickrPhotoTO');
171
		try {
172
			$paginated = $es->moreLikeThis($fp, null, true);
0 ignored issues
show
Documentation introduced by
$fp is of type object<DataObject>|null, but the function expects a object<SilverStripe\Elastica\DataObject>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
null is of type null, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Unused Code introduced by
$paginated is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
173
		} catch (InvalidArgumentException $e) {
174
			$this->assertEquals('Fields cannot be null', $e->getMessage());
175
		}
176
	}
177
178
179 View Code Duplication
	public function testSimilarNullItem() {
1 ignored issue
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...
180
		$es = new ElasticSearcher();
181
		$es->setClasses('FlickrPhotoTO');
182
		$fields = array('Title.standard' => 1, 'Description.standard' => 1);
183
184
		try {
185
			$paginated = $es->moreLikeThis(null, $fields, true);
0 ignored issues
show
Documentation introduced by
null is of type null, but the function expects a object<SilverStripe\Elastica\DataObject>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Unused Code introduced by
$paginated is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
186
		} catch (InvalidArgumentException $e) {
187
			$this->assertEquals('A searchable item cannot be null', $e->getMessage());
188
		}
189
	}
190
191
192
193
	public function testHighlightsAsIfCMSEdited() {
194
		$es = new ElasticSearcher();
195
		$locale = \i18n::default_locale();
196
		$es->setLocale($locale);
197
		$es->setClasses('FlickrPhotoTO');
198
199
		$filter = array('ClazzName' => 'FlickrPhotoTO', 'Name' => 'Title');
200
		$titleField = SearchableField::get()->filter($filter)->first();
201
		$titleField->ShowHighlights = true;
202
		$titleField->write();
203
204
		$filter = array('ClazzName' => 'FlickrPhotoTO', 'Name' => 'Description');
205
		$nameField = SearchableField::get()->filter($filter)->first();
206
		$nameField->ShowHighlights = true;
207
		$nameField->write();
208
209
		$fields = array('Title' => 1, 'Description' => 1);
210
		$query = 'New Zealand';
211
		$paginated = $es->search($query, $fields);
212
		$ctr = 0;
213
214
		foreach ($paginated->getList()->toArray() as $result) {
215
			$ctr++;
216
			foreach ($result->SearchHighlightsByField->Description_standard->getIterator() as $highlight) {
217
				$snippet = $highlight->Snippet;
218
				$snippet = strtolower($snippet);
219
				$wordFound = false;
220
				$lcquery = explode(' ', strtolower($query));
221
				foreach ($lcquery as $part) {
222
					$bracketed = '<strong class="hl">'.$part.'</strong>';
223
					if (strpos($snippet, $bracketed) > 0) {
224
						$wordFound = true;
225
					}
226
				}
227
				$this->assertTrue($wordFound,'Highlight should have been found');
228
			}
229
		}
230
	}
231
232
233 View Code Duplication
	public function testHighlightPassingFields() {
1 ignored issue
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...
234
		$es = new ElasticSearcher();
235
		$es->setClasses('FlickrPhotoTO');
236
		$es->setHighlightedFields(array('Title', 'Title.standard', 'Description'));
237
238
		$fields = array('Title' => 1, 'Description' => 1);
239
		$query = 'New Zealand';
240
		$paginated = $es->search($query, $fields);
241
		$ctr = 0;
242
243
		foreach ($paginated->getList()->toArray() as $result) {
244
			$ctr++;
245
246
			foreach ($result->SearchHighlightsByField->Description->getIterator() as $highlight) {
247
				$snippet = $highlight->Snippet;
248
				$snippet = strtolower($snippet);
249
				$wordFound = false;
250
				$lcquery = explode(' ', strtolower($query));
251
				foreach ($lcquery as $part) {
252
					$bracketed = '<strong class="hl">'.$part.'</strong>';
253
					if (strpos($snippet, $bracketed) > 0) {
254
						$wordFound = true;
255
					}
256
				}
257
				$this->assertTrue($wordFound,'Highlight should have been found');
258
			}
259
		}
260
	}
261
262
263 View Code Duplication
	public function testAutoCompleteGood() {
1 ignored issue
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...
264
		$es = new ElasticSearcher();
265
		$es->setClasses('FlickrPhotoTO');
266
		$fields = array('Title' => 1, 'Description' => 1);
0 ignored issues
show
Unused Code introduced by
$fields is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
267
		$query = 'Lond';
268
		$results = $es->autocomplete_search($query, 'Title');
269
		$this->assertEquals(7, $results->getTotalItems());
270
		foreach ($results->toArray() as $result) {
271
			$this->assertTrue(strpos($result->Title, $query) > 0);
272
		}
273
	}
274
275
276 View Code Duplication
	private function makeCode($paginated) {
1 ignored issue
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...
277
		$results = $paginated->getList()->toArray();
278
		$ctr = 0;
279
		echo '$result = $paginated->getList()->toArray();'."\n";
280
		foreach ($results as $result) {
281
			echo '$this->assertEquals("'.$result->Title.'", $results['.$ctr.']->Title);'."\n";
282
			$ctr++;
283
		}
284
	}
285
286
}
287