These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace Wikibase\EntityStore\MongoDB; |
||
4 | |||
5 | use Doctrine\MongoDB\Database; |
||
6 | use Doctrine\MongoDB\Query\Expr; |
||
7 | use Wikibase\DataModel\Term\Term; |
||
8 | use Wikibase\EntityStore\Internal\EntityIdForTermLookup; |
||
9 | |||
10 | /** |
||
11 | * Internal class |
||
12 | * |
||
13 | * @licence GPLv2+ |
||
14 | * @author Thomas Pellissier Tanon |
||
15 | */ |
||
16 | class MongoDBEntityIdForTermLookup implements EntityIdForTermLookup { |
||
17 | |||
18 | /** |
||
19 | * @var Database |
||
20 | */ |
||
21 | private $database; |
||
22 | |||
23 | /** |
||
24 | * @var MongoDBDocumentBuilder |
||
25 | */ |
||
26 | private $documentBuilder; |
||
27 | |||
28 | /** |
||
29 | * @param Database $database |
||
30 | * @param MongoDBDocumentBuilder $documentBuilder |
||
31 | */ |
||
32 | 2 | public function __construct( Database $database, MongoDBDocumentBuilder $documentBuilder ) { |
|
33 | 2 | $this->database = $database; |
|
34 | 2 | $this->documentBuilder = $documentBuilder; |
|
35 | 2 | } |
|
36 | |||
37 | /** |
||
38 | * @see EntityDocumentLookup::getEntityDocumentsForTerm |
||
39 | */ |
||
40 | 2 | public function getEntityIdsForTerm( Term $term, $entityType ) { |
|
41 | 2 | $documents = $this->database |
|
42 | 2 | ->selectCollection( $entityType ) |
|
43 | 2 | ->find( |
|
44 | 2 | $this->buildGetEntityIdForTermQuery( $term ), |
|
0 ignored issues
–
show
|
|||
45 | 2 | [ '_id' => 1 ] |
|
46 | 2 | ); |
|
47 | |||
48 | 2 | $entities = []; |
|
49 | |||
50 | 2 | foreach( $documents as $document ) { |
|
51 | 2 | $entities[] = $this->documentBuilder->buildEntityIdForDocument( $document ); |
|
52 | 2 | } |
|
53 | |||
54 | 2 | return $entities; |
|
55 | } |
||
56 | |||
57 | 2 | private function buildGetEntityIdForTermQuery( Term $term ) { |
|
58 | 2 | $expr = new Expr(); |
|
59 | 2 | $expr->field( 'sterms.' . $term->getLanguageCode() )->equals( |
|
60 | 2 | $this->documentBuilder->cleanTextForSearch( $term->getText() ) |
|
61 | 2 | ); |
|
62 | 2 | return $expr->getQuery(); |
|
63 | } |
||
64 | } |
||
65 |
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: