Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
7 / 7 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
EntityLookupLemmaLookup | |
100.00% |
7 / 7 |
|
100.00% |
2 / 2 |
4 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getLemmas | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
3 |
1 | <?php |
2 | |
3 | declare( strict_types = 1 ); |
4 | |
5 | namespace Wikibase\Lexeme\DataAccess\Store; |
6 | |
7 | use Wikibase\DataModel\Services\Lookup\EntityLookup; |
8 | use Wikibase\DataModel\Services\Lookup\UnresolvedEntityRedirectException; |
9 | use Wikibase\DataModel\Term\TermList; |
10 | use Wikibase\Lexeme\Domain\Model\Lexeme; |
11 | use Wikibase\Lexeme\Domain\Model\LexemeId; |
12 | |
13 | /** |
14 | * @license GPL-2.0-or-later |
15 | */ |
16 | class EntityLookupLemmaLookup implements LemmaLookup { |
17 | |
18 | private EntityLookup $entityLookup; |
19 | |
20 | public function __construct( EntityLookup $entityLookup ) { |
21 | $this->entityLookup = $entityLookup; |
22 | } |
23 | |
24 | public function getLemmas( LexemeId $lexemeId ): TermList { |
25 | try { |
26 | $lexeme = $this->entityLookup->getEntity( $lexemeId ); |
27 | } catch ( UnresolvedEntityRedirectException $ex ) { // T228996 |
28 | // Regression catch. |
29 | // When there's a double redirect in Lexemes (eg. L1 -> L2 -> L3) |
30 | // then getting lemmas of L1 will fatal as the second redirect is |
31 | // not handled by the lookup, and the exception bubbles up here. |
32 | // Fatal was caused by that exception as it wasn't handled. Seen on |
33 | // Special:RecentChanges and Special:WhatLinksHere pages. |
34 | // Handled gracefully with this catch, by returning an empty list, |
35 | // effectively displaying the lexeme by its ID instead. |
36 | return new TermList(); |
37 | } |
38 | |
39 | if ( $lexeme === null ) { |
40 | return new TermList(); |
41 | } |
42 | |
43 | /** @var Lexeme $lexeme */ |
44 | '@phan-var Lexeme $lexeme'; |
45 | return $lexeme->getLemmas(); |
46 | } |
47 | } |