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