Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
61.54% |
8 / 13 |
|
33.33% |
1 / 3 |
CRAP | |
0.00% |
0 / 1 |
SenseTitleStoreLookup | |
61.54% |
8 / 13 |
|
33.33% |
1 / 3 |
8.05 | |
0.00% |
0 / 1 |
__construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getTitleForId | |
87.50% |
7 / 8 |
|
0.00% |
0 / 1 |
3.02 | |||
getTitlesForIds | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
6 |
1 | <?php |
2 | |
3 | namespace Wikibase\Lexeme\DataAccess\Store; |
4 | |
5 | use MediaWiki\Title\Title; |
6 | use UnexpectedValueException; |
7 | use Wikibase\DataModel\Entity\EntityId; |
8 | use Wikibase\Lexeme\Domain\DummyObjects\NullSenseId; |
9 | use Wikibase\Lexeme\Domain\Model\SenseId; |
10 | use Wikibase\Repo\Store\EntityTitleStoreLookup; |
11 | use Wikimedia\Assert\Assert; |
12 | |
13 | /** |
14 | * @license GPL-2.0-or-later |
15 | */ |
16 | class SenseTitleStoreLookup implements EntityTitleStoreLookup { |
17 | |
18 | /** |
19 | * @var EntityTitleStoreLookup |
20 | */ |
21 | private $lookup; |
22 | |
23 | public function __construct( EntityTitleStoreLookup $lookup ) { |
24 | $this->lookup = $lookup; |
25 | } |
26 | |
27 | /** |
28 | * @see EntityTitleStoreLookup::getTitleForId |
29 | * |
30 | * @param SenseId $senseId |
31 | * |
32 | * @throws UnexpectedValueException |
33 | * @return Title|null |
34 | */ |
35 | public function getTitleForId( EntityId $senseId ) { |
36 | Assert::parameterType( SenseId::class, $senseId, '$senseId' ); |
37 | |
38 | if ( $senseId instanceof NullSenseId ) { |
39 | return null; |
40 | } |
41 | |
42 | $title = $this->lookup->getTitleForId( $senseId->getLexemeId() ); |
43 | |
44 | if ( $title === null ) { |
45 | return null; |
46 | } |
47 | |
48 | $title->setFragment( '#' . $senseId->getIdSuffix() ); |
49 | |
50 | return $title; |
51 | } |
52 | |
53 | /** |
54 | * @inheritDoc |
55 | */ |
56 | public function getTitlesForIds( array $ids ) { |
57 | $result = []; |
58 | /** @var EntityId $id */ |
59 | foreach ( $ids as $id ) { |
60 | $result[$id->getSerialization()] = $this->getTitleForId( $id ); |
61 | } |
62 | |
63 | return $result; |
64 | } |
65 | |
66 | } |