EntitySearcher   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A search() 0 16 2
1
<?php
2
3
namespace Wikibase\Api\Service;
4
5
use Mediawiki\Api\MediawikiApi;
6
use Mediawiki\Api\SimpleRequest;
7
8
/**
9
 * @access private
10
 *
11
 * @author Addshore
12
 */
13
class EntitySearcher {
14
15
	/**
16
	 * @var MediawikiApi
17
	 */
18
	private $api;
19
20
	/**
21
	 * @param MediawikiApi $api
22
	 */
23
	public function __construct( MediawikiApi $api ) {
24
		$this->api = $api;
25
	}
26
27
	/**
28
	 * @since 0.8
29
	 *
30
	 * @param string $entityType
31
	 * @param string $string
32
	 * @param string $language
33
	 * @return string[] EntityIds
34
	 */
35
	public function search( $entityType, $string, $language ){
36
		$params = array(
37
			'search' => $string,
38
			'language' => $language,
39
			'type' => $entityType,
40
		);
41
42
		$data = $this->api->getRequest( new SimpleRequest( 'wbsearchentities', $params ) );
43
44
		$ids = [];
45
		foreach( $data['search'] as $searchResult ) {
46
			$ids[] = $searchResult['id'];
47
		}
48
49
		return $ids;
50
	}
51
52
}