Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
6 / 6 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
GrammaticalFeatureItemIdsExtractor | |
100.00% |
6 / 6 |
|
100.00% |
2 / 2 |
3 | |
100.00% |
1 / 1 |
extractEntityIds | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
extractGrammaticalFeatureIds | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace Wikibase\Lexeme\Domain\EntityReferenceExtractors; |
4 | |
5 | use Wikibase\DataModel\Entity\EntityDocument; |
6 | use Wikibase\DataModel\Entity\ItemId; |
7 | use Wikibase\Lexeme\Domain\Model\FormSet; |
8 | use Wikibase\Lexeme\Domain\Model\Lexeme; |
9 | use Wikibase\Repo\EntityReferenceExtractors\EntityReferenceExtractor; |
10 | use Wikimedia\Assert\Assert; |
11 | |
12 | /** |
13 | * Extracts the item ids of a lexeme's forms' grammatical features |
14 | * |
15 | * @license GPL-2.0-or-later |
16 | */ |
17 | class GrammaticalFeatureItemIdsExtractor implements EntityReferenceExtractor { |
18 | |
19 | /** |
20 | * @param EntityDocument $lexeme |
21 | * @return ItemId[] |
22 | */ |
23 | public function extractEntityIds( EntityDocument $lexeme ) { |
24 | Assert::parameterType( Lexeme::class, $lexeme, '$lexeme' ); |
25 | '@phan-var Lexeme $lexeme'; |
26 | |
27 | /** @var Lexeme $lexeme */ |
28 | return $this->extractGrammaticalFeatureIds( $lexeme->getForms() ); |
29 | } |
30 | |
31 | /** |
32 | * @param FormSet $forms |
33 | * @return ItemId[] |
34 | */ |
35 | private function extractGrammaticalFeatureIds( FormSet $forms ) { |
36 | $ids = []; |
37 | |
38 | foreach ( $forms->toArrayUnordered() as $form ) { |
39 | $ids = array_merge( $ids, $form->getGrammaticalFeatures() ); |
40 | } |
41 | |
42 | return array_values( array_unique( $ids ) ); |
43 | } |
44 | |
45 | } |